:root {
  --bg-0: #0b1520;
  --bg-1: #122233;
  --ink: #e8eef4;
  --muted: #8fa3b5;
  --line: rgba(232, 238, 244, 0.12);
  --accent: #d4a017;
  --accent-2: #2ec4b6;
  --danger: #ff5a5f;
  --ok: #3dd68c;
  --card: rgba(18, 34, 51, 0.82);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --font: "Kanit", sans-serif;
  --mono: "Share Tech Mono", monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 10% -10%, rgba(46, 196, 182, 0.18), transparent 55%),
    radial-gradient(900px 600px at 100% 0%, rgba(212, 160, 23, 0.16), transparent 50%),
    linear-gradient(160deg, var(--bg-0), #081018 55%, #101c28);
  overflow-x: hidden;
}

.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

.glow {
  pointer-events: none;
  position: fixed;
  width: 280px;
  height: 280px;
  right: -60px;
  bottom: 12%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(212, 160, 23, 0.22), transparent 70%);
  filter: blur(8px);
  animation: float 8s ease-in-out infinite;
  z-index: 0;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-18px); }
}

.app {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  margin: 0 auto;
  padding: 28px 18px 40px;
  min-height: 100dvh;
}

.screen {
  display: none;
  animation: fadeUp 0.45s ease both;
}

