@font-face {
  font-family: "Figtree";
  src: url(/assets/fonts/figtree-latin-v1.woff2) format("woff2");
  font-weight: 300 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #f6f7fa;
  --white: #fff;
  --ink: #12151c;
  --ink-2: #464d5c;
  --ink-3: #626a7c;
  --line: #e2e5ec;
  --line-2: #cbd1dc;
  --cobalt: #2848f5;
  --cobalt-deep: #1c35c9;
  --cobalt-wash: #ebeeff;
  --flame: #ff5a36;
  --sun: #ffc631;
  --leaf: #12a56b;
  --sky: #cfdbff;
  --blush: #ffe0d6;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  font: 400 16px/1.5 "Figtree", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100svh; background: var(--paper); color: var(--ink); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:where(a, button, input, textarea, summary, [tabindex]):focus-visible { outline: 3px solid var(--cobalt); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ top bar */

.top {
  position: sticky; top: 0; z-index: 30;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  height: 68px; padding: 0 20px;
  background: rgba(246, 247, 250, .9);
  backdrop-filter: blur(10px);
}
.mark { display: inline-flex; width: 34px; height: 34px; }
.mark svg { width: 100%; height: 100%; display: block; }
.tabs { display: inline-flex; gap: 2px; padding: 4px; background: var(--white); border: 1px solid var(--line); border-radius: 999px; }
.tabs a {
  padding: 7px 22px; border-radius: 999px; text-decoration: none; color: var(--ink-2);
  font-weight: 600; font-size: 15px; letter-spacing: -.005em;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--ink); color: var(--white); }
.top-tools { display: flex; justify-content: flex-end; gap: 8px; }
.ghost {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 999px;
  border: 1px solid transparent; background: transparent; color: var(--ink-2); font-weight: 600; font-size: 14px;
}
.ghost:hover { background: var(--white); border-color: var(--line); color: var(--ink); }
.ghost svg { width: 16px; height: 16px; }

.primary, .secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 22px; border-radius: 999px; font-weight: 650; font-size: 15px;
  border: 1px solid transparent;
}
.primary { background: var(--cobalt); color: var(--white); }
.primary:hover:not(:disabled) { background: var(--cobalt-deep); }
.primary:disabled { background: var(--line-2); }
.secondary { background: var(--white); border-color: var(--line-2); color: var(--ink); }
.secondary:hover { border-color: var(--ink); }

/* ------------------------------------------------------------------ AI page */

.ai { --col: 780px; display: flex; flex-direction: column; min-height: calc(100svh - 68px); padding: 0 20px; }
.ai[data-state="empty"] { justify-content: center; padding-bottom: 12svh; }
.thread { width: min(100%, var(--col)); margin: 0 auto; flex: 1; padding: 16px 0 28px; display: flex; flex-direction: column; gap: 26px; }
.ai[data-state="empty"] .thread { display: none; }
.dock { width: min(100%, var(--col)); margin: 0 auto; }
.ai[data-state="chat"] .dock { position: sticky; bottom: 0; padding: 10px 0 max(16px, env(safe-area-inset-bottom)); background: linear-gradient(to bottom, rgba(246, 247, 250, 0), var(--paper) 18px); }

.alert { margin: 0 0 10px; padding: 11px 16px; border-radius: 16px; background: var(--blush); color: #7a2511; font-size: 15px; font-weight: 520; }

.bar {
  position: relative; background: var(--white); border: 1px solid var(--line); border-radius: 26px;
  padding: 18px 18px 14px;
  box-shadow: 0 1px 2px rgba(18, 21, 28, .04), 0 22px 44px -22px rgba(28, 53, 201, .28);
  transition: border-color .15s, box-shadow .15s;
}
.bar:focus-within { border-color: var(--cobalt); box-shadow: 0 0 0 4px rgba(40, 72, 245, .12), 0 22px 44px -22px rgba(28, 53, 201, .28); }
.bar.drag { border-color: var(--cobalt); background: var(--cobalt-wash); }
.bar textarea {
  display: block; width: 100%; min-height: 34px; max-height: 240px; padding: 0 2px; border: 0; outline: 0; resize: none;
  background: transparent; font-size: 19px; line-height: 1.45; letter-spacing: -.005em;
}
.bar textarea::placeholder { color: #8a92a3; }
.bar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.bar-row .spacer { flex: 1; }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--white); color: var(--ink-2);
}
.icon-btn:hover { border-color: var(--ink); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

.seg { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); }
.seg button { padding: 5px 13px; border: 0; border-radius: 999px; background: transparent; color: var(--ink-2); font-weight: 620; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--white); }

