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

:root {
  --t: 52px;                 /* token size, set by JS layout() */
  --gold: #e3bd6a;
  --gold-deep: #a97c2c;
  --ink: #3a2708;
  --bg: #14111a;
  --panel: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.13);
}

html, body { height: 100%; }

body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #241d31 0%, var(--bg) 60%),
    var(--bg);
  color: #e9e2d2;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow-x: hidden;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px calc(78px + env(safe-area-inset-bottom));
}

/* ---- bottom tab bar ---- */

#tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(20, 17, 26, 0.7), #14111a 40%);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1;
  max-width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 4px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: none;
  color: rgba(233, 226, 210, 0.6);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.tab .ti { font-size: 19px; line-height: 1; }
.tab.active {
  color: var(--gold);
  background: rgba(227, 189, 106, 0.1);
  border-color: rgba(227, 189, 106, 0.4);
}
.tab:active { transform: scale(0.95); }

/* ---- header ---- */

header {
  width: 100%;
  max-width: 720px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 4px 10px;
}

.brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 2px 10px rgba(227, 189, 106, 0.25);
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand .byline {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.32em;
  color: rgba(227, 189, 106, 0.55);
  text-shadow: none;
  padding-left: 26px;
}

.chips { display: flex; gap: 6px; }

.chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  white-space: nowrap;
}
.chip b { color: var(--gold); font-variant-numeric: tabular-nums; }

.btns { display: flex; gap: 6px; }

.btns button {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: #e9e2d2;
  font-size: 17px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btns button:active { transform: scale(0.92); }
.btns button:disabled { opacity: 0.35; cursor: default; }
.btns button.active {
  border-color: rgba(227, 189, 106, 0.7);
  box-shadow: 0 0 10px rgba(227, 189, 106, 0.3);
}

/* ---- board ---- */

#board {
  flex: 1;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 14px 10px;
  padding: 10px 0 6px;
}

.tube {
  position: relative;
  width: calc(var(--t) + 18px);
  height: calc(var(--cap, 4) * (var(--t) + 6px) + 16px);
  border: 2px solid var(--line);
  border-top-color: rgba(255, 255, 255, 0.22);
  border-radius: 14px 14px calc(var(--t) / 1.6) calc(var(--t) / 1.6);
  background:
    linear-gradient(105deg, rgba(255, 255, 255, 0.09) 0%, rgba(255, 255, 255, 0.02) 30%, rgba(255, 255, 255, 0.05) 100%);
  box-shadow:
    inset 0 -10px 22px rgba(0, 0, 0, 0.35),
    inset 4px 0 10px rgba(255, 255, 255, 0.05),
    0 6px 16px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  padding: 0;
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
}

.tube.sel {
  border-color: rgba(227, 189, 106, 0.75);
  box-shadow:
    0 0 0 3px rgba(227, 189, 106, 0.18),
    0 0 22px rgba(227, 189, 106, 0.28),
    inset 0 -10px 22px rgba(0, 0, 0, 0.35);
}

.tube.done {
  border-color: rgba(140, 220, 160, 0.55);
  box-shadow:
    0 0 14px rgba(140, 220, 160, 0.22),
    inset 0 -10px 22px rgba(0, 0, 0, 0.35);
}

.tube.pop { animation: pop 0.45s ease; }
@keyframes pop {
  35% { transform: scale(1.07); }
}

