:root {
  --ink: #17161a;
  --paper: #fffaf0;
  --accent: #ff5a1f;
  --ok: #22b864;
  --bad: #e5383b;
  --mute: #6b6670;
  --cur: #ffcc33;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--ink);
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
body {
  font-family: var(--font); color: var(--ink);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
}
canvas { position: fixed; inset: 0; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font-family: var(--font); color: var(--ink); touch-action: manipulation; }

/* ---------- HUD */
#hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 5; pointer-events: none;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 10px) 0 calc(env(safe-area-inset-left) + 10px);
}
.brand {
  font-weight: 900; font-style: italic; letter-spacing: .02em; font-size: 15px; color: #fff;
  background: var(--ink); padding: 7px 11px; border-radius: 9px; white-space: nowrap;
  box-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.brand span { color: var(--cur); }
.mid { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
#chips {
  list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 5px;
}
#chips li {
  display: flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px;
  background: rgba(23,22,26,.84); color: #fff; font-weight: 800; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; transition: background .15s;
}
#chips li b {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255,255,255,.16); font-size: 11px;
}
#chips li.cur { background: var(--cur); color: var(--ink); }
#chips li.cur b { background: rgba(0,0,0,.12); }
#chips li.ok { background: var(--ok); }
#chips li.fail { background: var(--bad); }
#attempt {
  font-weight: 800; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: #fff;
  background: rgba(23,22,26,.6); padding: 2px 10px; border-radius: 999px;
}
#attempt:empty { display: none; }
.icons { display: flex; gap: 6px; }
.icons button {
  pointer-events: auto; width: 38px; height: 38px; padding: 0; cursor: pointer;
  border: 2px solid var(--ink); border-radius: 10px; background: var(--paper);
  box-shadow: 2px 2px 0 var(--ink); display: grid; place-items: center;
}
.icons button:active { transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--ink); }
.icons svg { width: 20px; height: 20px; }
#ico-sound .cross { display: none; }
body.muted #ico-sound .cross { display: inline; }
body.muted #ico-sound .wave { display: none; }

@media (max-width: 700px) {
  #hud { grid-template-columns: auto minmax(0, 1fr); }
  .mid { grid-column: 1 / -1; grid-row: 2; }
  .icons { justify-self: end; }
}
@media (max-width: 700px), (max-height: 440px) {
  .brand { font-size: 13px; padding: 6px 9px; }
  #chips li { font-size: 11px; padding: 2px 8px 2px 2px; gap: 5px; }
  #chips li b { width: 17px; height: 17px; font-size: 10px; }
  .icons button { width: 34px; height: 34px; }
  .icons svg { width: 18px; height: 18px; }
}

/* ---------- bail bar */
#bailbar {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 18px); width: min(420px, calc(100% - 24px));
  background: var(--paper); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 5px 5px 0 var(--ink);
  padding: 10px 14px 12px; text-align: center; cursor: pointer; animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translate(-50%, 14px); opacity: 0; } }
.bb-title { font-weight: 900; font-style: italic; font-size: 24px; text-transform: uppercase; color: var(--bad); line-height: 1.1; }
.bb-title.wrong { color: var(--accent); }
.bb-reason { font-weight: 800; font-size: 15px; margin-top: 2px; }
.bb-meta { font-size: 13px; color: var(--mute); font-weight: 600; margin-top: 3px; }
.bb-cta {
  display: inline-block; margin-top: 8px; font-weight: 900; font-size: 13px; letter-spacing: .08em; text-transform: uppercase;
  background: var(--ink); color: #fff; padding: 6px 14px; border-radius: 8px;
}

