:root {
  --bg: #0f1d3a;
  --bg2: #1a2f5c;
  --ink: #1d2340;
  --paper: #fffaf0;
  --accent: #ff7a1a;
  --accent2: #ffc233;
  --good: #22a55a;
  --bad: #e2453c;
  --side: clamp(300px, 26vw, 470px);
  --speak: #45aef0;
  --vocab: #4cc569;
  --grammar: #f7a531;
  --think: #ef5b57;
  --star: #9a67ee;
  --mystery: #a9a6c4;
  --font: 'Fredoka', 'Segoe UI Rounded', 'Arial Rounded MT Bold', 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%);
  color: #fff;
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
}
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
[hidden] { display: none !important; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 16px; }
.screen.active { display: flex; }

.btn {
  border: none; border-radius: 14px; padding: .55em 1.1em;
  font-size: clamp(15px, 1.25vw, 22px); font-weight: 600;
  background: #e9ecf7; color: var(--ink);
  box-shadow: 0 4px 0 rgba(0,0,0,.25);
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.btn.big { font-size: clamp(18px, 1.7vw, 30px); padding: .6em 1.4em; border-radius: 18px; }
.btn.small { font-size: clamp(13px, 1vw, 17px); padding: .4em .9em; }
.btn.primary { background: linear-gradient(180deg, #ffb13d, var(--accent)); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.2); }
.btn.good { background: linear-gradient(180deg, #35c46f, var(--good)); color: #fff; }
.btn.bad { background: linear-gradient(180deg, #f36b62, var(--bad)); color: #fff; }
.btn:disabled { opacity: .4; pointer-events: none; }

/* ---------- title ---------- */
#screen-title {
  background: linear-gradient(rgba(15,29,58,.45), rgba(15,29,58,.75)), url(background.jpg) center / cover;
}
.title-box { text-align: center; }
.title-box h1 {
  margin: 0 0 .5em; font-size: clamp(64px, 10vw, 170px); font-weight: 700; line-height: 1;
  color: var(--accent2);
  text-shadow: 0 6px 0 #c2410c, 0 12px 30px rgba(0,0,0,.5);
  letter-spacing: .02em;
}
.title-btns { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; }

/* ---------- panels ---------- */
.panel {
  background: var(--paper); color: var(--ink); border-radius: 28px;
  padding: clamp(20px, 3vw, 48px); width: min(760px, 96vw); max-height: 96vh; overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.panel.wide { width: min(1250px, 96vw); }
.panel h2 { margin: 0 0 .2em; font-size: clamp(30px, 3.4vw, 56px); text-align: center; color: #c2410c; }
.error { color: var(--bad); font-weight: 600; text-align: center; min-height: 1.4em; margin: .5em 0; font-size: clamp(16px, 1.3vw, 22px); }
.row-btns { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

.name-row { display: flex; align-items: center; gap: 14px; margin: 8px 0; }
.name-row .pawn-mini { width: clamp(30px, 3vw, 44px); flex: none; }
.name-row input {
  flex: 1; font-size: clamp(18px, 1.7vw, 28px); padding: .35em .6em; border-radius: 12px;
  border: 3px solid #d9d4c7; background: #fff; color: var(--ink); outline: none; min-width: 0;
}
.name-row input:focus { border-color: var(--accent); }

/* ---------- reveal ---------- */
#reveal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin: 20px 0; }
.reveal-card {
  background: #fff; border-radius: 22px; padding: 18px 10px; text-align: center;
  border: 5px solid var(--pc); box-shadow: 0 8px 0 var(--pc);
  animation: drop .6s cubic-bezier(.3,1.6,.5,1) both;
}
.reveal-card .pawn-big { width: clamp(60px, 7vw, 110px); margin: 0 auto; display: block; animation: bob 2s ease-in-out infinite; }
.reveal-card .rname { font-size: clamp(24px, 2.8vw, 46px); font-weight: 700; margin-top: 6px; overflow-wrap: anywhere; }
.reveal-card .rcol { font-size: clamp(16px, 1.5vw, 26px); color: var(--pc); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
@keyframes drop { from { opacity: 0; transform: translateY(-60px) scale(.7); } to { opacity: 1; transform: none; } }
@keyframes bob { 50% { transform: translateY(-8px); } }

/* ---------- how to play ---------- */
.howto { display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(12px, 1.6vw, 26px); margin: 6px 0 22px; }
.step {
  position: relative; background: #fff; border-radius: 24px; padding: clamp(18px, 2.4vw, 34px) 12px clamp(14px, 2vw, 26px);
  display: flex; flex-direction: column; align-items: center; gap: 14px; box-shadow: 0 6px 0 #e6dfcf;
}
.step-n {
  position: absolute; top: -14px; left: -10px; width: 2.1em; height: 2.1em; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 700;
  font-size: clamp(16px, 1.4vw, 24px); box-shadow: 0 3px 0 #c2410c;
}
.vis { height: clamp(70px, 8vw, 120px); display: flex; align-items: center; justify-content: center; gap: 6px; }
.vis .die { width: clamp(64px, 6.5vw, 104px); height: clamp(64px, 6.5vw, 104px); cursor: default; }
.mtile {
  width: clamp(46px, 4.6vw, 76px); height: clamp(46px, 4.6vw, 76px); border-radius: 14px; background: var(--c);
  border: 3px solid #1f1a36; display: grid; place-items: center; font-size: clamp(22px, 2.2vw, 36px);
  font-weight: 700; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.3); box-shadow: inset 0 0 0 3px rgba(255,255,255,.45);
}
.mtile.plain { background: #fff4dc; width: clamp(64px, 6.4vw, 104px); height: clamp(64px, 6.4vw, 104px); }
.cap { font-size: clamp(22px, 2.3vw, 40px); font-weight: 700; text-align: center; line-height: 1.1; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chips.center { margin: 4px 0 14px; }
.chip {
  font-size: clamp(16px, 1.5vw, 26px); font-weight: 600; padding: .2em .7em; border-radius: 99px;
  background: #eee; color: var(--ink);
}
.chip.good { background: #dcfce7; color: #15803d; }
.chip.bad { background: #fee2e2; color: #b91c1c; }

/* ---------- game layout ---------- */
#screen-game {
  padding: 0; justify-content: flex-start; align-items: stretch;
  background: radial-gradient(ellipse at 40% 50%, rgba(10,18,40,.05), rgba(10,18,40,.45)), url(background.jpg) center / cover;
}
#board-area { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; }
#board {
  position: relative;
  width: min(calc(100vw - var(--side)), calc(100vh * 1400 / 1050));
  aspect-ratio: 1400 / 1050;
}
#track { width: 100%; height: 100%; display: block; overflow: visible; }
#track text { font-family: var(--font); font-weight: 700; text-anchor: middle; dominant-baseline: central; }
#track .num-light { fill: #1d2340; }
#track .num-dark { fill: #fff; stroke: rgba(20,20,45,.75); stroke-width: 5px; paint-order: stroke; stroke-linejoin: round; }
#track .ico { font-size: 34px; }

#side {
  width: var(--side); flex: none; display: flex; flex-direction: column; gap: 1vh;
  padding: 1.2vh 14px; background: rgba(14,26,56,.84);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-left: 4px solid rgba(255,255,255,.18); overflow: hidden;
}
.side-icons { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn { background: rgba(255,255,255,.12); color: #fff; border: none; border-radius: 10px; width: 2.1em; height: 2.1em; font-size: clamp(14px, 1.1vw, 18px); }
.icon-btn:hover { background: rgba(255,255,255,.22); }

#turn-box {
  display: flex; align-items: center; gap: 12px; border-radius: 18px; padding: 1vh 14px;
  background: var(--pc, #666); box-shadow: inset 0 -5px 0 rgba(0,0,0,.2), 0 0 0 3px rgba(255,255,255,.8);
  transition: background .3s;
}
#turn-pawn { width: clamp(36px, 3.4vw, 56px); flex: none; filter: drop-shadow(0 3px 2px rgba(0,0,0,.35)); }
#turn-name { font-size: clamp(22px, min(2.6vw, 4.6vh), 46px); font-weight: 700; line-height: 1; text-shadow: 0 2px 0 rgba(0,0,0,.3); overflow-wrap: anywhere; }
#turn-box.dark-text #turn-name { color: var(--ink); text-shadow: none; }

#dice-box { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; row-gap: .8vh; align-items: center; }
#dice-box .die { grid-row: 1 / 3; border: none; cursor: pointer; }
.roll { font-size: clamp(20px, min(1.9vw, 3.4vh), 34px); width: 100%; padding: .4em; }
.manual { display: flex; gap: 4px; justify-content: center; opacity: .55; transition: opacity .15s; }
.manual:hover { opacity: 1; }
.num { width: 2em; height: 2em; border-radius: 8px; border: 2px solid rgba(255,255,255,.4); background: rgba(255,255,255,.1); color: #fff; font-weight: 700; font-size: clamp(12px, 1vw, 17px); }
.num:hover { background: rgba(255,255,255,.25); }
#dice-box.locked .roll, #dice-box.locked .num { opacity: .35; pointer-events: none; }

/* die */
.die {
  width: clamp(60px, min(5.6vw, 11vh), 104px); height: clamp(60px, min(5.6vw, 11vh), 104px); flex: none; border-radius: 18%;
  background: linear-gradient(145deg, #fff, #e4e4ee); box-shadow: inset 0 -6px 0 #c9c9d8, 0 6px 14px rgba(0,0,0,.4);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: clamp(9px, 1.3vh, 15px); gap: 3px;
}
.die i { width: 100%; height: 100%; border-radius: 50%; background: #1d2340; visibility: hidden; }
.die i.on { visibility: visible; }
.die.rolling { animation: shake .12s linear infinite; }
.die.done { animation: pop .35s ease; }
@keyframes shake { 0% { transform: rotate(-14deg) scale(1.05); } 50% { transform: rotate(14deg) scale(.95); } 100% { transform: rotate(-14deg) scale(1.05); } }
@keyframes pop { 50% { transform: scale(1.3); } }

#status { min-height: 1.4em; text-align: center; font-size: clamp(15px, 1.3vw, 22px); font-weight: 500; color: var(--accent2); }

#player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5vh; flex: 1; min-height: 0; }
#player-list li {
  display: flex; align-items: center; gap: 10px; padding: .3vh 10px; border-radius: 12px;
  background: rgba(255,255,255,.08); border: 2px solid transparent; font-size: clamp(14px, min(1.35vw, 2.5vh), 24px);
}
#player-list li.current { background: rgba(255,255,255,.18); border-color: var(--pc); }
#player-list li.finished { opacity: .75; }
#player-list .pawn-mini { width: clamp(20px, 1.8vw, 30px); flex: none; }
#player-list .pname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#player-list .ppos { font-weight: 700; min-width: 2.2em; text-align: right; }

/* ---------- pawns on the board ---------- */
.pawn {
  position: absolute; width: 3.4%; transform: translate(-50%, -86%);
  transition: left .26s ease-in-out, top .26s ease-in-out; z-index: 2; pointer-events: none;
}
.pawn svg { width: 100%; display: block; filter: drop-shadow(0 3px 2px rgba(0,0,0,.5)); }
.pawn.hop svg { animation: hop .26s ease-out; }
.pawn.current { z-index: 5; }
.pawn.current svg { animation: glow 1.2s ease-in-out infinite; }
.pawn.current.hop svg { animation: hop .26s ease-out; }
.pawn .tag {
  display: none; position: absolute; bottom: 104%; left: 50%; transform: translateX(-50%);
  background: var(--pc); color: #fff; font-weight: 700; white-space: nowrap;
  font-size: clamp(11px, 1.05vw, 20px); padding: .1em .55em; border-radius: 99px;
  border: 2px solid #fff; box-shadow: 0 3px 6px rgba(0,0,0,.4); animation: tagbob 1s ease-in-out infinite;
}
.pawn .tag.dark-text { color: var(--ink); }
.pawn.current .tag { display: block; }
@keyframes hop { 40% { transform: translateY(-45%) scale(1.08); } 100% { transform: none; } }
@keyframes glow { 50% { filter: drop-shadow(0 0 6px #fff) drop-shadow(0 0 12px #fff) drop-shadow(0 3px 2px rgba(0,0,0,.5)); transform: translateY(-6%); } }
@keyframes tagbob { 50% { transform: translateX(-50%) translateY(-18%); } }

#land-ring {
  position: absolute; width: 9%; aspect-ratio: 1; border-radius: 50%; transform: translate(-50%, -50%);
  border: 5px solid #fff; box-shadow: 0 0 20px 6px var(--rc, #fff); opacity: 0; pointer-events: none; z-index: 1;
}
#land-ring.show { animation: ring 1.1s ease-out; }
@keyframes ring { 0% { opacity: 1; transform: translate(-50%, -50%) scale(.4); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); } }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(8,14,32,.6); z-index: 20; padding: 16px;
}
.overlay.show { display: flex; }

.dialog {
  background: var(--paper); color: var(--ink); border-radius: 28px; padding: clamp(20px, 3vw, 44px);
  text-align: center; width: min(760px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: dlg .35s cubic-bezier(.3,1.5,.5,1);
}
@keyframes dlg { from { transform: scale(.7); opacity: 0; } }
.dialog-ico { font-size: clamp(50px, 5vw, 90px); line-height: 1; }
.dialog h3 { font-size: clamp(28px, 3vw, 52px); margin: .2em 0; }
.dialog p { font-size: clamp(18px, 1.8vw, 30px); margin: .4em 0 1em; line-height: 1.35; }
.menu-btns { display: flex; flex-direction: column; gap: 12px; align-items: center; margin: 16px 0; }
.keys { font-size: clamp(13px, 1vw, 17px); color: #555; line-height: 1.5; }

#win-ranking { text-align: left; font-size: clamp(20px, 2vw, 34px); display: inline-block; margin: .4em auto 1em; padding-left: 1.6em; }
#win-ranking li { margin: .2em 0; }
#win-ranking li b { color: var(--pc); text-shadow: 0 0 1px #1d2340, 0 1px 1px #1d2340, 0 -1px 1px rgba(29,35,64,.6); }

/* ---------- flash card ---------- */
.card {
  background: var(--paper); color: var(--ink); border-radius: 30px; width: min(1200px, 94vw); max-height: 94vh; overflow: auto;
  box-shadow: 0 0 0 8px var(--cc), 0 24px 70px rgba(0,0,0,.55); padding: 0 0 clamp(14px, 2vh, 26px);
}
.card.enter { animation: flip .55s cubic-bezier(.3,1.3,.5,1); }
@keyframes flip { from { transform: perspective(1200px) rotateY(80deg) scale(.6); opacity: 0; } }
.card-head {
  display: flex; align-items: center; gap: 14px; background: var(--cc); color: #fff;
  padding: clamp(10px, 1.5vh, 18px) clamp(16px, 2vw, 32px); font-weight: 700;
  font-size: clamp(22px, 2.2vw, 38px); text-shadow: 0 2px 0 rgba(0,0,0,.2);
}
.card-ico { font-size: 1.3em; filter: drop-shadow(0 2px 1px rgba(0,0,0,.3)); }
.card-type { text-transform: uppercase; letter-spacing: .05em; }
.card-player { margin-left: auto; background: var(--pc); border: 3px solid #fff; border-radius: 99px; padding: .05em .7em; font-size: .85em; }
.card-player.dark-text { color: var(--ink); text-shadow: none; }
.card-stakes {
  margin-left: auto; font-size: .7em; padding: .15em .7em; border-radius: 99px;
  background: rgba(255,255,255,.92); text-shadow: none;
}
.card-stakes.must { color: #b91c1c; }
.card-stakes.bonus { color: #15803d; }
.card-stakes.final { color: #6d28d9; }
.card-stakes + .card-player { margin-left: 0; }
.card-q {
  font-size: clamp(26px, 3.1vw, 58px); font-weight: 600; line-height: 1.3; text-align: center;
  padding: clamp(14px, 3vh, 40px) clamp(18px, 3vw, 56px) clamp(10px, 2vh, 26px);
}
.card-q b { color: #c2410c; }
.blank { display: inline-block; min-width: 3.2em; border-bottom: .09em solid currentColor; margin: 0 .1em; }
.card-options { display: flex; flex-wrap: wrap; gap: clamp(10px, 1.2vw, 20px); justify-content: center; padding: 0 clamp(18px, 3vw, 56px); }
.opt {
  font-size: clamp(22px, 2.5vw, 46px); font-weight: 600; background: #fff; color: var(--ink);
  border: 4px solid #d6d0c2; border-radius: 18px; padding: .3em .8em; min-width: 5em;
  box-shadow: 0 5px 0 #d6d0c2; display: flex; align-items: center; gap: .5em;
}
.opt .k { display: inline-grid; place-items: center; width: 1.4em; height: 1.4em; border-radius: 50%; background: var(--cc); color: #fff; font-size: .7em; flex: none; }
.opt:hover { border-color: var(--cc); }
.opt.right { background: #dcfce7; border-color: var(--good); box-shadow: 0 5px 0 var(--good); }
.opt.wrong { background: #fee2e2; border-color: var(--bad); box-shadow: 0 5px 0 var(--bad); }
.card-options.done .opt { pointer-events: none; }

.card-timer { display: flex; align-items: center; gap: 16px; padding: 10px clamp(18px, 3vw, 56px) 0; }
.timer-bar { flex: 1; height: clamp(14px, 1.6vh, 22px); background: #e5e0d4; border-radius: 99px; overflow: hidden; }
.timer-fill { height: 100%; width: 100%; background: var(--cc); border-radius: 99px; transition: width 1s linear; }
.timer-num { font-size: clamp(28px, 3vw, 52px); font-weight: 700; min-width: 2.2em; text-align: right; }
.card-timer.ending .timer-num { color: var(--bad); animation: pop .5s ease infinite; }

.card-reveal {
  margin: clamp(10px, 2vh, 22px) clamp(18px, 3vw, 56px) 0; background: #fff; border: 3px dashed var(--cc); border-radius: 18px;
  padding: .6em 1em; text-align: center; animation: dlg .3s ease;
}
.reveal-ans { font-size: clamp(22px, 2.4vw, 42px); font-weight: 700; color: var(--good); }
.reveal-e { font-size: clamp(17px, 1.6vw, 28px); color: #444; margin-top: .2em; }
.reveal-e:empty { display: none; }

.card-controls { display: flex; gap: 12px; align-items: center; padding: clamp(12px, 2vh, 24px) clamp(18px, 3vw, 56px) 0; flex-wrap: wrap; }
.card-controls .spacer { flex: 1; }
.card-controls .btn { font-size: clamp(17px, 1.6vw, 28px); min-width: 3em; }
.card-controls .btn.judge { font-size: clamp(26px, 2.6vw, 46px); min-width: 2.6em; padding: .15em .6em; }
.card-controls .btn.suggest { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(255,255,255,.9), 0 0 24px 8px rgba(0,0,0,.25); } }

.card[data-type=speak]   { --cc: var(--speak); }
.card[data-type=vocab]   { --cc: var(--vocab); }
.card[data-type=grammar] { --cc: var(--grammar); }
.card[data-type=think]   { --cc: var(--think); }
.card[data-type=star]    { --cc: var(--star); }
.card[data-type=mystery] { --cc: #7f7ca3; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(.6); opacity: 0; z-index: 40;
  background: var(--tc, #1d2340); color: #fff; border: 6px solid #fff; border-radius: 30px;
  padding: .5em 1.4em; text-align: center; pointer-events: none; transition: opacity .2s, transform .3s cubic-bezier(.3,1.6,.5,1);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast-big { font-size: clamp(36px, 4.6vw, 84px); font-weight: 700; text-shadow: 0 3px 0 rgba(0,0,0,.2); }
.toast-small { font-size: clamp(20px, 2.1vw, 38px); font-weight: 500; }
.toast-small:empty { display: none; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

/* ---------- narrow screens (just in case) ---------- */
@media (max-width: 900px) {
  #screen-game { flex-direction: column; overflow: auto; }
  #board { width: 100vw; }
  #side { width: 100%; border-left: none; overflow: visible; }
  #reveal-grid { grid-template-columns: repeat(2, 1fr); }
  .howto { grid-template-columns: repeat(2, 1fr); row-gap: 26px; }
}