.tube.shake { animation: shake 0.3s ease; }
@keyframes shake {
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

/* Hint / tutorial highlights: source glows gold, destination glows green. */
.tube.hintsrc, .tube.coach {
  border-color: rgba(227, 189, 106, 0.95);
  box-shadow:
    0 0 0 3px rgba(227, 189, 106, 0.3),
    0 0 22px rgba(227, 189, 106, 0.55),
    inset 0 -10px 22px rgba(0, 0, 0, 0.35);
  animation: coachPulse 1s ease-in-out infinite;
}
.tube.hintdst {
  border-color: rgba(140, 220, 160, 0.95);
  box-shadow:
    0 0 0 3px rgba(140, 220, 160, 0.3),
    0 0 22px rgba(140, 220, 160, 0.55),
    inset 0 -10px 22px rgba(0, 0, 0, 0.35);
  animation: coachPulse 1s ease-in-out infinite;
}
@keyframes coachPulse {
  50% { transform: translateY(-5px); }
}

/* ---- tokens ---- */

.token {
  position: absolute;
  left: 50%;
  bottom: calc(8px + var(--slot) * (var(--t) + 6px));
  width: var(--t);
  height: var(--t);
  margin-left: calc(var(--t) / -2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--t) * 0.62);
  line-height: 1;
  color: var(--ink);
  background: radial-gradient(circle at 32% 28%, #f7e3ab 0%, #e3bd6a 45%, var(--gold-deep) 100%);
  box-shadow:
    inset 0 -3px 6px rgba(0, 0, 0, 0.28),
    inset 0 3px 5px rgba(255, 255, 255, 0.45),
    0 3px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.18s ease;
  pointer-events: none;
}

.token.lifted {
  transform: translateY(calc(-1 * ((var(--cap, 4) - 1 - var(--slot)) * (var(--t) + 6px) + var(--t) * 0.55)));
}

/* The black court (groups 6-11): ebony tokens with a gold-ringed glyph. */
.token.t6, .token.t7, .token.t8, .token.t9, .token.t10, .token.t11 {
  background: radial-gradient(circle at 32% 28%, #4a4256 0%, #262130 55%, #14101c 100%);
  color: #e3bd6a;
  box-shadow:
    inset 0 0 0 2px rgba(227, 189, 106, 0.35),
    inset 0 -3px 6px rgba(0, 0, 0, 0.5),
    0 3px 6px rgba(0, 0, 0, 0.4);
}

/* Academy tokens: rounded-square medallions. The board fills the token and
   is clipped by its rounded corners, with a gold rim ring on top. */
.token.academy {
  border-radius: 22%;
  overflow: hidden;
  background: #a8845a;
  box-shadow:
    inset 0 0 0 2.5px rgba(227, 189, 106, 0.95),
    inset 0 0 0 4px rgba(138, 94, 20, 0.55),
    0 3px 6px rgba(0, 0, 0, 0.45);
}
.token.academy .mini {
  width: 100%;
  height: 100%;
  display: block;
  margin: 0;
}

/* Champion fact cards. */
.token.academy .champCard {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12%;
  background: linear-gradient(160deg, #f4e6bd 0%, #dfc180 60%, #c09a4d 100%);
  color: #3a2708;
  font-size: calc(var(--t) * 0.16);
  font-weight: 600;
  line-height: 1.25;
}
.champCard.big {
  width: 160px;
  height: 160px;
  border-radius: 18px;
  font-size: 19px;
}

/* Course picker */
#courseList { display: grid; gap: 8px; margin-bottom: 16px; }
.courseBtn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  color: #e9e2d2;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.courseBtn:hover { border-color: rgba(227, 189, 106, 0.5); }
.courseBtn:active { transform: scale(0.98); }
.courseBtn.active { border-color: var(--gold); box-shadow: 0 0 12px rgba(227, 189, 106, 0.25); }
.courseBtn .ce { font-size: 24px; flex: 0 0 32px; text-align: center; }
.courseBtn .ct { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.courseBtn .ct b { font-size: 15px; }
.courseBtn .ct small { font-size: 12px; color: rgba(233, 226, 210, 0.6); }
.courseBtn .cl { font-size: 12px; color: var(--gold); white-space: nowrap; }
.courseBtn.exit { opacity: 0.85; }

#magnify {
  position: fixed;
  top: 64px;
  right: 10px;
  z-index: 60;
  background: linear-gradient(170deg, #2b2438, #1d1828);
  border: 1px solid rgba(227, 189, 106, 0.45);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.2s ease;
}
#magnify.hidden { display: none; }
#magnify .magLabel {
  font-size: 11px;
  color: rgba(233, 226, 210, 0.65);
  max-width: 160px;
  text-align: center;
}

/* Face-down pieces on Mystery levels. */
.token.mystery {
  background: radial-gradient(circle at 32% 28%, #3b3547 0%, #211c2c 60%, #131019 100%);
  color: rgba(233, 226, 210, 0.5);
  font-weight: 700;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.08),
    inset 0 -3px 6px rgba(0, 0, 0, 0.5),
    0 3px 6px rgba(0, 0, 0, 0.4);
}

.token.fly {
  position: fixed;
  left: 0;
  top: 0;
  margin: 0;
  z-index: 50;
  transition: none;
}

/* ---- colorful theme: each piece type gets its own jewel hue ---- */

body[data-theme="colorful"] .token.t0 { background: radial-gradient(circle at 32% 28%, #b8e8c2 0%, #6cc47f 45%, #3d8a4f 100%); color: #0e2f16; }
body[data-theme="colorful"] .token.t1 { background: radial-gradient(circle at 32% 28%, #c4dcf7 0%, #6fa7e8 45%, #38699f 100%); color: #0e2440; }
body[data-theme="colorful"] .token.t2 { background: radial-gradient(circle at 32% 28%, #e0cbf5 0%, #b07fe0 45%, #6f4796 100%); color: #2a1440; }
body[data-theme="colorful"] .token.t3 { background: radial-gradient(circle at 32% 28%, #f5c4c4 0%, #e07070 45%, #9c3d3d 100%); color: #3d0e0e; }
body[data-theme="colorful"] .token.t4 { background: radial-gradient(circle at 32% 28%, #f7e3ab 0%, #e8b84f 45%, #a97c2c 100%); color: #3a2708; }
body[data-theme="colorful"] .token.t5 { background: radial-gradient(circle at 32% 28%, #ffffff 0%, #e4e4ee 45%, #9c9cb0 100%); color: #26263a; }

/* Colorful black court: ebony discs, glyph tinted to match the white twin. */
body[data-theme="colorful"] .token.t6 { color: #6cc47f; box-shadow: inset 0 0 0 2px rgba(108, 196, 127, 0.4), inset 0 -3px 6px rgba(0,0,0,.5), 0 3px 6px rgba(0,0,0,.4); }
body[data-theme="colorful"] .token.t7 { color: #6fa7e8; box-shadow: inset 0 0 0 2px rgba(111, 167, 232, 0.4), inset 0 -3px 6px rgba(0,0,0,.5), 0 3px 6px rgba(0,0,0,.4); }
body[data-theme="colorful"] .token.t8 { color: #b07fe0; box-shadow: inset 0 0 0 2px rgba(176, 127, 224, 0.4), inset 0 -3px 6px rgba(0,0,0,.5), 0 3px 6px rgba(0,0,0,.4); }
body[data-theme="colorful"] .token.t9 { color: #e07070; box-shadow: inset 0 0 0 2px rgba(224, 112, 112, 0.4), inset 0 -3px 6px rgba(0,0,0,.5), 0 3px 6px rgba(0,0,0,.4); }
body[data-theme="colorful"] .token.t10 { color: #e8b84f; box-shadow: inset 0 0 0 2px rgba(232, 184, 79, 0.4), inset 0 -3px 6px rgba(0,0,0,.5), 0 3px 6px rgba(0,0,0,.4); }
body[data-theme="colorful"] .token.t11 { color: #e4e4ee; box-shadow: inset 0 0 0 2px rgba(228, 228, 238, 0.4), inset 0 -3px 6px rgba(0,0,0,.5), 0 3px 6px rgba(0,0,0,.4); }

/* Trial move-counter running hot */
.chip.warn {
  border-color: rgba(224, 112, 112, 0.65);
  color: #f0a0a0;
}
.chip.warn b { color: #f07070; }

/* ---- hint / toast ---- */

#hint {
  font-size: 13.5px;
  color: var(--gold);
  padding: 4px 12px 0;
  text-align: center;
  animation: pulse 1.8s ease-in-out infinite;
}
#hint.hidden { display: none; }
@keyframes pulse {
  50% { opacity: 0.45; }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 120;
  max-width: 88vw;
  background: linear-gradient(170deg, #2b2438, #1d1828);
  border: 1px solid rgba(227, 189, 106, 0.4);
  border-radius: 14px;
  padding: 10px 16px;
  font-size: 14px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.25s ease;
}
#toast.hidden { display: none; }
@keyframes toastIn {
  from { transform: translateX(-50%) translateY(12px); opacity: 0; }
}

/* ---- tutorial coach banner ---- */

#coach {
  position: fixed;
  left: 50%;
  top: calc(56px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 80;
  width: min(92vw, 460px);
  background: linear-gradient(170deg, #322a44, #201a2e);
  border: 1px solid rgba(227, 189, 106, 0.55);
  border-radius: 16px;
  padding: 12px 16px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  animation: coachIn 0.25s ease;
}
#coach.hidden { display: none; }
#coach .ctext { font-size: 14.5px; line-height: 1.4; color: #f2ead8; }
#coach .ctext b { color: var(--gold); }
#coach .cbtns { margin-top: 10px; display: flex; justify-content: center; }
#coach #coachStart, #coach #introOk {
  border: none;
  border-radius: 12px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(180deg, #f0cd82, #cfa14b);
  color: #2c1e06;
}
#coach .skip {
  background: none;
  border: none;
  color: rgba(233, 226, 210, 0.55);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}
@keyframes coachIn {
  from { transform: translateX(-50%) translateY(-10px); opacity: 0; }
}

/* ---- par note ---- */

#parNote {
  font-size: 12.5px;
  color: rgba(233, 226, 210, 0.55);
  padding: 6px 0 2px;
  letter-spacing: 0.03em;
}
#parNote b { color: var(--gold); }

/* ---- overlays ---- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 14, 0.72);
  backdrop-filter: blur(6px);
  padding: 18px;
}
.overlay.hidden { display: none; }

.card {
  width: min(92vw, 380px);
  max-height: 80dvh; /* long content (help, map) scrolls inside the card */
  overflow-y: auto;
  overscroll-behavior: contain;
  background: linear-gradient(170deg, #221c2e, #171320);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 26px 24px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  animation: cardIn 0.3s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(227, 189, 106, 0.35) transparent;
}
.card { position: relative; }
/* Dismisses a panel so the board behind it can be seen. Only panels whose
   content is short enough not to scroll carry one, so absolute is safe. */
.cardClose {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 34px;
  height: 34px;
  min-width: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  color: #e8e4f0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.cardClose:active { background: rgba(255, 255, 255, 0.16); }

.card::-webkit-scrollbar { width: 6px; }
.card::-webkit-scrollbar-thumb { background: rgba(227, 189, 106, 0.35); border-radius: 3px; }
@keyframes cardIn {
  from { transform: translateY(14px) scale(0.97); opacity: 0; }
}

.card h1 {
  font-size: 26px;
  color: var(--gold);
  margin-bottom: 6px;
  letter-spacing: 0.03em;
}

.stars {
  font-size: 42px;
  color: var(--gold);
  letter-spacing: 6px;
  text-shadow: 0 3px 16px rgba(227, 189, 106, 0.45);
  margin: 4px 0 8px;
}

.detail { font-size: 14px; color: rgba(233, 226, 210, 0.75); margin-bottom: 18px; }

.rules {
  list-style: none;
  text-align: left;
  font-size: 14px;
  line-height: 1.45;
  margin: 14px 0 18px;
  display: grid;
  gap: 10px;
}
.rules li { display: flex; gap: 10px; align-items: flex-start; }
.rules .ri { font-size: 18px; flex: 0 0 24px; text-align: center; color: var(--gold); }

.btnRow { display: flex; gap: 10px; justify-content: center; }

.btnRow button {
  border: none;
  border-radius: 14px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(180deg, #f0cd82, #cfa14b);
  color: #2c1e06;
  box-shadow: 0 4px 14px rgba(227, 189, 106, 0.3);
  transition: transform 0.1s;
}
.btnRow button:active { transform: scale(0.95); }
.btnRow button.secondary {
  background: var(--panel);
  border: 1px solid var(--line);
  color: #e9e2d2;
  box-shadow: none;
}

.credit {
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: rgba(233, 226, 210, 0.45);
}
.credit b { color: rgba(227, 189, 106, 0.7); }
.credit a { color: rgba(233, 226, 210, 0.55); }

/* ---- journey map ---- */

.mapCard { width: min(94vw, 420px); }

.mapNote {
  font-size: 13px;
  color: rgba(233, 226, 210, 0.65);
  margin-bottom: 12px;
}

.mapNav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
}
.mapNav span { font-size: 14px; color: var(--gold); min-width: 110px; }
.mapNav button {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: #e9e2d2;
  font-size: 17px;
  cursor: pointer;
}
.mapNav button:disabled { opacity: 0.3; cursor: default; }

#mapGrid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.cell {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: #e9e2d2;
  padding: 8px 2px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.1s, border-color 0.15s;
}
.cell:not(.locked):hover { transform: scale(1.06); border-color: rgba(227, 189, 106, 0.5); }
.cell .n { font-size: 15px; font-weight: 700; }
.cell .s { font-size: 11px; color: var(--gold); letter-spacing: 1px; }
.cell.done { border-color: rgba(227, 189, 106, 0.45); }
.cell.current {
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(227, 189, 106, 0.35);
  animation: pulse 1.8s ease-in-out infinite;
}
.cell.locked { opacity: 0.4; cursor: default; }

.recTitle {
  font-size: 12px;
  color: rgba(233, 226, 210, 0.5);
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.records {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 6px;
  margin-bottom: 16px;
}
.rec {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.rec b { font-size: 16px; color: var(--gold); }
.rec span { font-size: 10.5px; color: rgba(233, 226, 210, 0.6); }

/* ---- achievements ---- */

.achGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 6px;
  margin-bottom: 16px;
}
.ach {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  opacity: 0.45;
}
.ach .an { font-size: 18px; }
.ach .at { font-size: 9px; text-align: center; line-height: 1.15; color: rgba(233, 226, 210, 0.6); }
.ach.got {
  opacity: 1;
  border-color: rgba(227, 189, 106, 0.45);
  box-shadow: 0 0 10px rgba(227, 189, 106, 0.2);
}
.ach.got .at { color: var(--gold); }

/* ---- confetti ---- */

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti span {
  position: absolute;
  top: -6vh;
  color: var(--gold);
  animation: fall linear forwards;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
@keyframes fall {
  to { transform: translateY(115vh) rotate(340deg); opacity: 0.7; }
}
