:root {
  --ink: #14173A;        /* midnight ink: page background */
  --panel: #232763;      /* nebula plum: surfaces */
  --panel-2: #2d3280;
  --line: #3b4199;
  --star: #F4F6FF;       /* star white: text */
  --dust: #9aa0cf;       /* dust: secondary text / locked */
  --mint: #4ff0bd;       /* comet mint: passed, success */
  --mint-ink: #07382c;
  --sun: #ffb347;        /* solar tangerine: time + highlights */
  --coral: #ff6f81;      /* alert */
  --radius: 18px;
  --font-display: 'Kanit', 'Sarabun', system-ui, sans-serif;
  --font-body: 'Sarabun', 'Kanit', system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--ink); color: var(--star);
  font: 400 1.05rem/1.5 var(--font-body); -webkit-tap-highlight-color: transparent;
}
.sky {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff9 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 12%, #fff8 50%, transparent 51%),
    radial-gradient(2px 2px at 46% 34%, #ffe9b8 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 56%, #fff8 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 24% 72%, #fff9 50%, transparent 51%),
    radial-gradient(1px 1px at 63% 84%, #fff7 50%, transparent 51%),
    radial-gradient(120% 70% at 85% -10%, #3a2f9a55, transparent 60%),
    radial-gradient(90% 60% at 0% 110%, #1b6f8a40, transparent 60%);
}
h1, h2, h3 { font-family: var(--font-display); margin: 0; line-height: 1.2; letter-spacing: .1px; }
h1 { font-size: clamp(1.6rem, 5vw, 2.3rem); font-weight: 600; }
h2 { font-size: 1.35rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 500; }
p { margin: 0; }
a { color: var(--mint); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; border-radius: 8px; }

.wrap { width: min(1080px, 100%); margin: 0 auto; padding: 18px 16px 120px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.top .brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top .brand b { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .logo { font-size: 1.6rem; }
.muted { color: var(--dust); }
.small { font-size: .9rem; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 20px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--panel); font-family: var(--font-display); font-weight: 500; font-size: 1.05rem; text-decoration: none; color: var(--star);
}
.btn:hover { background: var(--panel-2); }
.btn.go { background: var(--mint); color: var(--mint-ink); border-color: var(--mint); font-weight: 600; }
.btn.go:hover { background: #7bf6d0; }
.btn.warn { background: var(--sun); color: #3d2600; border-color: var(--sun); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--coral); color: var(--coral); background: transparent; }
.btn.big, .result .btn.big { min-height: 56px; font-size: 1.2rem; padding: 12px 28px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.spacer { flex: 1; }

/* home: profile cards */
.profiles { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr)); }
.pcard { background: var(--panel); border: 2px solid var(--line); border-radius: 24px; padding: 18px; display: grid; gap: 14px; }
.pcard header { display: flex; gap: 14px; align-items: center; }
.avatar { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-size: 2rem; background: var(--ink); border: 3px solid var(--sun); flex: none; }
.pcard h2 { font-size: 1.5rem; }
.gauge { display: grid; gap: 6px; }
.gauge .bar { height: 16px; border-radius: 99px; background: var(--ink); border: 2px solid var(--line); overflow: hidden; }
.gauge .bar i { display: block; height: 100%; background: var(--mint); border-radius: 99px; min-width: 0; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.gauge .meta { display: flex; justify-content: space-between; gap: 8px; font-size: .95rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-width: 44px; padding: 4px 12px; border-radius: 99px; font-family: var(--font-display); font-weight: 500; text-align: center; border: 2px solid transparent; font-size: .95rem; }
.chip.passed { background: var(--mint); color: var(--mint-ink); }
.chip.current { background: transparent; border-color: var(--mint); color: var(--mint); }
.chip.locked { background: #3a3f78; color: #8d93c6; }
.bucket { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 8px; }
.bucket div { background: var(--ink); border-radius: 14px; padding: 8px 10px; text-align: center; }
.bucket b { display: block; font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; }
.bucket span { font-size: .82rem; color: var(--dust); }
.pace { font-size: .95rem; }
.empty { text-align: center; padding: 48px 16px; }
.empty div.big { font-size: 3rem; }

/* map */
.mission { background: var(--panel); border: 2px solid var(--line); border-radius: 24px; padding: 18px; margin-bottom: 18px; }
.mission.locked { opacity: .6; }
.mission header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 18px; }
.bankpill { background: var(--ink); border: 2px solid var(--sun); color: var(--sun); border-radius: 99px; padding: 4px 14px; font-family: var(--font-display); font-weight: 500; }
.route { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px 0; position: relative; padding: 4px 0 10px; }
.route .rowline { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(5, 1fr); position: relative; }
.route .rowline::before { content: ''; position: absolute; left: 10%; right: 10%; top: 32px; border-top: 4px dotted var(--line); }
.route .rowline.rev { direction: rtl; }
.route .rowline.rev > * { direction: ltr; }
.node { position: relative; display: grid; justify-items: center; gap: 4px; background: none; border: 0; padding: 0; color: inherit; }
.node .dot {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; z-index: 1;
  font-family: var(--font-display); font-weight: 600; font-size: .95rem; border: 4px solid var(--line); background: #3a3f78; color: #aab0dd;
}
.node.done .dot { background: var(--mint); border-color: var(--mint); color: var(--mint-ink); }
.node.skipped .dot { background: repeating-linear-gradient(45deg, #2f8f78, #2f8f78 6px, #3fb596 6px, #3fb596 12px); border-color: #3fb596; color: #06322a; }
.node.current .dot { background: var(--sun); border-color: #fff3d6; color: #3d2600; box-shadow: 0 0 0 6px #ffb34744; animation: pulse 1.8s ease-in-out infinite; }
.node.boss .dot { width: 76px; height: 76px; font-size: 2rem; margin-top: -6px; }
.node.locked { cursor: default; }
.node .stars { font-size: .8rem; letter-spacing: 1px; height: 1.2em; color: var(--sun); }
.node .lbl { font-size: .8rem; color: var(--dust); }
.ship { position: absolute; top: -18px; font-size: 1.5rem; z-index: 2; animation: bob 2.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 12px #ffb34722; } }
@keyframes bob { 50% { transform: translateY(-4px); } }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { padding: 8px 16px; border-radius: 99px; border: 2px solid var(--line); background: transparent; font-family: var(--font-display); }
.tab[aria-selected="true"] { background: var(--mint); color: var(--mint-ink); border-color: var(--mint); }
.tab.locked { opacity: .5; }

/* panels / modal */
.panel { background: var(--panel); border: 2px solid var(--line); border-radius: 22px; padding: 18px; }
.modal { position: fixed; inset: 0; background: #0a0c24cc; display: grid; place-items: center; padding: 16px; z-index: 50; overflow: auto; }
.modal .box { background: var(--panel); border: 2px solid var(--line); border-radius: 24px; padding: 22px; width: min(520px, 100%); display: grid; gap: 14px; max-height: 92vh; overflow: auto; }
.rules { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; }

/* play */
.hud { position: sticky; top: 0; z-index: 10; background: #14173Aee; backdrop-filter: blur(6px); padding: 10px 16px; border-bottom: 2px solid var(--line); }
.hud .in { width: min(1080px, 100%); margin: 0 auto; display: flex; align-items: center; gap: 14px; }
.ring { position: relative; width: 74px; height: 74px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring .bg { stroke: #2a2f6e; }
.ring .fg { stroke: var(--mint); stroke-linecap: round; transition: stroke .3s; }
.ring.warn .fg { stroke: var(--sun); } .ring.crit .fg { stroke: var(--coral); }
.ring b { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.hud .title { min-width: 0; }
.hud .title b { font-family: var(--font-display); font-size: 1.2rem; }
.sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 16px 0 340px; }
.prob { position: relative; border: 3px solid var(--line); border-radius: 18px; padding: 10px 12px 10px 44px; background: var(--panel); cursor: pointer; text-align: left; color: var(--star); }
.prob .pn { position: absolute; left: 10px; top: 8px; font-size: .85rem; color: var(--dust); font-family: var(--font-display); }
.prob.active { border-color: var(--sun); box-shadow: 0 0 0 4px #ffb34733; }
.prob.filled { border-color: #5a61c8; }
.prob.wrong { border-color: var(--coral); background: #4b2342; }
.prob.okp { border-color: var(--mint); }
.sum { font-family: var(--font-display); font-weight: 400; font-size: 1.9rem; line-height: 1.15; text-align: right; font-variant-numeric: tabular-nums; letter-spacing: .08em; }
.sum .op { float: left; color: var(--sun); }
.sum .line { border-top: 3px solid var(--star); margin: 4px 0 2px; }
.ansbox { min-height: 2.3rem; font-family: var(--font-display); font-weight: 600; font-size: 1.9rem; text-align: right; color: var(--mint); font-variant-numeric: tabular-nums; letter-spacing: .08em; }
.ansbox.empty-cell::after { content: '—'; color: var(--dust); }
.ansbox .caret { display: inline-block; width: 2px; height: 1.6rem; background: var(--sun); vertical-align: -4px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.pad { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: #14173Af4; border-top: 2px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.pad .in { width: min(520px, 100%); margin: 0 auto; display: grid; gap: 8px; }
.keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.key { min-height: 52px; border-radius: 14px; border: 2px solid var(--line); background: var(--panel); font-family: var(--font-display); font-size: 1.5rem; font-weight: 500; }
.key:active { background: var(--panel-2); transform: scale(.97); }
.key.fn { font-size: 1.05rem; background: transparent; }
.key.next { background: var(--sun); color: #3d2600; border-color: var(--sun); font-size: 1.05rem; font-weight: 600; }
.overlay { position: fixed; inset: 0; z-index: 40; background: var(--ink); display: grid; place-items: center; padding: 20px; text-align: center; }

/* review + result */
.review { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin: 14px 0; }
.rv { border: 2px solid var(--line); border-radius: 12px; padding: 8px; background: var(--ink); text-align: center; font-family: var(--font-display); }
.rv small { display: block; color: var(--dust); }
.rv.blank { border-color: var(--coral); }
.result { text-align: center; display: grid; gap: 14px; justify-items: center; padding-top: 24px; }
.result div.big { font-size: 4rem; line-height: 1; }
.starline { font-size: 2.6rem; letter-spacing: 6px; }
.starline .pop { display: inline-block; animation: pop .5s cubic-bezier(.3,1.6,.5,1) both; }
@keyframes pop { from { transform: scale(0) rotate(-40deg); } }
.bank { background: var(--panel); border: 2px solid var(--sun); border-radius: 16px; padding: 10px 18px; font-family: var(--font-display); color: var(--sun); }
.helper { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; text-align: left; background: var(--panel); border: 2px solid var(--line); border-radius: 20px; padding: 14px 16px; max-width: 560px; }
.helper .face { font-size: 2.6rem; }
.chest { background: var(--panel); border: 3px solid var(--sun); border-radius: 22px; padding: 16px 22px; animation: pop .6s cubic-bezier(.3,1.5,.5,1) both; }
.chest .em { font-size: 3.4rem; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .85rem; background: var(--ink); border: 1.5px solid var(--line); }
.tag.rare { border-color: #6fb7ff; } .tag.epic { border-color: var(--sun); }
.explain { text-align: left; font-size: .95rem; color: var(--dust); margin-top: 4px; }
.explain b { color: var(--sun); font-weight: 600; }

/* leaderboard & tables */
table.t { width: 100%; border-collapse: collapse; }
table.t th, table.t td { text-align: left; padding: 8px 6px; border-bottom: 1.5px solid var(--line); }
table.t tr.me td { background: #2d328055; font-weight: 600; }
.rank { font-family: var(--font-display); font-weight: 600; width: 2.2em; }
.field { display: grid; gap: 4px; }
.field label { font-size: .92rem; color: var(--dust); }
input[type=text], input[type=password], input[type=number], select {
  min-height: 46px; border-radius: 12px; border: 2px solid var(--line); background: var(--ink); color: var(--star); padding: 8px 12px; font: inherit; width: 100%;
}
.avatars { display: flex; flex-wrap: wrap; gap: 6px; }
.avatars button { width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--line); background: var(--ink); font-size: 1.5rem; }
.avatars button[aria-pressed="true"] { border-color: var(--mint); box-shadow: 0 0 0 3px #4ff0bd44; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--star); color: var(--ink); padding: 10px 18px; border-radius: 99px; font-weight: 600; z-index: 100; max-width: 90vw; }
.err { color: var(--coral); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
hr.sep { border: 0; border-top: 1.5px solid var(--line); margin: 14px 0; }
@media (max-width: 520px) {
  .node .dot { width: 54px; height: 54px; } .node.boss .dot { width: 64px; height: 64px; }
  .route .rowline::before { top: 27px; }
  .sheet { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* mobile polish */
.btn { white-space: nowrap; }
.hud .btn.small { padding: 8px 12px; }
.hud .title b { font-size: 1.05rem; white-space: nowrap; }
@media (max-width: 480px) {
  .top .brand b { font-size: 1rem; }
  .hud .in { gap: 10px; }
}
.tab { text-decoration: none; color: inherit; }
.tab[aria-selected="true"] { color: var(--mint-ink); }