.screen.active {
  display: grid;
  gap: 18px;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero {
  text-align: center;
  padding: 18px 8px 8px;
}

.codename {
  font-family: var(--mono);
  letter-spacing: 0.35em;
  font-size: 0.75rem;
  color: var(--accent-2);
}

.brand {
  font-size: clamp(4.2rem, 18vw, 5.6rem);
  line-height: 0.9;
  letter-spacing: 0.08em;
  font-weight: 700;
  background: linear-gradient(180deg, #fff 20%, #c9d6e2 70%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  animation: brandIn 0.8s ease both;
}

@keyframes brandIn {
  from { opacity: 0; letter-spacing: 0.35em; transform: scale(0.96); }
  to { opacity: 1; letter-spacing: 0.08em; transform: scale(1); }
}

.tagline {
  margin-top: 10px;
  color: var(--muted);
  font-weight: 300;
}

.game-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: -6px;
  flex-wrap: wrap;
}

.game-nav a,
.game-nav-current {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  text-decoration: none;
}

.game-nav-current {
  color: #1a1200;
  background: linear-gradient(135deg, var(--accent), #b8870d);
  border-color: transparent;
  font-weight: 600;
}

.section-head {
  text-align: center;
  display: grid;
  gap: 6px;
}

.eyebrow {
  font-family: var(--mono);
  color: var(--accent);
  letter-spacing: 0.18em;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.player-focus {
  font-size: 2.4rem;
  line-height: 1.1;
}

.muted {
  color: var(--muted);
  font-weight: 300;
  font-size: 0.95rem;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.panel-title,
.panel h3 {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 12px;
}

.panel-head .panel-title {
  margin-bottom: 0;
}

.player-count {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent-2);
  letter-spacing: 0.06em;
}

.panel-hint {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 300;
  margin-bottom: 12px;
}

.add-player {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.add-player input {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font: inherit;
}

.player-list {
  list-style: none;
  display: grid;
  gap: 8px;
}

.player-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  transition: border-color 0.2s, transform 0.2s, opacity 0.2s;
}

.player-list li:hover {
  border-color: rgba(46, 196, 182, 0.35);
  transform: translateX(2px);
}

.player-check {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  cursor: pointer;
  user-select: none;
}

.player-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.player-check .tick {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 1.5px solid rgba(232, 238, 244, 0.35);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-left: auto;
  transition: background 0.15s, border-color 0.15s;
}

.player-check .tick::after {
  content: "";
  width: 6px;
  height: 11px;
  border: solid transparent;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.player-check input:checked + .avatar + .name + .tick,
.player-check:has(input:checked) .tick {
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.player-check:has(input:checked) .tick::after {
  border-color: #081018;
}

.player-list li.off {
  opacity: 0.42;
}

.player-check .name {
  flex: 1;
}

.player-list.compact li {
  padding: 8px 10px;
}

.phone-panel .panel-title {
  margin-bottom: 14px;
}

.phone-row {
  display: grid;
  grid-template-columns: 148px 1fr;
  gap: 14px;
  align-items: center;
}

.phone-qr {
  width: 148px;
  height: 148px;
  border-radius: 14px;
  background: #fff;
  padding: 8px;
  object-fit: contain;
}

.phone-meta {
  display: grid;
  gap: 10px;
  align-content: start;
}

.phone-hint {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 300;
  line-height: 1.4;
}

.phone-url {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--accent-2);
  word-break: break-all;
  text-decoration: none;
  line-height: 1.35;
}

.btn-small {
  padding: 10px 12px;
  font-size: 0.9rem;
  width: fit-content;
}

@media (max-width: 420px) {
  .phone-row {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .phone-meta {
    justify-items: center;
  }
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 0.95rem;
  color: #081018;
  flex-shrink: 0;
}

.settings {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.field select {
  appearance: none;
  background: #0d1a26;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--font);
  font-size: 1rem;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 14px 18px;
  font-family: var(--font);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #b8870d);
  color: #1a1200;
  box-shadow: 0 10px 30px rgba(212, 160, 23, 0.28);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn-secondary {
  background: rgba(46, 196, 182, 0.16);
  color: #9ff3ea;
  border: 1px solid rgba(46, 196, 182, 0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.reveal-card {
  position: relative;
  min-height: 280px;
  border: 1px dashed rgba(212, 160, 23, 0.45);
  border-radius: 22px;
  background:
    linear-gradient(145deg, rgba(20, 36, 54, 0.95), rgba(10, 18, 28, 0.98));
  color: inherit;
  cursor: pointer;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.25s ease, border-color 0.25s ease;
}

.reveal-card:hover {
  transform: translateY(-2px);
  border-color: rgba(212, 160, 23, 0.75);
}

.reveal-card.open {
  border-style: solid;
  border-color: rgba(46, 196, 182, 0.55);
}

.reveal-card.spy.open {
  border-color: rgba(255, 90, 95, 0.65);
}

.reveal-closed,
.reveal-open {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}

.reveal-closed .stamp {
  font-family: var(--mono);
  letter-spacing: 0.28em;
  color: var(--accent);
  font-size: 0.8rem;
  border: 2px solid rgba(212, 160, 23, 0.55);
  padding: 8px 14px;
  transform: rotate(-8deg);
  margin: 0 auto 8px;
  width: fit-content;
}

.hidden {
  display: none !important;
}

.role-label {
  font-family: var(--mono);
  letter-spacing: 0.2em;
  font-size: 0.85rem;
}

.role-label.civ {
  color: var(--accent-2);
}

.role-label.spy {
  color: var(--danger);
}

.role-word {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.2;
}

.role-category,
.role-tip {
  color: var(--muted);
  font-weight: 300;
}

.progress-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.progress-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  transition: background 0.2s, transform 0.2s;
}

.progress-dots span.done {
  background: var(--accent-2);
}

.progress-dots span.current {
  background: var(--accent);
  transform: scale(1.25);
}

.timer {
  font-family: var(--mono);
  font-size: clamp(3.4rem, 16vw, 4.6rem);
  text-align: center;
  letter-spacing: 0.08em;
  color: var(--ink);
  text-shadow: 0 0 40px rgba(46, 196, 182, 0.25);
}

.timer.urgent {
  color: var(--danger);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.timer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tip-panel ul {
  margin-left: 18px;
  color: var(--muted);
  display: grid;
  gap: 8px;
  font-weight: 300;
}

.vote-grid {
  display: grid;
  gap: 10px;
}

.vote-btn {
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.05rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.vote-btn.selected {
  border-color: rgba(212, 160, 23, 0.7);
  background: rgba(212, 160, 23, 0.12);
  transform: translateX(3px);
}

.result-card {
  text-align: center;
  padding: 28px 16px;
  border-radius: 22px;
  border: 1px solid rgba(46, 196, 182, 0.35);
  background:
    radial-gradient(circle at 50% 0%, rgba(46, 196, 182, 0.18), transparent 55%),
    rgba(12, 22, 34, 0.9);
  box-shadow: var(--shadow);
}

.result-label {
  font-family: var(--mono);
  letter-spacing: 0.18em;
  color: var(--accent-2);
  font-size: 0.8rem;
  margin-bottom: 8px;
}

.result-word {
  font-size: 2rem;
  font-weight: 700;
}

.result-category {
  margin-top: 6px;
  color: var(--muted);
}

.win {
  color: var(--ok);
}

.lose {
  color: var(--danger);
}

@media (max-width: 380px) {
  .brand { font-size: 3.8rem; }
  .player-focus { font-size: 2rem; }
  .reveal-card { min-height: 240px; }
}

/* ---------- Join gate: กรอกชื่อก่อนเข้าเล่น ---------- */
.join-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 8, 10, 0.88);
  backdrop-filter: blur(4px);
}

.join-card {
  width: 100%;
  max-width: 360px;
  display: grid;
  gap: 14px;
  padding: 24px;
  border-radius: 18px;
  background: var(--panel, #15151a);
  border: 1px solid rgba(212, 160, 23, 0.25);
}

.join-card input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.35);
  color: inherit;
}

.join-error {
  min-height: 1.2em;
  margin: 0;
  color: #e0695b;
  font-size: 0.9rem;
}