.menu { position: relative; }
.menu-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--white); font-size: 14px; white-space: nowrap;
}
.menu-btn:hover, .menu-btn[aria-expanded="true"] { border-color: var(--ink); }
.menu-btn .k { color: var(--ink-3); }
.menu-btn .v { font-weight: 650; }
.menu-btn svg { width: 14px; height: 14px; color: var(--ink-3); }
.menu-list {
  position: absolute; z-index: 40; left: 0; top: calc(100% + 8px); min-width: 300px; max-width: min(380px, calc(100vw - 40px));
  margin: 0; padding: 6px; list-style: none; background: var(--white); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 24px 56px -16px rgba(18, 21, 28, .3), 0 2px 6px rgba(18, 21, 28, .06);
}
.menu-list.up { top: auto; bottom: calc(100% + 8px); }
.menu-list.end { left: auto; right: 0; }
.opt {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 14px; align-items: baseline; padding: 9px 12px; border-radius: 12px; cursor: pointer;
}
.opt[aria-selected="true"] { background: var(--cobalt-wash); }
.opt.active { background: var(--paper); }
.opt[aria-selected="true"].active { background: #dfe5ff; }
.opt .name { font-weight: 650; }
.opt .price { color: var(--ink-3); font-size: 13px; text-align: right; }
.opt .note { grid-column: 1 / -1; color: var(--ink-3); font-size: 13px; }

.send {
  display: inline-grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: var(--cobalt); color: var(--white);
}
.send:hover:not(:disabled) { background: var(--cobalt-deep); }
.send:disabled { background: var(--line-2); }
.send svg { width: 20px; height: 20px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 4px 6px 4px 4px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--paper); font-size: 13px;
}
.chip .thumb { width: 30px; height: 30px; border-radius: 8px; background: var(--white) center / cover no-repeat; display: grid; place-items: center; color: var(--ink-3); font-size: 10px; font-weight: 700; }
.chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; font-weight: 560; }
.chip .sz { color: var(--ink-3); }
.chip button { width: 24px; height: 24px; border: 0; border-radius: 50%; background: transparent; color: var(--ink-3); font-size: 18px; line-height: 1; }
.chip button:hover { background: var(--line); color: var(--ink); }

/* messages */
.msg.user { align-self: flex-end; max-width: min(88%, 620px); }
.msg.user .body { padding: 11px 17px; background: var(--cobalt-wash); border-radius: 22px 22px 6px 22px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 17px; }
.msg.user .chips { margin: 8px 0 0; justify-content: flex-end; }
.msg.user .chip { background: var(--white); }
.msg.assistant { align-self: stretch; }
.msg.assistant .md { font-size: 17px; line-height: 1.65; overflow-wrap: anywhere; }
.caption { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 10px; color: var(--ink-3); font-size: 13px; }
.caption .who { color: var(--ink); font-weight: 650; }
.caption button { border: 0; background: transparent; padding: 2px 6px; margin-left: -6px; border-radius: 8px; color: var(--ink-3); font-size: 13px; font-weight: 600; }
.caption button:hover { background: var(--white); color: var(--ink); }
.divider { align-self: stretch; display: flex; align-items: center; gap: 14px; color: var(--ink-3); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px dashed var(--line-2); }

