:root {
  --bg: radial-gradient(1200px 800px at 10% 10%, #1a2840, #0b1220 60%);
  --panel: #0f1b2e;
  --panel-2: #0b1626;
  --text: #e6f1ff;
  --muted: #93a4c4;
  --accent: #6ee7ff;
  --accent-2: #7c3aed;
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Nunito", system-ui, -apple-system, Segoe UI, Roboto, Ubuntu,
    Cantarell, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background-attachment: fixed;
  overflow-x: hidden;
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 18px 40px;
}

.banner {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: linear-gradient(
    180deg,
    rgba(124, 58, 237, 0.25),
    rgba(124, 58, 237, 0) 70%
  );
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
}
.brand-left {
  font-family: "Kanit", sans-serif;
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 14px;
  color: var(--accent);
}
.brand-right {
  font-family: "Kanit", sans-serif;
  font-weight: 800;
  font-size: 28px;
  line-height: 1.1;
}

.hud {
  display: grid;
  grid-auto-flow: column;
  gap: 18px;
}
.hud-item {
  background: linear-gradient(
    180deg,
    rgba(110, 231, 255, 0.12),
    rgba(110, 231, 255, 0)
  );
  border: 1px solid rgba(110, 231, 255, 0.25);
  padding: 10px 14px;
  border-radius: 12px;
  text-align: center;
  min-width: 110px;
}
.hud-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.hud-item strong {
  font-size: 22px;
  letter-spacing: 0.02em;
  transition: all 0.3s ease;
}

.board {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 18px;
  margin-top: 18px;
}
.left,
.right {
  display: grid;
  gap: 18px;
}
.left {
  grid-template-rows: auto auto 1fr;
}

.panel {
  background: linear-gradient(
    180deg,
    rgba(15, 27, 46, 0.9),
    rgba(15, 27, 46, 0.75)
  );
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.panel h2,
.panel h3 {
  margin: 6px 0 12px;
  font-family: "Kanit", sans-serif;
  letter-spacing: 0.02em;
}
.panel h2 {
  font-size: 22px;
}
.panel h3 {
  font-size: 18px;
  color: var(--accent);
}

.gm-log {
  height: 120px;
  overflow: auto;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  line-height: 1.5;
}
.gm-log .line {
  opacity: 0.95;
}
.gm-log .line strong {
  color: var(--accent);
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.op-btn {
  background: linear-gradient(
    180deg,
    rgba(124, 58, 237, 0.12),
    rgba(124, 58, 237, 0.03)
  );
  border: 1px solid rgba(124, 58, 237, 0.35);
  color: var(--text);
  padding: 10px 8px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.2s ease;
  font-weight: 700;
}
.op-btn:hover {
  transform: translateY(-1px);
}
.op-btn.active {
  outline: 2px solid var(--accent);
  background: rgba(110, 231, 255, 0.08);
}

.dice-panel {
  position: relative;
}
.dice-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}
.dice-btn {
  background: linear-gradient(
    180deg,
    rgba(15, 27, 46, 1),
    rgba(15, 27, 46, 0.6)
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  cursor: pointer;
  padding: 8px;
  transition: transform 0.12s ease, box-shadow 0.12s ease,
    outline-color 0.12s ease;
}
.dice-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
}
.dice-btn:active {
  transform: translateY(0);
}
.dice-btn.active {
  outline: 2px solid var(--accent);
}
.dice-svg {
  display: block;
  width: 100%;
  height: 80px;
}

.roll-visual {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}
.die-preview {
  height: 120px;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.die-3d {
  width: 100px;
  height: 100px;
  perspective: 500px;
  position: relative;
}
.die-3d .cube {
  width: 100%;
  height: 100%;
  position: absolute;
  transform-style: preserve-3d;
  animation: roll 1s ease-in-out;
}
.die-3d .face {
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(145deg, #152238, #0c1627);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 42px;
  font-weight: 900;
  color: #e9f2ff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}
.die-3d .face:nth-child(1) {
  transform: rotateY(0deg) translateZ(50px);
}
.die-3d .face:nth-child(2) {
  transform: rotateY(90deg) translateZ(50px);
}
.die-3d .face:nth-child(3) {
  transform: rotateY(180deg) translateZ(50px);
}
.die-3d .face:nth-child(4) {
  transform: rotateY(-90deg) translateZ(50px);
}
.die-3d .face:nth-child(5) {
  transform: rotateX(90deg) translateZ(50px);
}
.die-3d .face:nth-child(6) {
  transform: rotateX(-90deg) translateZ(50px);
}

@keyframes roll {
  0% {
    transform: rotate3d(0, 0, 0, 0deg);
  }
  25% {
    transform: rotate3d(1, 1, 0, 180deg);
  }
  50% {
    transform: rotate3d(0, 1, 1, 360deg);
  }
  75% {
    transform: rotate3d(1, 0, 1, 540deg);
  }
  100% {
    transform: rotate3d(1, 1, 1, 720deg);
  }
}

.calc-card {
  background: linear-gradient(
    180deg,
    rgba(12, 22, 39, 0.9),
    rgba(12, 22, 39, 0.6)
  );
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 12px;
  font-family: "Kanit", sans-serif;
  font-size: 18px;
  letter-spacing: 0.02em;
}
.calc-line {
  opacity: 0.95;
}
.calc-line.strong {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
}
.calc-line.arrow {
  text-align: center;
  opacity: 0.6;
}

.timer {
  position: relative;
  height: 18px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  overflow: hidden;
}
.timer .bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  background: linear-gradient(90deg, var(--good), var(--warn), var(--bad));
  transform-origin: left center;
  transition: transform 0.1s linear;
}
.timer .countdown {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-weight: 900;
  display: none;
}

.leaderboard-panel ol {
  margin: 0;
  padding-left: 20px;
}
.leaderboard-panel li {
  margin: 6px 0;
}

.actions-panel {
  display: grid;
}
.primary {
  background: linear-gradient(
    180deg,
    rgba(110, 231, 255, 0.18),
    rgba(110, 231, 255, 0.06)
  );
  border: 1px solid rgba(110, 231, 255, 0.4);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.6);
}
.modal.hidden {
  display: none;
}
.modal-content {
  background: linear-gradient(
    180deg,
    rgba(15, 27, 46, 0.95),
    rgba(15, 27, 46, 0.85)
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 18px;
  width: min(420px, 92vw);
  box-shadow: var(--shadow);
}
.modal-content.center {
  text-align: center;
  width: min(520px, 94vw);
}
.modal-content.intro-modal {
  max-height: 90vh;
  overflow-y: auto;
  width: min(480px, 92vw);
}
.intro-content {
  margin-bottom: 16px;
}
.intro-list {
  margin: 8px 0 10px;
}
.intro-list ul {
  margin: 4px 0 6px 16px;
}
.lang-group {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.lang-btn.active {
  outline: 2px solid var(--accent);
}
.muted {
  color: var(--muted);
}
.final-score {
  font-family: "Kanit", sans-serif;
  font-size: 54px;
  font-weight: 800;
  margin: 10px 0 12px;
  color: var(--accent);
  text-shadow: 0 6px 22px rgba(110, 231, 255, 0.18);
}
.center-actions {
  justify-content: center;
  gap: 10px;
}
.secondary {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.08),
    rgba(255, 255, 255, 0.03)
  );
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
}
.modal-content h2 {
  margin: 6px 0 8px;
  font-family: "Kanit";
}
.modal-content p {
  margin: 4px 0 10px;
  color: var(--muted);
}
.modal-content h3 {
  margin: 12px 0 8px;
  font-family: "Kanit";
  font-size: 16px;
  color: var(--accent);
}
#nicknameInput {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
}
.level-selection {
  margin-top: 16px;
}
.level-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.level-btn {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.08),
    rgba(255, 255, 255, 0.03)
  );
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  text-align: left;
  transition: all 0.2s ease;
}
.level-btn:hover {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.12),
    rgba(255, 255, 255, 0.06)
  );
  transform: translateY(-1px);
}
.level-btn.active {
  outline: 2px solid var(--accent);
  background: linear-gradient(
    180deg,
    rgba(110, 231, 255, 0.15),
    rgba(110, 231, 255, 0.05)
  );
}
.modal-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

/* Confetti overlay */
#confetti {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 9999;
  display: none;
}

@media (max-width: 900px) {
  .board {
    grid-template-columns: 1fr;
  }
  .left {
    grid-template-rows: auto auto auto;
  }
  .dice-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .roll-visual {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .modal-content.intro-modal {
    max-height: 85vh;
    width: 95vw;
    padding: 16px;
  }
  .intro-list {
    font-size: 14px;
  }
  .intro-list ul {
    margin: 3px 0 5px 14px;
  }
}

/* Game Over Modal Styles */
.center-actions {
  justify-content: center;
}

.center {
  text-align: center;
}

.final-score {
  font-size: 48px;
  font-weight: 900;
  color: var(--accent);
  margin: 20px 0;
  font-family: "Kanit", sans-serif;
}

.muted {
  color: var(--muted);
}
