@font-face { font-family: 'Noto Serif'; font-weight: 700; font-display: swap; src: url('fonts/noto-serif-bold.woff') format('woff'); }
@font-face { font-family: 'Cutive Mono'; font-weight: 400; font-display: swap; src: url('fonts/cutive-mono.woff') format('woff'); }

:root, [data-theme='light'] {
  --bg: #f3eee4; --surface: #fbf8f2; --surface2: #f1ebe0; --line: #d8cebd; --text: #1f1b16; --text2: #5f584d; --text3: #9a9080;
  --dot: #1f1b16; --dash: #d2412d; --accent: #d2412d; --mark: #ffcf3a; --good: #2c8a58; --warn: #d9821c; --bad: #c0262d;
  --blue: #2f68a8; --violet: #8448b0; --good-soft: #d7eedf; --bad-soft: #f6d5d3; --ink-on-mark: #1f1b16;
  --cap: #fffdf8; --cap-down: #1f1b16; --glyph: #1f1b16; --glyph-down: #fbf8f2; --shadow: 0 10px 30px rgba(48, 32, 16, .14);
  color-scheme: light;
}
[data-theme='dark'] {
  --bg: #15130f; --surface: #1f1c17; --surface2: #26221c; --line: #3b362e; --text: #f1ebdf; --text2: #b3a997; --text3: #7d7466;
  --dot: #f1ebdf; --dash: #ff6a4f; --accent: #ff6a4f; --mark: #ffcf3a; --good: #5dc98b; --warn: #ffa64d; --bad: #ff6b6b;
  --blue: #73a9e6; --violet: #c49bf0; --good-soft: #1f3a2b; --bad-soft: #452322; --ink-on-mark: #1f1b16;
  --cap: #27231e; --cap-down: #f1ebdf; --glyph: #f1ebdf; --glyph-down: #15130f; --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-tap-highlight-color: transparent; min-height: 100dvh; display: flex; flex-direction: column;
}
.serif { font-family: 'Noto Serif', Georgia, serif; font-weight: 700; letter-spacing: -.01em; }
.muted { color: var(--text2); }
.small { font-size: .85rem; }
.center { text-align: center; }
a { color: inherit; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { display: block; }

/* ---------------------------------------------------------------- header + tabs */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px clamp(12px, 3vw, 28px); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; flex: 0 0 auto; }
.brand__mark { width: 36px; height: 18px; }
.m-dot { fill: var(--dot); } .m-dash { fill: var(--dash); }
.brand__name { font-family: 'Noto Serif', Georgia, serif; font-weight: 700; font-size: 1.15rem; white-space: nowrap; }
.tabs { display: flex; gap: 4px; margin: 0 auto; background: var(--surface2); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.tab {
  border: 0; background: transparent; padding: 7px 16px; border-radius: 999px; cursor: pointer;
  font-weight: 600; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--text2); white-space: nowrap;
}
.tab[aria-selected='true'] { background: var(--text); color: var(--bg); }
.tab:focus-visible, .btn:focus-visible, .round-btn:focus-visible, .key:focus-visible, .icon-btn:focus-visible, .pill-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.top__actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.pill-btn {
  border: 2px solid var(--text); background: transparent; border-radius: 12px; padding: 4px 12px; font-weight: 700; cursor: pointer; font-size: .85rem;
}
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; text-decoration: none;
}
.icon-btn svg { width: 20px; height: 20px; fill: var(--text); stroke: none; }
.icon-btn--sm { width: 30px; height: 30px; border-radius: 10px; }
.icon-btn--sm svg { fill: none; stroke: var(--text2); stroke-width: 2.2; stroke-linecap: round; width: 16px; height: 16px; }

@media (max-width: 860px) {
  .top { flex-wrap: wrap; row-gap: 8px; }
  .top__actions { margin-left: auto; }
  .tabs { order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; justify-content: space-between; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 7px 6px; font-size: .74rem; letter-spacing: 0; text-transform: none; flex: 1 0 auto; }
}

