:root {
  --bg-a: #090d15;
  --bg-b: #0e1524;
  --bg-c: #171f31;
  --text: #e7ecfb;
  --muted: #95a0bb;
  --border: #2a3552;
  --accent: #1f9dff;
  --accent-strong: #39b3ff;
  --danger: #ff5f6d;
  --danger-strong: #ff4355;
  --success: #24b36b;
  --success-strong: #2dcc7b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% -10%, #1c3158 0%, transparent 35%),
    radial-gradient(circle at 95% 0%, #21315c 0%, transparent 28%),
    linear-gradient(165deg, var(--bg-a) 0%, var(--bg-b) 48%, var(--bg-c) 100%);
}

.lobby-body {
  display: grid;
  place-items: center;
  padding: 1rem;
}

.lobby-wrap {
  width: 100%;
  max-width: 560px;
}

.lobby-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: linear-gradient(160deg, #131d31 0%, #0f1728 100%);
  box-shadow:
    0 30px 60px #02050d99,
    inset 0 1px 0 #ffffff10;
  padding: 1rem;
}

.lobby-card h1 {
  margin: 0 0 0.25rem;
  letter-spacing: 0.02em;
}

.lobby-subtitle {
  margin: 0 0 1rem;
  color: var(--muted);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #35436499;
  background: #0b1220d9;
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0.03em;
}

.topbar-left {
  display: grid;
  gap: 0.18rem;
}

.top-share {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.room-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-weight: 600;
  background: #172037;
}

.room-top-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.leave-btn {
  background: #44506c;
}

.leave-btn:hover {
  background: #57668a;
}

.layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  padding: 1rem;
  min-height: calc(100vh - 86px);
}

.left-panel,
.right-panel {
  display: grid;
  gap: 1rem;
}

.left-panel {
  grid-template-rows: 1.3fr auto;
}