.thinking { display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 16px; }
.dots { display: inline-flex; gap: 5px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--cobalt); animation: beat 1.1s infinite ease-in-out; }
.dots i:nth-child(2) { background: var(--flame); animation-delay: .15s; }
.dots i:nth-child(3) { background: var(--sun); animation-delay: .3s; }
.thinking .elapsed { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.thinking button { margin-left: 4px; border: 0; background: transparent; color: var(--ink-3); font-weight: 600; padding: 4px 8px; border-radius: 8px; }
.thinking button:hover { background: var(--white); color: var(--ink); }
@keyframes beat { 0%, 70%, 100% { transform: translateY(0); opacity: .45; } 35% { transform: translateY(-5px); opacity: 1; } }

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 14px; }
.md h1, .md h2, .md h3, .md h4 { margin: 22px 0 8px; line-height: 1.25; letter-spacing: -.01em; }
.md h1 { font-size: 24px; } .md h2 { font-size: 21px; } .md h3, .md h4 { font-size: 18px; }
.md ul, .md ol { padding-left: 24px; }
.md li { margin: 3px 0; }
.md a { color: var(--cobalt); text-underline-offset: 3px; }
.md code { font-family: var(--mono); font-size: .88em; background: #eceef4; padding: 1px 6px; border-radius: 6px; }
.md pre { position: relative; background: #eef0f6; border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; overflow-x: auto; }
.md pre code { background: transparent; padding: 0; font-size: 14px; line-height: 1.55; }
.md pre .copy { position: absolute; top: 8px; right: 8px; border: 1px solid var(--line-2); background: var(--white); border-radius: 8px; padding: 2px 9px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.md blockquote { padding: 2px 0 2px 16px; border-left: 3px solid var(--line-2); color: var(--ink-2); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 15px; }
.md th, .md td { padding: 6px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.md th { font-weight: 650; border-bottom-color: var(--line-2); }

/* receipt */
.receipt { margin: 14px 4px 0; padding-top: 12px; border-top: 1px dashed var(--line-2); font-size: 14px; }
.receipt summary { display: flex; align-items: baseline; gap: 10px; cursor: pointer; list-style: none; color: var(--ink-2); }
.receipt summary::-webkit-details-marker { display: none; }
.receipt .r-total { font-size: 17px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.receipt .r-bar { flex: 1; height: 4px; min-width: 40px; border-radius: 4px; background: var(--line); overflow: hidden; align-self: center; }
.receipt .r-bar i { display: block; height: 100%; width: calc(var(--used, 0) * 1%); min-width: 2px; background: var(--cobalt); border-radius: 4px; }
.receipt[data-warn="true"] .r-bar i { background: var(--flame); }
.receipt .r-more { color: var(--ink-3); font-weight: 600; }
.receipt[open] .r-more::after { content: " (hide)"; }
.r-body { max-height: 46svh; overflow: auto; padding: 12px 0 2px; }
.r-body table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.r-body th, .r-body td { padding: 6px 0 6px 12px; text-align: right; white-space: nowrap; border-bottom: 1px dashed var(--line); }
.r-body th:first-child, .r-body td:first-child { text-align: left; padding-left: 0; white-space: normal; }
.r-body thead th { color: var(--ink-3); font-weight: 600; font-size: 13px; border-bottom: 1px dashed var(--line-2); }
.r-body tfoot th { font-weight: 650; color: var(--ink); }
.r-body tfoot td { font-weight: 700; }
.r-body .prov { color: var(--ink-3); font-size: 12px; margin-left: 6px; }
.r-body .empty { text-align: left; color: var(--ink-3); padding: 10px 0; }
.r-note { margin: 12px 0 0; color: var(--ink-3); font-size: 13px; line-height: 1.5; }

/* access code dialog */
dialog#gate { width: min(440px, calc(100vw - 32px)); padding: 28px; border: 0; border-radius: 26px; background: var(--white); color: var(--ink); box-shadow: 0 40px 90px -20px rgba(18, 21, 28, .45); }
dialog#gate::backdrop { background: rgba(18, 21, 28, .42); }
dialog#gate h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.015em; }
dialog#gate p { margin: 0 0 18px; color: var(--ink-2); font-size: 15px; }
dialog#gate input { width: 100%; height: 50px; padding: 0 16px; border: 1px solid var(--line-2); border-radius: 14px; font-size: 17px; background: var(--paper); }
dialog#gate input:focus { outline: 0; border-color: var(--cobalt); box-shadow: 0 0 0 4px rgba(40, 72, 245, .14); background: var(--white); }
dialog#gate .err { margin: 10px 0 0; color: #b3321a; font-weight: 600; font-size: 14px; }
dialog#gate .acts { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ----------------------------------------------------------------- games */

.games { max-width: 1120px; margin: 0 auto; padding: 8px 20px 72px; }
.stage { background: var(--white); border: 1px solid var(--line); border-radius: 28px; overflow: hidden; }
.stage-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 24px 28px 0; }
.stage-title { margin: 0; font-size: 36px; line-height: 1.05; letter-spacing: -.025em; font-weight: 780; }
.stage-sub { margin: 6px 0 0; color: var(--ink-2); font-size: 16px; max-width: 54ch; }
.stage-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.stage-actions a, .stage-actions button { display: inline-flex; align-items: center; min-height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--white); color: var(--ink); font-weight: 620; font-size: 14px; text-decoration: none; }
.stage-actions a:hover, .stage-actions button:hover { border-color: var(--ink); }
.stage-body { padding: 22px 28px 28px; }

.own { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); gap: 36px; align-items: center; }
.rules { margin: 0 0 22px; font-size: 18px; line-height: 1.55; color: var(--ink-2); max-width: 44ch; }
.score { display: flex; gap: 36px; margin: 0 0 24px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .l { color: var(--ink-3); font-size: 14px; font-weight: 600; }
.stat .n { font-size: 44px; line-height: 1; font-weight: 760; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.status { margin: 16px 0 0; min-height: 24px; color: var(--ink-2); font-size: 15px; }
.board { width: 100%; max-width: 440px; aspect-ratio: 1; margin-inline: auto; }

.pulse { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.cell { border: 0; border-radius: 16px; background: #eceff6; transition: background .08s, transform .08s; }
.cell:disabled { cursor: default; }
.cell:not(:disabled):hover { background: #dde2ee; }
.cell.target { background: var(--flame); transform: scale(.94); }

.echo { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.pad { position: relative; border: 0; border-radius: 22px; color: rgba(18, 21, 28, .55); font-size: 28px; font-weight: 760; transition: transform .08s, filter .08s; }
.pad:nth-child(1) { background: #d3dcff; } .pad:nth-child(2) { background: #ffd9cf; }
.pad:nth-child(3) { background: #ffe9a9; } .pad:nth-child(4) { background: #bfeedb; }
.pad[aria-disabled="true"] { cursor: default; }
.pad.lit { transform: scale(.95); color: var(--white); }
.pad:nth-child(1).lit { background: var(--cobalt); } .pad:nth-child(2).lit { background: var(--flame); }
.pad:nth-child(3).lit { background: var(--sun); color: var(--ink); } .pad:nth-child(4).lit { background: var(--leaf); }

.orbit { position: relative; display: grid; place-items: center; }
.track { --half: 24deg; position: relative; width: 100%; aspect-ratio: 1; border-radius: 50%; background: conic-gradient(from calc(var(--half) * -1), var(--cobalt) 0 calc(var(--half) * 2), #e4e8f1 0); }
.track[data-level="2"] { --half: 17deg; } .track[data-level="3"] { --half: 12deg; }
.track::after { content: ""; position: absolute; inset: 22px; border-radius: 50%; background: var(--white); }
.orbit-arm { position: absolute; inset: 0; z-index: 1; }
.orbit-arm::before { content: ""; position: absolute; top: -5px; left: 50%; width: 32px; height: 32px; margin-left: -16px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 5px var(--white); }
.orbit .primary { position: absolute; z-index: 2; min-height: 54px; padding: 0 30px; font-size: 17px; }

.frame-wrap { background: var(--paper); border-radius: 18px; overflow: hidden; }
.frame-wrap iframe { display: block; width: 100%; height: min(72svh, 640px); min-height: 460px; border: 0; background: var(--white); }
.frame-wrap[data-game="2048"] iframe { height: min(82svh, 700px); min-height: 560px; }
.frame-wrap[data-game="andromeda-invaders"] iframe { height: auto; aspect-ratio: 4 / 3; max-height: 680px; }
.frame-note { margin: 12px 2px 0; color: var(--ink-3); font-size: 14px; }

.shelf { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 28px 0 0; padding: 0; list-style: none; }
.tile { position: relative; display: flex; flex-direction: column; background: var(--white); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; transition: transform .15s, border-color .15s; }
.tile:hover { border-color: var(--line-2); transform: translateY(-2px); }
.tile[data-on="true"] { outline: 3px solid var(--ink); outline-offset: 2px; }
.tile-main { display: flex; flex-direction: column; align-items: stretch; padding: 0; border: 0; background: transparent; text-align: left; flex: 1; }
.art { aspect-ratio: 4 / 3; display: grid; place-items: center; }
.art svg { width: 62%; height: auto; }
.tile-text { display: block; padding: 14px 16px 6px; }
.tile-text .t { display: block; font-size: 18px; font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }
.tile-text .d { display: block; margin-top: 3px; color: var(--ink-2); font-size: 14px; line-height: 1.4; }
.tile-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 16px 14px; color: var(--ink-3); font-size: 13px; }
.tile-foot a { color: var(--ink-2); font-weight: 600; text-underline-offset: 3px; }
.a-cobalt { background: var(--cobalt); } .a-sun { background: var(--sun); } .a-flame { background: var(--flame); }
.a-leaf { background: var(--leaf); } .a-ink { background: var(--ink); } .a-sky { background: var(--sky); }
.a-blush { background: #ffc9bb; } .a-lilac { background: #d9cffc; }

/* --------------------------------------------------------------- responsive */

@media (max-width: 960px) {
  .shelf { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .own { grid-template-columns: 1fr; gap: 24px; }
  .own .board, .own .orbit { order: 2; }
}
@media (max-width: 680px) {
  .top { padding: 0 14px; height: 60px; }
  .ai { padding: 0 14px; --col: 100%; }
  .ai[data-state="empty"] { padding-bottom: 6svh; justify-content: flex-start; padding-top: 6svh; }
  .bar { border-radius: 22px; padding: 14px 14px 12px; }
  .bar textarea { font-size: 17px; }
  .menu-list { min-width: min(300px, calc(100vw - 28px)); }
  .menu .menu-list { left: 0; }
  .menu.right .menu-list { left: auto; right: 0; }
  .stage-head { flex-direction: column; padding: 20px 18px 0; }
  .stage-title { font-size: 30px; }
  .stage-body { padding: 18px 18px 22px; }
  .shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .score { gap: 26px; }
  .stat .n { font-size: 38px; }
  .games { padding: 4px 14px 56px; }
  .msg.assistant .md { font-size: 16.5px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