/* ---------- cards */
#overlay {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 14px);
  background: rgba(15,14,18,.5); touch-action: pan-y;
}
.card {
  position: relative; width: min(450px, 100%); max-height: calc(100dvh - 28px); overflow: auto; touch-action: pan-y;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 16px; box-shadow: 7px 7px 0 var(--ink);
  padding: 20px 20px 18px; animation: pop .2s ease-out; user-select: text; -webkit-user-select: text;
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.kicker { font-weight: 800; font-size: 12px; letter-spacing: .12em; color: var(--mute); text-transform: uppercase; }
.card h1 {
  margin: 4px 40px 12px 0; font-size: 30px; font-weight: 900; font-style: italic; line-height: 1;
  text-transform: uppercase; letter-spacing: -.01em;
}
.card h2 { margin: 16px 0 6px; font-size: 14px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.card p { margin: 6px 0; font-size: 14.5px; line-height: 1.45; }
.close {
  position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; padding: 0; cursor: pointer;
  border: 2px solid var(--ink); border-radius: 9px; background: #fff; display: grid; place-items: center;
}
.close svg { width: 16px; height: 16px; }
.line-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.line-list li {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 9px;
  padding: 7px 9px; border: 2px solid var(--ink); border-radius: 10px; background: #fff;
}
.line-list .n {
  width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-weight: 900; font-size: 13px;
}
.line-list .t { font-weight: 900; text-transform: uppercase; font-size: 15px; }
.line-list .o { font-weight: 600; color: var(--mute); font-size: 13px; text-transform: none; }
.line-list .how {
  font-size: 12px; font-weight: 800; background: #f0e9dc; border-radius: 6px; padding: 3px 7px; white-space: nowrap;
}
.rule { color: var(--mute); font-weight: 600; font-size: 13.5px !important; }
.big {
  display: block; width: 100%; margin-top: 12px; padding: 14px; cursor: pointer;
  font: italic 900 22px/1 var(--font); letter-spacing: .03em; text-transform: uppercase;
  background: var(--accent); color: #fff; border: 3px solid var(--ink); border-radius: 12px; box-shadow: 4px 4px 0 var(--ink);
}
.big:active, .ghost:active { transform: translate(2px,2px); box-shadow: 2px 2px 0 var(--ink); }
.ghost {
  display: block; width: 100%; margin-top: 10px; padding: 11px; cursor: pointer;
  font: 900 15px/1 var(--font); letter-spacing: .05em; text-transform: uppercase;
  background: #fff; border: 3px solid var(--ink); border-radius: 12px; box-shadow: 3px 3px 0 var(--ink);
}
.sub { text-align: center; font-size: 12.5px; font-weight: 700; color: var(--mute); margin-top: 10px; }
.linkbtn {
  display: block; margin: 8px auto 0; background: none; border: 0; padding: 4px; cursor: pointer;
  font-weight: 800; font-size: 13px; text-decoration: underline; text-underline-offset: 3px;
}
.tip { font-size: 12.5px; font-weight: 700; color: var(--mute); text-align: center; margin-top: 8px; }

.result { display: flex; justify-content: center; gap: 26px; margin: 4px 0 10px; }
.result div { text-align: center; }
.result b { display: block; font-size: 40px; font-weight: 900; font-style: italic; line-height: 1; }
.result span { font-size: 11px; font-weight: 800; letter-spacing: .1em; color: var(--mute); text-transform: uppercase; }
.grid { margin: 6px 0 4px; }
.grid .row { display: flex; justify-content: center; gap: 4px; margin: 4px 0; }
.grid i { width: 22px; height: 22px; border-radius: 5px; border: 2px solid var(--ink); background: #d8d2c8; }
.grid i.g { background: var(--ok); }
.grid i.r { background: var(--bad); }
.grid .more { font-size: 12px; font-weight: 800; color: var(--mute); }
.next { text-align: center; font-weight: 700; font-size: 13.5px; margin-top: 12px; color: var(--mute); }
.next b { color: var(--ink); font-variant-numeric: tabular-nums; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin: 4px 0 6px; }
.stat-row b { display: block; font-size: 28px; font-weight: 900; font-style: italic; line-height: 1.05; }
.stat-row span { font-size: 10.5px; font-weight: 800; letter-spacing: .06em; color: var(--mute); text-transform: uppercase; }
.dist { display: grid; gap: 4px; }
.dist .bar { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 6px; font-size: 12px; font-weight: 800; }
.dist .fill {
  background: #cfc8bc; color: var(--ink); border-radius: 5px; padding: 2px 6px; text-align: right;
  min-width: 22px; font-size: 12px; font-weight: 900;
}
.dist .fill.today { background: var(--ok); color: #fff; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; font-size: 14px; }
.keys kbd {
  font-family: var(--font); font-weight: 900; font-size: 12.5px; background: #fff; border: 2px solid var(--ink);
  border-bottom-width: 3px; border-radius: 7px; padding: 2px 7px; white-space: nowrap; justify-self: start;
}

#toast {
  position: fixed; z-index: 20; left: 50%; top: calc(env(safe-area-inset-top) + 64px); transform: translateX(-50%);
  background: var(--ink); color: #fff; font-weight: 800; font-size: 14px; padding: 9px 16px; border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
}

/* ---------- v2: element parts, difficulty, hints */
.line-list li { grid-template-columns: 26px 1fr; }
.line-list .el { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 6px; font-weight: 900; text-transform: uppercase; font-size: 14.5px; }
.line-list .part.in, .line-list .part.out { font-size: 12.5px; color: #4a4550; }
.line-list .sep { color: var(--mute); font-weight: 900; }
.line-list .o { margin-left: 2px; text-transform: none; }
.line-list kbd, .hint kbd {
  font-family: var(--font); font-weight: 900; font-size: 11.5px; background: #f0e9dc; border: 1.5px solid var(--ink);
  border-bottom-width: 2.5px; border-radius: 6px; padding: 0 5px; margin-left: 2px; white-space: nowrap; font-style: normal;
}
.hint { font-size: 13px !important; background: #fff3d1; border: 2px solid var(--ink); border-radius: 10px; padding: 7px 10px; }
.outtag { display: inline-block; font-weight: 900; font-style: italic; font-size: 11px; color: #fff; background: var(--accent); border-radius: 4px; padding: 0 5px; }
.level {
  display: inline-flex; align-items: center; gap: 6px; vertical-align: middle; margin-left: 6px;
  font-size: 12px; font-style: normal; letter-spacing: .08em; background: var(--ink); color: var(--cur);
  border-radius: 999px; padding: 4px 9px; transform: translateY(-3px);
}
.pips { display: inline-flex; gap: 2px; }
.pips i { width: 5px; height: 10px; border-radius: 2px; background: rgba(255,255,255,.22); }
.pips i.on { background: var(--cur); }
