:root {
  --panel: rgba(20, 22, 32, 0.82);
  --text: #f4f4f8;
  --muted: #b8bccb;
  --accent: #ffd95a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111; color: var(--text); font-family: system-ui, "Yu Gothic", "Noto Sans JP", sans-serif; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }

#picker { position: fixed; top: 12px; left: 12px; display: flex; flex-wrap: wrap; gap: 6px; max-width: calc(100vw - 280px); }
#picker input { width: 5.5em; padding: 6px 10px; font-size: 22px; text-align: center; border-radius: 8px; border: 2px solid var(--accent); background: var(--panel); color: var(--text); }
#picker button { padding: 6px 12px; font-size: 15px; border-radius: 8px; border: 0; background: var(--accent); color: #222; cursor: pointer; }
#picker button:hover { filter: brightness(1.08); }

#picker select { padding: 6px 8px; font-size: 15px; border-radius: 8px; border: 2px solid var(--accent); background: var(--panel); color: var(--text); cursor: pointer; }
#picker select:disabled { opacity: 0.5; cursor: default; }
#live { font-size: 12px; color: var(--muted); margin-top: 2px; }

#hud { position: fixed; top: 12px; right: 12px; text-align: right; background: var(--panel); padding: 8px 12px; border-radius: 8px; }
#biome { font-size: 14px; color: var(--muted); }
#lights { font-size: 20px; color: var(--accent); }

#lesson-chip { position: fixed; top: 76px; right: 12px; max-width: min(46vw, 420px); text-align: right; font: inherit; font-size: 13px; color: var(--text); background: var(--panel); border: 1px solid var(--muted); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
#lesson-chip.ready { border-color: var(--accent); color: var(--accent); }
.panel { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(94vw, 760px); max-height: 86vh; overflow: auto; background: rgba(20, 22, 32, 0.96); border: 2px solid var(--accent); border-radius: 12px; padding: 16px 18px; z-index: 5; }
.panel h2 { margin: 0 0 6px; font-size: 20px; color: var(--accent); }
.panel .sub { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.kanji-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 8px; }
.kcard { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.kcard.known { border-color: var(--accent); }
.kbig { font-size: 44px; line-height: 1.1; text-align: center; }
.kmeaning { font-size: 14px; text-align: center; }
.kread, .kparts, .kdots { font-size: 12px; color: var(--muted); text-align: center; }
.kdots { letter-spacing: 3px; color: var(--accent); }
.kwords { list-style: none; margin: 4px 0 0; padding: 0; font-size: 12px; display: grid; gap: 2px; }
.words { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.words li { display: grid; grid-template-columns: 6em 7em 1fr auto; gap: 8px; align-items: baseline; padding: 3px 6px; border-radius: 6px; font-size: 15px; }
.words li.due { background: rgba(255, 217, 90, 0.12); }
.words .w { font-size: 18px; } .words .r, .words .b { color: var(--muted); } .words .g { min-width: 0; overflow-wrap: anywhere; }
.pq { font-size: 22px; margin: 6px 0 4px; }
.pq-note { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.pchoices { display: grid; gap: 6px; margin-top: 6px; }
.pchoices button { font: inherit; font-size: 17px; text-align: left; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--muted); background: rgba(255,255,255,0.06); color: var(--text); cursor: pointer; }
.pchoices button:hover:not(:disabled) { border-color: var(--accent); }
.pchoices button.right { border-color: #6fd08c; background: rgba(111, 208, 140, 0.18); }
.pchoices button.wrong { border-color: #e0756b; background: rgba(224, 117, 107, 0.18); }
.flashcard { background: rgba(255,255,255,0.06); border: 1px solid var(--muted); border-radius: 12px; padding: 18px 16px; text-align: center; margin: 8px 0; min-height: 150px; display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.cardfront { font-size: 44px; line-height: 1.2; overflow-wrap: anywhere; }
.cardback { display: grid; gap: 4px; border-top: 1px solid rgba(255,255,255,0.15); padding-top: 8px; }
.cardword { font-size: 26px; } .cardmeaning { font-size: 19px; color: var(--accent); } .cardsentence { font-size: 14px; color: var(--muted); }
.mnemonic { border-radius: 8px; background-color: #fff; background-repeat: no-repeat; margin: 0 auto; border: 1px solid rgba(255,255,255,0.2); }
.cardpics { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.cardnote { font-size: 12px; color: var(--muted); }
.kcard .mnemonic { margin: 6px auto; }
.tools { margin-top: 8px; border-top: 1px dashed rgba(255,255,255,0.2); padding-top: 8px; }
.writehost { margin: 6px 0; }
.writemodel { font-size: 56px; line-height: 1.1; margin-top: 4px; }
.kactions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; margin-top: 6px; }
.kactions button { font-size: 13px; padding: 5px 8px; }
.kcardnote { font-size: 12px; color: var(--muted); }
.actions.tabs { margin: 0 0 8px; }
.pfeedback { margin-top: 10px; font-size: 16px; min-height: 1.4em; }
.panel .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.panel .actions button { font: inherit; font-size: 15px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--muted); background: transparent; color: var(--text); cursor: pointer; }
.panel .actions button.primary { background: var(--accent); color: #222; border-color: var(--accent); }
#banner { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); text-align: center; padding: 10px 24px; background: var(--panel); border-radius: 10px; border: 1px solid var(--accent); max-width: min(92vw, 560px); pointer-events: none; }
#banner-title { font-size: 28px; color: var(--accent); letter-spacing: 0.05em; }
#banner-sub { font-size: 14px; color: var(--muted); }

#message { position: fixed; top: 25%; left: 50%; transform: translateX(-50%); background: var(--panel); padding: 14px 20px; border-radius: 10px; max-width: min(90vw, 480px); text-align: center; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel); padding: 10px 16px; border-radius: 10px; max-width: min(90vw, 520px); text-align: center; font-size: 17px; border: 1px solid var(--accent); white-space: pre-line; }

#dialog { position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); width: min(92vw, 560px); background: var(--panel); border: 2px solid var(--accent); border-radius: 10px; padding: 12px 16px; }
#dialog-title { font-weight: 700; color: var(--accent); margin-bottom: 4px; }
#dialog-text { font-size: 18px; line-height: 1.4; }
#dialog-you { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
#dialog-choices { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; }
#dialog-choices button { width: 100%; text-align: left; font: inherit; font-size: 16px; padding: 6px 10px; border-radius: 6px; border: 1px solid transparent; background: rgba(255,255,255,0.06); color: inherit; cursor: pointer; }
#dialog-choices button:hover, #dialog-choices button.pick { border-color: var(--accent); background: rgba(255,255,255,0.14); }
#dialog-hint { margin-top: 6px; font-size: 12px; color: var(--muted); text-align: right; }

#help { position: fixed; bottom: 8px; left: 12px; font-size: 12px; color: var(--muted); text-shadow: 0 1px 2px #000; }
[hidden] { display: none !important; }

/* rewards: a word that floats up, with sparks */
.pop { position: fixed; left: 50%; top: 38%; transform: translate(-50%, 0); z-index: 30; pointer-events: none; font-size: 30px; font-weight: bold; color: var(--accent); text-shadow: 0 2px 0 #000, 0 0 12px rgba(0,0,0,0.6); white-space: nowrap; animation: pop-up 1.5s ease-out forwards; }
.pop.bad { color: #ff9a8a; font-size: 22px; }
.pop.big { font-size: 46px; top: 32%; animation-duration: 2.4s; }
.pop .spark { position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; background: var(--accent); border-radius: 1px; animation: spark 0.9s ease-out forwards; }
@keyframes pop-up { 0% { opacity: 0; transform: translate(-50%, 20px) scale(0.6); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.15); } 30% { transform: translate(-50%, -4px) scale(1); } 100% { opacity: 0; transform: translate(-50%, -70px) scale(1); } }
@keyframes spark { 0% { opacity: 1; transform: translate(0, 0); } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)); } }
@media (prefers-reduced-motion: reduce) { .pop .spark { display: none; } .pop { animation-name: pop-fade; } @keyframes pop-fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } } }

/* the quest line */
#lesson-chip .quest { display: block; font-weight: bold; }
#lesson-chip .where { display: block; opacity: 0.75; font-size: 12px; }
#lesson-chip.ready { animation: nudge 2.2s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 214, 90, 0); } 50% { box-shadow: 0 0 10px 2px rgba(255, 214, 90, 0.55); } }

/* meeting a kanji */
.meet { text-align: center; }
.meet .steps { display: flex; justify-content: center; gap: 6px; margin: 0 0 10px; }
.meet .steps span { width: 28px; height: 6px; border-radius: 3px; background: var(--muted); opacity: 0.4; }
.meet .steps span.on { background: var(--accent); opacity: 1; }
.meet .bigkanji { font-size: 96px; line-height: 1.1; }
.meet .meaning { font-size: 22px; margin: 4px 0; }
.meet .reading { font-size: 20px; color: var(--accent); }
.meet .why { color: var(--muted); font-size: 14px; margin: 6px 0; }
.meet .mnemonic { margin: 6px auto; }
.meet .pchoices { justify-content: center; }
.kcard.unmet { opacity: 0.95; border-style: dashed; }
.kcard .kunmet { color: var(--muted); font-size: 13px; margin: 4px 0; }

/* the gates */
#dex .dex-bar { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); margin: 0 0 10px; overflow: hidden; }
#dex .dex-fill { height: 100%; background: var(--accent); }
#dex .dex-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
#dex .dex-tabs button { font: inherit; font-size: 15px; padding: 5px 16px; border-radius: 8px; border: 1px solid var(--muted); background: transparent; color: var(--text); cursor: pointer; }
#dex .dex-tabs button.on { background: var(--accent); color: #222; border-color: var(--accent); }
#dex .dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
#dex .dex-card { font: inherit; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 4px 8px; border-radius: 10px; border: 2px solid rgba(255, 255, 255, 0.2); background: rgba(255, 255, 255, 0.05); color: var(--text); cursor: pointer; }
#dex .dex-card.here { border-color: var(--accent); }
#dex .dex-card.open { background: rgba(255, 214, 90, 0.2); }
#dex .dex-card .num { font-size: 11px; color: var(--muted); }
#dex .dex-card .k { font-size: 38px; line-height: 1.1; }
#dex .dex-card .pips { font-size: 12px; letter-spacing: 3px; color: var(--accent); }
#dex .dex-card .count { font-size: 11px; color: var(--muted); }
#dex .dex-more { grid-column: 1 / -1; color: var(--muted); font-size: 13px; padding: 6px 2px; }
#dex .dex-detail { margin-top: 12px; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, 0.18); }
#dex .dex-detail h3 { margin: 0 0 2px; font-size: 20px; }
#dex .dex-words { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
#dex .dex-word { display: grid; grid-template-columns: minmax(70px, auto) minmax(80px, auto) 1fr auto auto; gap: 10px; align-items: center; padding: 5px 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.06); }
#dex .dex-word .w { font-size: 22px; }
#dex .dex-word .r { color: var(--accent); }
#dex .dex-word .m { color: var(--text); }
#dex .dex-word.unknown { opacity: 0.45; }
#dex .dex-word .from { font-size: 12px; color: var(--muted); }
#dex .dex-word .hear { font: inherit; background: transparent; border: 1px solid var(--muted); border-radius: 6px; color: var(--text); cursor: pointer; padding: 2px 8px; }
.jp { cursor: pointer; border-bottom: 1px dotted var(--accent); border-radius: 3px; }
.jp:hover { background: rgba(255, 214, 90, 0.28); }
.ac { position: fixed; z-index: 1000; list-style: none; margin: 0; padding: 4px; max-height: 240px; overflow-y: auto; background: rgba(28, 30, 44, 0.98); border: 1px solid var(--accent); border-radius: 8px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); }
.ac li { padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 16px; color: var(--text); }
.ac li:hover, .ac li.on { background: rgba(255, 214, 90, 0.25); }
#dex .dex-quiz { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 10px; }
#dex .dex-quiz button.on { background: var(--accent); color: #222; border-color: var(--accent); }
#dex .dex-quiz .label { color: var(--muted); font-size: 14px; }
#dex .dex-quiz button, #dex .bench button.small { font: inherit; font-size: 14px; padding: 4px 12px; border-radius: 8px; border: 1px solid var(--accent); background: transparent; color: var(--text); cursor: pointer; }
#dex .bench { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
#dex .benchword { font-size: 44px; line-height: 1.2; }
#dex .bench input { font: inherit; font-size: 17px; padding: 7px 10px; width: min(100%, 360px); border-radius: 8px; border: 1px solid var(--muted); background: rgba(0, 0, 0, 0.3); color: var(--text); }
#dex .dex-search { width: 100%; box-sizing: border-box; font: inherit; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--muted); background: rgba(0, 0, 0, 0.3); color: var(--text); }
#dex .dex-empty { color: var(--muted); padding: 10px 2px; }
#gate .story { font-size: 19px; line-height: 2; margin: 8px 0 12px; }
#gate .chips { display: flex; flex-wrap: wrap; gap: 8px; }
#gate .chip { font: inherit; font-size: 22px; padding: 1px 10px; margin: 0 2px; border-radius: 8px; border: 2px solid var(--accent); background: rgba(255, 214, 90, 0.12); color: var(--text); cursor: pointer; }
#gate .chip.part { background: rgba(255, 214, 90, 0.32); }
#gate .chip.done { border-color: #6fd08c; background: rgba(111, 208, 140, 0.22); }
#gate .chip.done::after { content: ' ✔'; font-size: 14px; }
#gate .chip.old { border-style: dotted; border-color: var(--muted); background: transparent; }
#gate .chip.picked { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.45); }
#gate .bench { background: rgba(255, 255, 255, 0.05); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
#gate .benchhead { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
#gate .benchword { font-size: 44px; line-height: 1.2; }
#gate .step { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid rgba(255, 255, 255, 0.08); }
#gate .step.ok .steplabel { color: #6fd08c; }
#gate .steplabel { min-width: 96px; font-weight: bold; }
#gate .stepval { font-size: 18px; }
#gate .stepout { color: var(--muted); font-size: 14px; }
#gate .kanapreview { min-width: 4em; font-size: 20px; color: var(--accent); }
#gate input[type=text] { font: inherit; font-size: 16px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--muted); background: rgba(0, 0, 0, 0.35); color: var(--text); min-width: 14em; }
#gate button.small { font: inherit; font-size: 14px; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--muted); background: transparent; color: var(--text); cursor: pointer; }
#gate button.small.primary { background: var(--accent); color: #222; border-color: var(--accent); }
#gate button:disabled { opacity: 0.45; cursor: not-allowed; }