/* ---------------------------------------------------------------- work area (send + training) */
main { flex: 1 0 auto; }
.work {
  display: grid; gap: 14px; padding: 14px clamp(12px, 3vw, 28px);
  grid-template-columns: minmax(0, 1fr) clamp(300px, 30vw, 400px);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: 'panel key' 'tree key';
  height: calc(100dvh - 64px); min-height: 560px; max-width: 1500px; margin: 0 auto;
}
.work__panel { grid-area: panel; min-width: 0; }
.work__tree { grid-area: tree; min-height: 0; position: relative; }
.work__key { grid-area: key; align-self: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
#tree { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

@media (max-width: 860px) {
  .work {
    display: flex; flex-direction: column; height: calc(100dvh - 108px); min-height: 520px; gap: 10px; padding: 10px 12px 12px;
  }
  .work__panel { flex: 0 0 auto; }
  .work__tree { flex: 1 1 auto; min-height: 190px; }
  .work__key { flex: 0 0 auto; }
}

/* message (send) */
.panel { min-height: 0; }
.msg { min-height: 120px; }
.msg__text { font-family: 'Cutive Mono', ui-monospace, monospace; font-size: clamp(1.05rem, 2.2vw, 1.5rem); letter-spacing: .12em; color: var(--text2); word-break: break-word; min-height: 1.6em; max-height: 4.8em; overflow-y: auto; }
.msg__word { font-family: 'Noto Serif', Georgia, serif; font-weight: 700; font-size: clamp(2.4rem, 6vw, 4.2rem); line-height: 1.1; min-height: 1.15em; word-break: break-all; }
.caret { color: var(--accent); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.codeview { display: flex; align-items: center; gap: 8px; min-height: 30px; flex-wrap: wrap; }
.codeview--center { justify-content: center; }
.g-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--dot); display: inline-block; }
.g-dash { width: 40px; height: 14px; border-radius: 7px; background: var(--dash); display: inline-block; }
.codeview .arrow { margin-left: 14px; color: var(--text2); }
.codeview .sym { font-family: 'Noto Serif', Georgia, serif; font-weight: 700; font-size: 1.6rem; }
.codeview .sym.good { color: var(--good); } .codeview .sym.bad { color: var(--bad); }
.help p { margin: .25em 0; }
.help__small { color: var(--text2); font-size: .92rem; }
.i-dot, .i-dash { display: inline-block; vertical-align: middle; margin: 0 2px; }
.i-dot { width: .55em; height: .55em; border-radius: 50%; background: var(--dot); }
.i-dash { width: 1.5em; height: .55em; border-radius: .3em; background: var(--dash); }
@media (max-width: 860px) {
  .msg { min-height: 0; }
  .help { font-size: .9rem; }
  .help__small { font-size: .82rem; }
  .help .hide-mobile { display: none; }
}

/* key */
.keyrow { display: flex; align-items: center; justify-content: center; gap: clamp(10px, 3vw, 22px); width: 100%; }
.side { display: flex; flex-direction: column; gap: 12px; }
.round-btn {
  width: 56px; height: 56px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  display: grid; place-items: center; box-shadow: var(--shadow);
}
.round-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.round-btn.undo { border-color: var(--accent); }
.key {
  width: clamp(190px, 26vw, 320px); aspect-ratio: 1; border: 0; padding: 0; background: transparent; cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; border-radius: 50%;
}
.key svg { width: 100%; height: 100%; overflow: visible; }
.key__track { fill: none; stroke: var(--line); stroke-width: 7; }
.key__ring { fill: none; stroke: var(--text2); stroke-width: 7; stroke-linecap: round; stroke-dasharray: 0 100; transform: rotate(-90deg); transform-origin: 100px 100px; }
.key__cap { fill: var(--cap); filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .22)); transition: fill .06s; }
.key__glyph { fill: var(--glyph); transition: fill .06s; }
.key__glyph--dash { fill: var(--dash); }
.key__caption { fill: var(--text2); font-size: 13px; font-weight: 600; text-anchor: middle; letter-spacing: .04em; }
.key.down .key__cap { fill: var(--cap-down); filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .2)); }
.key.down .key__glyph:not(.key__glyph--dash) { fill: var(--glyph-down); }
.key.down .key__caption { fill: var(--glyph-down); }
@media (max-width: 860px) {
  .key { width: min(46vw, 30dvh, 230px); }
  .round-btn { width: 48px; height: 48px; }
}

/* choices (what do you hear?) */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: min(100%, 360px); }
.choice {
  font-family: 'Noto Serif', Georgia, serif; font-weight: 700; font-size: 2rem; padding: 14px 8px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; box-shadow: var(--shadow); min-height: 72px;
}
.choice.word { font-size: 1.25rem; }
.choice.good { background: var(--good-soft); border-color: var(--good); }
.choice.bad { background: var(--bad-soft); border-color: var(--bad); }
.choice:disabled { cursor: default; }

