:root {
  --board: #1b2925;
  --board2: #22332e;
  --panel: rgba(23, 36, 32, 0.97);
  --solid: #17241f;
  --line: rgba(236, 232, 218, 0.22);
  --chalk: #ece8da;
  --dim: #a8b2aa;
  --faint: #6f7d76;
  --yellow: #ffd36b;
  --pink: #ff8fa3;
  --blue: #8cc8ff;
  --green: #8fe3a5;
  --red: #ff7b7b;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--board); color: var(--chalk); font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
#map { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; cursor: crosshair; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- generic */
.btn { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { background: rgba(255, 255, 255, 0.1); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--yellow); color: #1b2925; border-color: transparent; font-weight: 650; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.on { border-color: var(--yellow); color: var(--yellow); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line); font-size: 13px; color: var(--dim); }
.muted { color: var(--dim); }
.faint { color: var(--faint); font-size: 13px; }
.mono { font-family: var(--mono); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; }
select, input[type=text], input[type=number] { min-height: 40px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.25); }
select option { background: #22332e; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.bar { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--yellow); border-radius: 99px; }

/* ---------------------------------------------------------------- screens */
.screen { position: fixed; inset: 0; overflow: auto; padding: calc(24px + var(--safe-t)) calc(20px + var(--safe-r)) calc(24px + var(--safe-b)) calc(20px + var(--safe-l)); background: radial-gradient(ellipse at 50% 20%, rgba(27, 41, 37, 0.55), rgba(27, 41, 37, 0.92) 70%); }
.screen.see { background: radial-gradient(ellipse at 50% 30%, rgba(27, 41, 37, 0.82), rgba(27, 41, 37, 0.25) 60%); }
.screen .inner { max-width: 960px; margin: 0 auto; }
.title { text-align: center; padding-top: 6vh; }
.logo { font-family: var(--serif); font-size: clamp(44px, 9vw, 84px); letter-spacing: 0.01em; line-height: 1; }
.logo em { font-style: italic; color: var(--yellow); }
.tagline { color: var(--dim); font-size: 18px; margin: 14px auto 28px; max-width: 520px; }
.menu { display: grid; gap: 10px; max-width: 360px; margin: 0 auto; }
.menu .btn { min-height: 52px; font-size: 17px; }
.menu .btn:not(.primary) { background: var(--solid); }
.account { position: fixed; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opts .btn { min-height: 38px; padding: 0 12px; font-size: 14px; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--dim); }
.subjects { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.subjects label { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; font-size: 14px; min-height: 40px; }
.subjects label.on { border-color: var(--yellow); background: rgba(255, 211, 107, 0.08); }
.subjects input { accent-color: var(--yellow); }
.field-h { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); margin: 10px 0 2px; }
.back { margin-bottom: 14px; }
.rooms { display: grid; gap: 8px; }
.room { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); }
.how p { color: var(--dim); margin: 6px 0 12px; }

/* ---------------------------------------------------------------- HUD */
.hud-top { position: fixed; top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); display: flex; gap: 8px; align-items: flex-start; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.me { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; min-width: 230px; }
.me .name { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.me .stat { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--dim); margin-top: 4px; }
.me .stat b { color: var(--chalk); font-family: var(--mono); font-weight: 500; }
.me .bar { margin-top: 3px; }
.board { position: fixed; top: calc(8px + var(--safe-t)); right: calc(8px + var(--safe-r)); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; min-width: 190px; font-size: 13px; }
.board .r { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.board .r.me-row { color: var(--yellow); }
.board .r span.n { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.board .r span.v { font-family: var(--mono); color: var(--dim); }
.board .hdr { display: flex; justify-content: space-between; color: var(--faint); font-size: 12px; margin-bottom: 4px; gap: 10px; }
.iconbtn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); display: inline-flex; align-items: center; justify-content: center; font-size: 18px; }
.bottom { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(8px + var(--safe-b)); display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 16px); pointer-events: none; }
.bottom > * { pointer-events: auto; }
.dock { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; }
.dock .grp { display: flex; gap: 6px; align-items: center; }
.dock .lbl { font-size: 12px; color: var(--faint); }
.send { display: flex; align-items: center; gap: 8px; }
.send input[type=range] { width: 120px; accent-color: var(--yellow); }
.send b { font-family: var(--mono); min-width: 40px; display: inline-block; }
.subject-pick { display: flex; gap: 6px; }
.subject-pick select { max-width: 170px; }
.tool { min-width: 44px; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); display: inline-flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px 8px; font-size: 12px; gap: 0; }
.tool .ic { font-size: 16px; line-height: 1.1; }
.tool .c { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.tool.on { border-color: var(--yellow); color: var(--yellow); }
.tool:disabled { opacity: 0.4; }
.feed { position: fixed; left: calc(8px + var(--safe-l)); bottom: calc(96px + var(--safe-b)); max-width: min(420px, 60vw); display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
.feed div { background: rgba(23, 36, 32, 0.82); border-radius: 8px; padding: 4px 10px; font-size: 13px; color: var(--dim); animation: fade 8s forwards; }
.feed div.good { color: var(--green); }
.feed div.bad { color: var(--pink); }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
.banner { position: fixed; top: calc(70px + var(--safe-t)); left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--yellow); border-radius: 12px; padding: 10px 16px; text-align: center; font-size: 15px; pointer-events: none; }
.banner b { color: var(--yellow); }
.tip { position: fixed; pointer-events: none; background: rgba(15, 24, 21, 0.95); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; max-width: 260px; z-index: 5; }
.tip .t { font-weight: 600; }

/* ---------------------------------------------------------------- duels */
.duels { z-index: 7; position: fixed; right: calc(8px + var(--safe-r)); bottom: calc(96px + var(--safe-b)); width: min(380px, calc(100vw - 16px)); display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; }
.duel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.duel.urgent { border-color: var(--pink); }
.duel .who { display: flex; justify-content: space-between; font-size: 13px; color: var(--dim); gap: 8px; }
.duel .who b { color: var(--chalk); }
.duel .subj { font-size: 12px; color: var(--faint); }
.duel .q { font-family: var(--mono); font-size: 19px; margin: 8px 0; white-space: pre-wrap; line-height: 1.35; }
.duel .q.text { font-family: inherit; font-size: 18px; }
.duel .ans { display: flex; gap: 6px; }
.duel .ans input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 18px; min-height: 44px; }
.duel .timer { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); margin-top: 8px; overflow: hidden; }
.duel .timer i { display: block; height: 100%; background: var(--yellow); }
.duel .note { font-size: 13px; margin-top: 6px; color: var(--dim); }
.duel .note.good { color: var(--green); }
.duel .note.bad { color: var(--pink); }
.duel .hide { float: right; background: none; border: none; color: var(--faint); font-size: 18px; min-width: 32px; min-height: 32px; margin: -6px -6px 0 0; }