.right-panel {
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.tray-card,
.pool-card,
.players-card,
.log-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(160deg, #131d31 0%, #0f1728 100%);
  box-shadow:
    0 18px 34px #02050d7d,
    inset 0 1px 0 #ffffff12;
  padding: 0.9rem;
}

.field-row {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.7rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.card-header h2 {
  margin: 0;
  font-size: 1rem;
}

input,
button {
  font: inherit;
}

input {
  width: 100%;
  border: 1px solid var(--border);
  background: #0d1525;
  color: var(--text);
  padding: 0.55rem 0.6rem;
  border-radius: 8px;
  outline: none;
}

input:focus {
  border-color: #4f86ff;
  box-shadow: 0 0 0 2px #2f5fb26e;
}

button {
  border: 1px solid transparent;
  background: var(--accent);
  color: #08101f;
  font-weight: 700;
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

button:hover {
  background: var(--accent-strong);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.connect-actions {
  display: flex;
  gap: 0.5rem;
}

.hint {
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.share-link {
  user-select: all;
  font-family: Consolas, "Courier New", monospace;
  color: #b8c7eb;
}

.error-text {
  color: #ff8b94;
  margin: 0.4rem 0 0;
  min-height: 1.1rem;
}

.dice-tray {
  position: relative;
  border-radius: 20px;
  height: 340px;
  overflow: hidden;
  border: 12px solid #4f341f;
  box-shadow:
    inset 0 0 0 2px #715133,
    inset 0 0 24px #0000008a,
    0 14px 34px #00000080;
  background:
    linear-gradient(145deg, #5f4028 0%, #3b2514 42%, #28180d 100%);
  perspective: 1200px;
  transform-style: preserve-3d;
}

.rolled-dice-grid {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0e1628;
  min-height: 210px;
  max-height: 320px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.rolled-dice-empty-state {
  width: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  min-height: 140px;
  text-align: center;
  border: 1px dashed #2f3b59;
  border-radius: 10px;
  background: #0b1324;
}

.rolled-roll-entry {
  border: 1px solid #2a3552;
  border-radius: 10px;
  background: #0f172a;
  padding: 0.45rem;
}

.rolled-roll-title {
  margin-bottom: 0.4rem;
  color: #b8c7eb;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 700;
}

.rolled-roll-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(98px, 1fr));
  gap: 0.5rem;
}

.rolled-die-card {
  border: 1px solid #2a3552;
  border-radius: 10px;
  background: #111a2e;
  padding: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rolled-die-face {
  width: 100%;
  aspect-ratio: 1 / 1;
  position: relative;
  overflow: visible;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.36rem;
}

.rolled-die-face::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid #00000066;
  box-shadow:
    inset 0 10px 14px #ffffff17,
    inset 0 -8px 10px #00000047;
  background: var(--die-face-color, #2a3f62);
  pointer-events: none;
  z-index: 0;
}

.rolled-die-face .rolled-die-symbols {
  position: relative;
  z-index: 1;
}

.rolled-die-face.die-shape-cube {
  clip-path: none;
}

.rolled-die-face.die-shape-cube::before {
  border-radius: 14px;
}

.rolled-die-face.die-shape-octahedron {
  clip-path: none;
}

.rolled-die-face.die-shape-octahedron::before {
  border-radius: 14px;
  clip-path: polygon(50% 6%, 56% 9%, 92% 80%, 92% 86%, 86% 92%, 14% 92%, 8% 86%, 8% 80%, 44% 9%);
}

.rolled-die-face.die-shape-dodecahedron {
  clip-path: none;
}

.rolled-die-face.die-shape-dodecahedron::before {
  border-radius: 14px;
  clip-path: polygon(50% 5%, 56% 7%, 90% 31%, 94% 37%, 92% 44%, 79% 90%, 73% 95%, 27% 95%, 21% 90%, 8% 44%, 6% 37%, 10% 31%, 44% 7%);
}

.die-shape-cube {
  border-radius: 14px;
}

.die-shape-octahedron {
  border-radius: 14px;
  clip-path: polygon(50% 6%, 56% 9%, 92% 80%, 92% 86%, 86% 92%, 14% 92%, 8% 86%, 8% 80%, 44% 9%);
}

.die-shape-dodecahedron {
  border-radius: 14px;
  clip-path: polygon(50% 5%, 56% 7%, 90% 31%, 94% 37%, 92% 44%, 79% 90%, 73% 95%, 27% 95%, 21% 90%, 8% 44%, 6% 37%, 10% 31%, 44% 7%);
}

.rolled-die-symbols {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.2rem;
}

.die-shape-octahedron .rolled-die-symbols {
  transform: translateY(24%);
}

.dice-tray::before {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 10px;
  border: 2px solid #00000075;
  background:
    radial-gradient(circle at 15% 15%, #244c4f 0%, #1f4146 32%, #163339 70%, #10272b 100%),
    repeating-linear-gradient(35deg, #ffffff08 0px, #ffffff08 2px, #00000000 2px, #00000000 7px);
  box-shadow:
    inset 0 14px 18px #ffffff0f,
    inset 0 -8px 14px #00000080;
  z-index: 0;
}

.dice-tray::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 10px;
  pointer-events: none;
  box-shadow:
    inset 0 0 40px #0000007a,
    inset 0 30px 30px #00000030;
  z-index: 2;
}

.tray-webgl {
  position: absolute;
  inset: 11px;
  z-index: 1;
  border-radius: 8px;
  pointer-events: none;
}

.tray-die {
  position: absolute;
  width: 64px;
  height: 64px;
  transform-style: preserve-3d;
  transform-origin: 50% 50%;
  user-select: none;
  z-index: 1;
  will-change: transform;
}

.die-face {
  position: absolute;
  border: 1px solid #0000005b;
  backface-visibility: hidden;
}

.die-symbol-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  flex-wrap: wrap;
  padding: 0.2rem;
  transform: translateZ(16px);
  z-index: 5;
}

.die-cube .cube-front {
  inset: 10px;
  border-radius: 9px;
  transform: translateZ(13px);
  background: linear-gradient(145deg, var(--die-top) 0%, var(--die-mid) 58%, var(--die-side) 100%);
  box-shadow:
    inset 0 8px 10px #ffffff1f,
    inset 0 -6px 10px #00000045,
    0 8px 15px #00000055;
}

.die-cube .cube-top {
  left: 10px;
  top: 1px;
  width: 44px;
  height: 20px;
  border-radius: 7px 7px 5px 5px;
  transform-origin: center bottom;
  transform: rotateX(90deg) translateZ(10px);
  background: linear-gradient(180deg, var(--die-top) 0%, var(--die-mid) 100%);
}

.die-cube .cube-side {
  right: 1px;
  top: 10px;
  width: 20px;
  height: 44px;
  border-radius: 5px 7px 7px 5px;
  transform-origin: left center;
  transform: rotateY(90deg);
  background: linear-gradient(180deg, var(--die-mid) 0%, var(--die-side) 100%);
}

.die-octahedron .die-face {
  inset: 0;
  border-radius: 8px;
}

.die-octahedron .octa-top-a,
.die-octahedron .octa-top-b,
.die-octahedron .octa-bottom-a,
.die-octahedron .octa-bottom-b {
  background: linear-gradient(160deg, var(--die-top) 0%, var(--die-mid) 65%, var(--die-side) 100%);
}

.die-octahedron .octa-top-a {
  clip-path: polygon(50% 0%, 8% 50%, 50% 50%);
  transform: translateZ(10px) rotateX(14deg);
}

.die-octahedron .octa-top-b {
  clip-path: polygon(50% 0%, 92% 50%, 50% 50%);
  transform: translateZ(10px) rotateY(-14deg);
}

.die-octahedron .octa-bottom-a {
  clip-path: polygon(8% 50%, 50% 100%, 50% 50%);
  transform: translateZ(10px) rotateY(14deg);
}

.die-octahedron .octa-bottom-b {
  clip-path: polygon(50% 50%, 50% 100%, 92% 50%);
  transform: translateZ(10px) rotateX(-14deg);
}

.octa-symbol-layer {
  transform: translateZ(16px);
  inset: 10px;
}

.die-dodecahedron .dodeca-core {
  inset: 11px;
  clip-path: polygon(50% 0%, 90% 30%, 74% 86%, 26% 86%, 10% 30%);
  transform: translateZ(12px);
  background: linear-gradient(160deg, var(--die-top) 0%, var(--die-mid) 65%, var(--die-side) 100%);
  border-radius: 8px;
}

.die-dodecahedron .dodeca-left {
  inset: 16px 40px 16px 4px;
  clip-path: polygon(70% 0, 100% 30%, 86% 100%, 24% 100%, 0 30%);
  background: linear-gradient(180deg, var(--die-mid) 0%, var(--die-side) 100%);
  transform: translateZ(7px) rotateY(-26deg);
}

.die-dodecahedron .dodeca-right {
  inset: 16px 4px 16px 40px;
  clip-path: polygon(0 30%, 30% 0, 100% 30%, 76% 100%, 14% 100%);
  background: linear-gradient(180deg, var(--die-mid) 0%, var(--die-side) 100%);
  transform: translateZ(7px) rotateY(26deg);
}

.die-dodecahedron .dodeca-top {
  inset: 3px 16px 40px 16px;
  clip-path: polygon(50% 0, 90% 34%, 74% 100%, 26% 100%, 10% 34%);
  background: linear-gradient(180deg, var(--die-top) 0%, var(--die-mid) 100%);
  transform: translateZ(7px) rotateX(26deg);
}

.die-dodecahedron .dodeca-bottom {
  inset: 40px 16px 3px 16px;
  clip-path: polygon(26% 0, 74% 0, 90% 66%, 50% 100%, 10% 66%);
  background: linear-gradient(180deg, var(--die-mid) 0%, var(--die-side) 100%);
  transform: translateZ(7px) rotateX(-26deg);
}

.dodeca-symbol-layer {
  inset: 13px;
  transform: translateZ(17px);
}

.result-summary {
  margin-top: 0.55rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0e1628;
  font-size: 0.93rem;
}

.result-summary-title {
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.result-summary-section {
  margin-bottom: 0.55rem;
}

.result-summary-section:last-child {
  margin-bottom: 0;
}

.dice-roll-count-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.dice-roll-count {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  border: 1px solid #2e3b5f;
  border-radius: 999px;
  padding: 0.16rem 0.42rem;
  background: #111d34;
}

.rolled-die-icon-wrap {
  --die-icon-wrap-size: 22px;
  --die-icon-size: 15px;
  --die-icon-radius: 6px;
  width: var(--die-icon-wrap-size);
  height: var(--die-icon-wrap-size);
  border-radius: var(--die-icon-radius);
  border: 1px solid #2f3d63;
  background: #0d162a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.rolled-die-icon {
  width: var(--die-icon-size);
  height: var(--die-icon-size);
  object-fit: contain;
}

.symbol-count-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.symbol-count-row.compact {
  display: inline-flex;
  gap: 0.28rem;
  margin-left: 0.2rem;
  vertical-align: middle;
}

.symbol-count {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  border: 1px solid #2e3b5f;
  border-radius: 999px;
  padding: 0.16rem 0.42rem;
  background: #111d34;
}

.symbol-count.compact {
  padding: 0.08rem 0.32rem;
  gap: 0.2rem;
}

.symbol-count-number {
  font-weight: 700;
  color: #dce8ff;
  line-height: 1;
}

.symbol-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid transparent;
  position: relative;
  flex: 0 0 auto;
}

.symbol-chip-transparent {
  background: transparent;
  border-color: transparent;
}

.symbol-chip-success {
  background: #36a95a;
  border-color: #6fdf95;
}

.symbol-chip-advantage {
  background: #2f80ed;
  border-color: #73b2ff;
}

.symbol-chip-triumph {
  background: #e2b119;
  border-color: #f6d873;
}

.symbol-chip-failure {
  background: #6f4fd7;
  border-color: #a28fff;
}

.symbol-chip-threat {
  background: #0f1015;
  border-color: #5d6474;
}

.symbol-chip-despair {
  background: #b82635;
  border-color: #f07984;
}

.symbol-chip-normal {
  width: 22px;
  height: 22px;
}

.symbol-chip-small {
  width: 18px;
  height: 18px;
}

.symbol-chip-die {
  width: 24px;
  height: 24px;
  border-radius: 7px;
}

.symbol-chip-overlay {
  width: 24px;
  height: 24px;
  border-radius: 0;
}

.symbol-chip[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 0.18rem 0.35rem;
  border-radius: 6px;
  font-size: 0.7rem;
  color: #e9efff;
  background: #0b1120;
  border: 1px solid #2a3758;
  box-shadow: 0 8px 14px #00000080;
  z-index: 20;
}

.symbol-glyph {
  width: 76%;
  height: 76%;
  object-fit: contain;
}

.symbol-glyph-native {
  filter: none;
}

.symbol-glyph-dark {
  filter: brightness(0);
}

.symbol-glyph-light {
  filter: brightness(0) invert(1);
}

.symbol-fallback-inline {
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
}

.symbol-chip-dark-text .symbol-fallback-inline {
  color: #08120d;
}

.symbol-chip-light-text .symbol-fallback-inline {
  color: #ffffff;
}

.symbol-fallback {
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1;
  color: #b9c8ec;
}

.roll-btn {
  background: var(--success);
  color: #03160d;
}

.roll-btn:hover {
  background: var(--success-strong);
}

.dice-controls {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.5rem;
}

.die-control-column {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.36rem;
  background: #0e1628;
}

.die-icon-wrap {
  --die-icon-wrap-size: 32px;
  --die-icon-size: 22px;
  --die-icon-radius: 8px;
}

.die-icon-wrap[data-tooltip]:hover::after,
.rolled-die-icon-wrap[data-tooltip]:hover::after,
.die-shape-token[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 0.18rem 0.35rem;
  border-radius: 6px;
  font-size: 0.7rem;
  color: #e9efff;
  background: #0b1120;
  border: 1px solid #2a3758;
  box-shadow: 0 8px 14px #00000080;
  z-index: 20;
}

.die-shape-token {
  position: relative;
  display: inline-block;
  border: 1px solid #00000066;
  box-shadow:
    inset 0 8px 12px #ffffff1f,
    inset 0 -7px 10px #00000047,
    0 1px 2px #00000066;
}

.die-shape-token-small {
  width: 22px;
  height: 22px;
}

.die-shape-token-large {
  width: 32px;
  height: 32px;
}

.die-pool-icon {
  object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(0 1px 2px #000000a8);
}

.die-counter {
  display: flex;
  align-items: center;
  gap: 0.32rem;
}

.pool-step-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 6px;
  background: #27385d;
  color: #eaf2ff;
}

.pool-step-btn:hover {
  background: #365185;
}

.die-count-value {
  min-width: 1.1rem;
  text-align: center;
  font-weight: 700;
}

.players-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.4rem;
}

.players-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  background: #0e1628;
  font-size: 0.92rem;
}

.player-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.badge {
  font-size: 0.72rem;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  border: 1px solid #ffe08a66;
  background: #ffc94d26;
  color: #ffd978;
}

.kick-btn {
  background: var(--danger);
  color: #2b0207;
  padding: 0.22rem 0.48rem;
  font-size: 0.82rem;
}

.kick-btn:hover {
  background: var(--danger-strong);
}

.log-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
}

.log-list {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  background: #0e1628;
  min-height: 0;
  height: 100%;
  max-height: 52vh;
}

.log-entry {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
  line-height: 1.3;
}

.log-entry.system {
  color: var(--muted);
}

.log-entry.chat strong,
.log-entry.roll strong {
  color: #79beff;
}

.log-roll-arrow {
  color: #9fb3de;
  margin: 0 0.35rem;
}

.chat-input-row {
  margin-top: 0.5rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
}

.admin-tools-row {
  margin-top: 0.4rem;
  display: flex;
  justify-content: flex-end;
}

.new-section-btn {
  background: #2a3552;
  color: #dce8ff;
  border: 1px solid #455985;
  padding: 0.34rem 0.62rem;
  font-size: 0.82rem;
}

.new-section-btn:hover {
  background: #35456b;
}

.log-entry.section {
  margin: 0.6rem 0 0.7rem;
}

.log-section-line {
  height: 1px;
  background: linear-gradient(90deg, #00000000 0%, #5a709f 22%, #5a709f 78%, #00000000 100%);
}

.log-section-label {
  margin-top: 0.22rem;
  text-align: center;
  font-size: 0.74rem;
  color: #9bb0d7;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

@media (max-width: 1040px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .left-panel {
    grid-template-rows: auto auto;
  }

  .rolled-dice-grid {
    max-height: 260px;
  }

  .dice-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
  }

  .topbar-left {
    gap: 0.1rem;
    max-width: 68%;
  }

  .top-share {
    font-size: 0.8rem;
  }

  .dice-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .connect-actions {
    flex-direction: column;
  }

  .room-top-meta {
    gap: 0.35rem;
  }

  .room-pill {
    font-size: 0.82rem;
  }
}
