:root {
  --paper: #f3f0e8;
  --paper-raised: #fbf9f3;
  --ink: #1c2a3a;
  --ink-soft: #4a5568;
  --rule: #d8d2c2;
  --gold: #a97a1f;
  --gold-deep: #8a6318;
  --clay: #963c2e;
  --green: #3c5c47;
  --green-soft: #e3eee6;
  --clay-soft: #f4e1dc;
  --radius: 6px;
  font-size: 16px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: "Source Sans 3", system-ui, sans-serif; -webkit-text-size-adjust: 100%; }

.top { border-bottom: 1px solid var(--rule); background: var(--paper-raised); }
.top-inner { max-width: 760px; margin: 0 auto; padding: 12px 16px 14px; }
.back { margin: 0 0 6px; font-size: 0.9rem; }
.back a { color: var(--gold-deep); text-decoration: none; }
.back a:hover { text-decoration: underline; }
h1 { font-family: "Fraunces", Georgia, serif; font-size: 1.7rem; margin: 0; line-height: 1.15; }
.subhead { margin: 6px 0 0; color: var(--ink-soft); font-size: 0.95rem; }
.wrap { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }

.crumb { display: flex; align-items: baseline; gap: 14px; margin-bottom: 10px; flex-wrap: wrap; }
.crumb-title { font-family: "Fraunces", Georgia, serif; font-size: 1.25rem; font-weight: 700; }
.link-btn { font: inherit; font-size: 0.95rem; background: none; border: 0; padding: 0; color: var(--gold-deep); text-decoration: underline; cursor: pointer; }