/* ---------------------------------------------------------------- solve panel and editor */
.sheet { position: fixed; inset: auto 0 0 0; max-height: calc(100% - 64px - var(--safe-t)); min-height: 46vh; max-width: 980px; margin: 0 auto; background: var(--solid); box-shadow: 0 -8px 40px rgba(0,0,0,0.45); border: 1px solid var(--line); border-radius: 16px 16px 0 0; display: flex; flex-direction: column; overflow: hidden; z-index: 4; }
.sheet.full { top: var(--safe-t); max-height: none; }
.sheet.tall { top: calc(56px + var(--safe-t)); }
.sheet header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.sheet header h2 { font-size: 20px; flex: 1; min-width: 120px; }
.sheet .body { flex: 1; overflow: auto; padding: 12px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.problem { font-family: var(--mono); font-size: 22px; white-space: pre-wrap; margin: 6px 0 12px; line-height: 1.4; }
.problem.text { font-family: inherit; }
.answer { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.answer input { font-family: var(--mono); font-size: 20px; min-height: 48px; flex: 1; min-width: 140px; }
.steps { margin-top: 12px; padding: 10px 12px; border-left: 3px solid var(--yellow); background: rgba(255, 255, 255, 0.03); border-radius: 0 8px 8px 0; font-family: var(--mono); font-size: 14px; white-space: pre-wrap; }
.result { margin-top: 10px; font-size: 15px; }
.result.good { color: var(--green); }
.result.bad { color: var(--pink); }
.levels { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.levels .btn { min-height: 36px; font-size: 13px; }
.plist { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.pitem { text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); display: grid; gap: 2px; min-height: 64px; }
.pitem:hover { background: rgba(255, 255, 255, 0.07); }
.pitem .t { font-weight: 600; }
.pitem .m { font-size: 12px; color: var(--faint); }
.pitem.done .t::after { content: ' ✓'; color: var(--green); }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 12px; height: 100%; }
@media (max-width: 760px) { .editor { grid-template-columns: minmax(0, 1fr); height: auto; } }
.statement { white-space: pre-wrap; color: var(--chalk); font-size: 15px; }
.statement .ex { font-family: var(--mono); font-size: 13px; color: var(--dim); }
.codebox { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
textarea.code { width: 100%; min-height: 260px; flex: 1; resize: vertical; font-family: var(--mono); font-size: 14px; line-height: 1.5; tab-size: 2; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: #111c19; color: #f3efe2; white-space: pre; overflow: auto; }
.symbols { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px; }
.symbols button { min-width: 40px; min-height: 40px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); font-family: var(--mono); }
.tests { display: grid; gap: 4px; font-family: var(--mono); font-size: 12px; max-height: 240px; overflow: auto; }
.tests div { padding: 4px 8px; border-radius: 6px; background: rgba(255, 255, 255, 0.03); white-space: pre-wrap; word-break: break-all; }
.tests .ok { color: var(--green); }
.tests .no { color: var(--pink); }
.chart { width: 100%; height: 120px; display: block; }
.hint { padding: 8px 10px; border-radius: 8px; background: rgba(255, 211, 107, 0.08); border: 1px solid rgba(255, 211, 107, 0.3); font-size: 14px; }
.pattern { color: var(--blue); font-size: 13px; }

/* ---------------------------------------------------------------- end and modal */
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(10, 16, 14, 0.6); z-index: 6; padding: 16px; }
.modal .card { max-width: 440px; width: 100%; text-align: center; }
.modal h2 { font-size: 32px; margin-bottom: 6px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin: 14px 0; text-align: left; font-size: 14px; }
.stats b { font-family: var(--mono); float: right; }
.toast { position: fixed; top: calc(14px + var(--safe-t)); left: 50%; transform: translateX(-50%); background: var(--yellow); color: #1b2925; padding: 8px 16px; border-radius: 99px; font-weight: 600; z-index: 9; animation: fade 4s forwards; pointer-events: none; }
.ctx { position: fixed; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px; display: grid; gap: 4px; z-index: 5; min-width: 200px; }
.ctx .btn { justify-content: flex-start; min-height: 40px; }
.ctx .h { font-size: 12px; color: var(--faint); padding: 2px 6px; }

@media (max-width: 640px) {
  .me { min-width: 0; padding: 6px 10px; }
  .board { display: none; }
  .board.open { display: block; }
  .send input[type=range] { width: 90px; }
  .dock { padding: 6px; gap: 6px; }
  .dock .grp { flex-wrap: wrap; justify-content: center; }
  .dock .grp > .lbl { display: none; }
  .subject-pick select { max-width: 38vw; min-height: 40px; font-size: 14px; }
  .sheet header h2 { font-size: 18px; }
  .statement { font-size: 14px; }
  .feed { bottom: calc(150px + var(--safe-b)); max-width: 80vw; }
  .duels { top: calc(124px + var(--safe-t)); bottom: auto; max-height: 50vh; }
  .problem { font-size: 19px; }
}