/* training panel */
.hub h2, .summary h2 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 4px; }
.hub__sub { margin: 0; font-weight: 600; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0 6px; }
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 10px 20px; border-radius: 999px; font-weight: 600; cursor: pointer;
}
.btn--primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn--danger { color: var(--bad); border-color: var(--bad); }
.task__head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.task__right { display: flex; align-items: center; gap: 10px; }
.eyebrow { font-size: .75rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin: 0; }
.eyebrow--red { color: var(--accent); margin: 26px 0 10px; }
.segments { display: flex; gap: 4px; margin: 8px 0 6px; }
.segments i { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.segments i.cur { background: var(--text); }
.segments i.ok { background: var(--good); } .segments i.slow { background: var(--warn); } .segments i.miss { background: var(--bad); }
.timer { height: 4px; border-radius: 2px; background: transparent; overflow: hidden; }
.timer__fill { height: 100%; width: 0; background: var(--accent); border-radius: 2px; }
.target { text-align: center; font-size: clamp(2.6rem, 7vw, 4.4rem); line-height: 1.15; margin: 6px 0 2px; letter-spacing: .04em; min-height: 1.2em; }
.target.long { font-size: clamp(2rem, 5vw, 3.2rem); }
.target .c-good { color: var(--good); } .target .c-warn { color: var(--warn); } .target .c-bad { color: var(--bad); }
.target .c-text { color: var(--text); } .target .c-dim { color: var(--text3); }
.target .cur { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: .12em; text-decoration-thickness: .06em; }
.info { text-align: center; margin: 2px 0 4px; min-height: 1.5em; color: var(--text2); }
.info.good { color: var(--good); } .info.warn { color: var(--warn); } .info.bad { color: var(--bad); } .info.accent { color: var(--accent); }
.stars { display: flex; gap: 6px; margin: 6px 0; font-size: 2rem; }
.stars .on { color: var(--mark); } .stars .off { color: var(--line); }
@media (max-width: 860px) {
  .target { font-size: clamp(2rem, 11vw, 3rem); }
  .hub h2, .summary h2 { font-size: 1.7rem; }
  .row { margin: 8px 0 4px; }
  .btn { padding: 8px 16px; }
}

/* ---------------------------------------------------------------- pages */
.page { max-width: 980px; margin: 0 auto; padding: 18px clamp(14px, 3vw, 28px) 40px; }
.page h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 6px 0 12px; }
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; }
.stat b { font-family: 'Noto Serif', Georgia, serif; font-size: 1.8rem; }
.stat span { color: var(--text2); font-size: .9rem; }
@media (max-width: 640px) { .stat-cards { grid-template-columns: 1fr 1fr; } }
.chart { padding: 10px; position: relative; }
.chart svg { width: 100%; height: 200px; }
.chart text { fill: var(--text3); font-size: 12px; }
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.cc { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 4px; text-align: center; cursor: pointer; }
.cc b { display: block; font-family: 'Noto Serif', Georgia, serif; font-size: 1.4rem; }
.cc span { display: block; font-size: .8rem; color: var(--text2); }
.cc.great { background: var(--good-soft); } .cc.weak { background: var(--bad-soft); } .cc.locked { opacity: .45; }
.howto { padding-left: 1.2em; } .howto li { margin: .4em 0; }
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.ref { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px; cursor: pointer; text-align: center; }
.ref b { display: block; font-family: 'Noto Serif', Georgia, serif; font-size: 1.5rem; }
.ref span { display: block; color: var(--dash); letter-spacing: .05em; font-weight: 700; }
.ref.off { opacity: .5; }

/* settings */
.settings { display: flex; flex-direction: column; gap: 4px; }
.settings h2 { margin: 22px 0 6px; }
.set { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set__txt { min-width: 0; }
.set__txt b { display: block; font-weight: 600; }
.set__txt small { color: var(--text2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: .9rem; }
.chip[aria-pressed='true'] { background: var(--text); color: var(--bg); border-color: var(--text); }
.set input[type='range'] { width: min(220px, 40vw); accent-color: var(--accent); }
.set output { min-width: 4.5em; text-align: right; color: var(--text2); font-variant-numeric: tabular-nums; }
.switch { width: 50px; height: 30px; border-radius: 15px; border: 1px solid var(--line); background: var(--surface2); position: relative; cursor: pointer; flex: 0 0 auto; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--text3); transition: left .15s, background .15s; }
.switch[aria-checked='true'] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked='true']::after { left: 23px; background: #fff; }
@media (max-width: 640px) { .set { flex-direction: column; align-items: stretch; } .chips { justify-content: flex-start; } .switch { align-self: flex-start; } }

/* ---------------------------------------------------------------- footer, toast, notice */
.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px clamp(14px, 3vw, 28px); color: var(--text2); font-size: .85rem; border-top: 1px solid var(--line); }
.foot a, .linklike { color: var(--text2); }
.foot__links { display: flex; gap: 16px; }
.linklike { background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; font-size: inherit; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 50; font-weight: 600; box-shadow: var(--shadow); }
.notice { position: fixed; left: 12px; right: 12px; bottom: 12px; max-width: 640px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; z-index: 40; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; }
.notice p { margin: 0; font-size: .9rem; color: var(--text2); }
@media (prefers-reduced-motion: reduce) { .caret { animation: none; } }

.row-inline { display: flex; align-items: center; gap: 10px; }
.key:not(.dash) #key-dash, .key.dash #key-dot { display: none; }

/* android app button + modal */
.apk-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; background: var(--good); color: #fff; border-radius: 12px; padding: 6px 12px 6px 10px; font-weight: 700; font-size: .85rem; cursor: pointer; white-space: nowrap; }
.apk-btn svg { width: 18px; height: 18px; fill: #fff; }
@media (max-width: 860px) { .apk-btn span { display: none; } .apk-btn { padding: 6px 8px; } }
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 16px; }
.modal__card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 22px 22px 16px; max-width: 560px; width: 100%; max-height: 90dvh; overflow-y: auto; box-shadow: var(--shadow); }
.modal__card h2 { margin: 0 0 6px; font-size: 1.6rem; padding-right: 36px; }
.modal__x { position: absolute; top: 14px; right: 14px; }
.btn--big { display: inline-block; text-decoration: none; padding: 14px 26px; font-size: 1.05rem; margin: 6px 0 4px; }