/* buttons */
.btn { font: inherit; font-weight: 600; font-size: 0.95rem; padding: 9px 14px; border-radius: var(--radius); border: 1px solid var(--rule); background: var(--paper-raised); color: var(--ink); cursor: pointer; min-height: 42px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2f4b39; border-color: #2f4b39; }
.btn-ghost { background: transparent; }
.btn.big { font-size: 1.1rem; padding: 12px 26px; min-height: 50px; }
:is(.btn, .opt, .chip, .tile, .card, .link-btn, input):focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* hub */
.hub { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card { display: flex; flex-direction: column; gap: 6px; padding: 16px; background: var(--paper-raised); border: 1px solid var(--rule); border-radius: 8px; color: inherit; text-decoration: none; box-shadow: 0 1px 2px rgba(28,42,58,.06); transition: border-color .15s, transform .1s; }
.card:hover { border-color: var(--gold); }
.card:active { transform: translateY(1px); }
.card h2 { font-family: "Fraunces", Georgia, serif; font-size: 1.25rem; margin: 0; }
.card .tag { margin: 0; color: var(--ink-soft); }
.card .best { margin: 0; min-height: 1.3em; color: var(--gold-deep); font-weight: 600; font-size: 0.9rem; }
.card .btn { margin-top: auto; align-self: flex-start; }
.hub-foot { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.note { margin: 0; color: var(--ink-soft); font-size: 0.85rem; max-width: 62ch; }

/* panels */
.panel { background: var(--paper-raised); border: 1px solid var(--rule); border-radius: 8px; padding: 16px; }
.panel.center { text-align: center; }
.help { color: var(--ink-soft); margin: 0 0 12px; line-height: 1.5; }
.center { text-align: center; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 14px; align-items: center; }
h2, h3 { font-family: "Fraunces", Georgia, serif; }
h3 { font-size: 1.05rem; margin: 18px 0 8px; }
.best { color: var(--gold-deep); font-weight: 600; margin: 8px 0 0; }
.badge { display: inline-block; background: var(--gold); color: #fff; font-weight: 700; border-radius: 999px; padding: 3px 12px; margin: 4px 0; }
.big-score { font-family: "Fraunces", Georgia, serif; font-size: 1.5rem; font-weight: 700; margin: 6px 0 10px; }

/* HUD */
.hud { display: flex; gap: 8px; justify-content: space-between; margin-bottom: 10px; }
.stat { display: flex; flex-direction: column; align-items: center; flex: 1; padding: 6px 4px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper); min-width: 0; }
.stat .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.stat strong { font-family: "Fraunces", Georgia, serif; font-size: 1.35rem; }
.strikes { color: var(--clay); letter-spacing: 2px; }
.bar { height: 8px; background: var(--rule); border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.bar-fill { height: 100%; width: 100%; background: var(--green); transition: width .1s linear; }
.bar-fill.low { background: var(--clay); }

/* prompt + options */
.prompt { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: 6px 10px; min-height: 5.5rem; padding: 10px 4px 14px; text-align: center; }
.prompt .small { color: var(--ink-soft); font-size: 1rem; }
.prompt .gloss, .gloss { color: var(--ink-soft); font-size: 0.9rem; }
.big-word { font-family: "Fraunces", Georgia, serif; font-size: 2rem; font-weight: 700; overflow-wrap: anywhere; }
.big-word.stem { color: var(--gold-deep); }
.options { display: grid; gap: 10px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid1 { grid-template-columns: 1fr; }
.grid3 { grid-template-columns: repeat(3, 1fr); }
.opt { font: inherit; font-size: 1.25rem; font-weight: 700; padding: 14px 10px; min-height: 62px; border-radius: 8px; border: 2px solid var(--rule); background: var(--paper); color: var(--ink); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; overflow-wrap: anywhere; }
.opt .sub { font-size: 0.8rem; font-weight: 400; color: var(--ink-soft); }
.opt:hover:not(:disabled) { border-color: var(--gold); }
.opt.is-right { background: var(--green-soft); border-color: var(--green); }
.opt.is-wrong { background: var(--clay-soft); border-color: var(--clay); }
.grid1 .opt { font-size: 1.05rem; font-weight: 600; }
.feedback { min-height: 3.2em; margin: 12px 0 0; font-weight: 600; text-align: center; line-height: 1.4; }
.feedback.ok { color: var(--green); }
.feedback.bad { color: var(--clay); }
.level { margin: 0; text-align: center; color: var(--ink-soft); font-size: 0.85rem; }

/* review lists */
.review { list-style: none; padding: 0; margin: 0 0 12px; text-align: left; }
.review li { padding: 8px 2px; border-bottom: 1px solid var(--rule); line-height: 1.45; }
.review .meaning { color: var(--gold-deep); }

/* Enfumu */
.zone-label { margin: 10px 0 4px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); font-weight: 700; }
.line, .bank { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; border-radius: 8px; min-height: 64px; align-content: flex-start; }
.line { border: 2px dashed var(--gold); background: #fffdf6; }
.bank { border: 2px solid var(--rule); background: var(--paper); }
.line.is-drop, .bank.is-drop { border-color: var(--green); background: var(--green-soft); }
.placeholder { color: var(--ink-soft); font-style: italic; align-self: center; width: 100%; text-align: center; }
.tile { font: inherit; font-size: 1.05rem; font-weight: 600; padding: 10px 14px; min-height: 46px; background: #f6e7bd; color: var(--ink); border: 1px solid #c9a45a; border-radius: 6px; box-shadow: 0 2px 0 rgba(0,0,0,.18); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.tile:disabled { cursor: default; opacity: 1; color: var(--ink); }
.tile.is-dragging { opacity: .35; }
.tile.ghost { position: fixed; z-index: 1000; transform: translate(-50%, -50%); pointer-events: none; box-shadow: 0 8px 18px rgba(0,0,0,.35); }
.tile.is-right { background: var(--green-soft); border-color: var(--green); }
.tile.is-wrong { background: var(--clay-soft); border-color: var(--clay); }
.tile.is-shown { background: #fff2c4; border-color: var(--gold); }
.reveal { margin-top: 14px; padding: 14px; border-left: 4px solid var(--gold); background: #fffdf6; border-radius: 4px; }
.reveal-label { margin: 0 0 2px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--gold-deep); font-weight: 700; }
.reveal-text { margin: 0 0 10px; font-family: "Fraunces", Georgia, serif; font-size: 1.1rem; line-height: 1.45; }

/* Ebikoikyo */
.riddle { text-align: center; padding: 8px 0 14px; }
.riddle-text { font-family: "Fraunces", Georgia, serif; font-size: 1.7rem; font-weight: 700; margin: 4px 0 0; overflow-wrap: anywhere; }
.typebox { display: flex; flex-direction: column; gap: 10px; }
input.text { font: inherit; font-size: 1.1rem; padding: 12px; border: 2px solid var(--rule); border-radius: 8px; background: #fff; width: 100%; min-width: 0; }

/* Builder */
.composer { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; padding: 10px; background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-label { width: 3.2rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); font-weight: 700; }
.chip { font: inherit; font-size: 0.9rem; padding: 7px 11px; min-height: 38px; border-radius: 999px; border: 1px solid var(--rule); background: var(--paper-raised); cursor: pointer; color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff; }
.chip:disabled { opacity: .4; cursor: not-allowed; }
.preview { margin: 0; min-height: 1.3em; font-size: 0.9rem; color: var(--clay); }
.preview.ok { color: var(--green); font-weight: 600; }
.typerow { display: flex; gap: 8px; }
.typerow input { flex: 1; }
.found { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; border-top: 1px solid var(--rule); }
.found.left { text-align: left; max-height: none; }
.found li { padding: 7px 2px; border-bottom: 1px solid var(--rule); display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.found li.empty { color: var(--ink-soft); font-style: italic; }
.found .pts { margin-left: auto; color: var(--green); font-weight: 700; }
.tagbadge { font-size: 0.7rem; border: 1px solid var(--rule); border-radius: 99px; padding: 1px 7px; color: var(--ink-soft); }

/* dialog + toast */
dialog { border: 1px solid var(--rule); border-radius: 8px; padding: 0; background: var(--paper-raised); color: var(--ink); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 50px rgba(28,42,58,.35); }
dialog::backdrop { background: rgba(28,42,58,.55); }
.dlg-body { padding: 18px; overflow: auto; max-height: calc(100vh - 28px); }
.dlg-body h2 { margin: 0 0 8px; font-size: 1.25rem; }
.dlg-actions { display: flex; justify-content: flex-end; margin-top: 14px; }
.table-scroll { overflow-x: auto; }
.concords { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.concords th, .concords td { padding: 6px 8px; border-bottom: 1px solid var(--rule); text-align: left; }
.concords th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: calc(100vw - 32px); }

@media (max-width: 520px) {
  h1 { font-size: 1.4rem; }
  .hub { grid-template-columns: 1fr; }
  .big-word { font-size: 1.7rem; }
  .riddle-text { font-size: 1.4rem; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .row-label { width: 100%; }
  .stat strong { font-size: 1.15rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
