@font-face {
  font-family: "Titan One";
  src: url("fonts/TitanOne-Regular.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Mono";
  src: url("fonts/AtkinsonHyperlegibleMono.ttf") format("truetype");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --red: #b8322a;
  --red-dark: #7a1913;
  --wood: #c48a52;
  --wood-dark: #5b2f24;
  --paper: #fbf3e2;
  --ink: #2a1a14;
  --gold: #f2c230;
  --ok: #2e9b4a;
  --bad: #d63a2c;
  --ui: "Titan One", "Trebuchet MS", sans-serif;
  --mono: "Atkinson Hyperlegible Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: #1d1210; color: var(--ink);
  font-family: system-ui, "Segoe UI", sans-serif; overflow: hidden;
}

#stage-wrap { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#stage {
  position: relative; width: 1280px; height: 720px; flex: none;
  transform-origin: center center; overflow: hidden; background: #3a1d14;
  border-radius: 8px;
}
#screen { position: absolute; inset: 0; }

#keytrap {
  position: fixed; left: -1000px; top: 0; width: 10px; height: 10px; opacity: 0;
  border: 0; padding: 0; resize: none;
}

canvas.bg { position: absolute; inset: 0; width: 100%; height: 100%; }
.layer { position: absolute; inset: 0; }

h1, h2, h3, .btn, .title-font { font-family: var(--ui); font-weight: normal; letter-spacing: 0.5px; }
h1 { font-size: 44px; margin: 0; }
h2 { font-size: 34px; margin: 0 0 12px; }
h3 { font-size: 24px; margin: 0 0 8px; }

.panel {
  background: var(--paper); border-radius: 18px; padding: 22px 28px;
  box-shadow: 0 8px 0 rgba(0,0,0,0.25), 0 12px 30px rgba(0,0,0,0.3);
  border: 3px solid #e0cba0;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 22px; padding: 10px 22px; border-radius: 14px; border: 0; cursor: pointer;
  background: var(--red); color: #fff; box-shadow: 0 5px 0 var(--red-dark);
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--red-dark); }
.btn.secondary { background: #6b5444; box-shadow: 0 5px 0 #3e2e24; }
.btn.small { font-size: 17px; padding: 7px 14px; }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn .num { background: rgba(0,0,0,0.25); border-radius: 8px; padding: 0 8px; font-size: 0.8em; }

.back-btn { position: absolute; left: 20px; top: 18px; z-index: 5; }
.corner-note { position: absolute; right: 20px; bottom: 12px; color: rgba(255,240,220,0.8); font-size: 14px; }

/* Title */
.title-logo { position: absolute; left: 0; right: 0; top: 70px; text-align: center; }
.title-logo .logo {
  font-family: var(--ui); font-size: 128px; color: #fff3d6; line-height: 1;
  text-shadow: 0 6px 0 var(--red-dark), 0 10px 24px rgba(0,0,0,0.5);
  letter-spacing: 6px;
}
.title-logo .say { font-size: 18px; color: #ffe8c0; margin-top: 10px; font-style: italic; }
.title-press {
  position: absolute; bottom: 60px; left: 0; right: 0; text-align: center; font-family: var(--ui);
  font-size: 34px; color: #fff; animation: pulse 1.6s infinite; text-shadow: 0 3px 6px rgba(0,0,0,0.5);
}
.version { position: absolute; left: 16px; bottom: 10px; color: rgba(255,240,220,0.75); font-size: 14px; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* Profiles */
.center-col { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.profiles { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.profile-card {
  width: 220px; padding: 18px; border-radius: 18px; background: var(--paper); cursor: pointer; text-align: center;
  border: 4px solid transparent; box-shadow: 0 6px 0 rgba(0,0,0,0.3);
}
.profile-card:hover { border-color: var(--gold); }
.profile-card .avatar { width: 80px; height: 80px; border-radius: 50%; margin: 0 auto 10px; display: flex; align-items: center; justify-content: center; font-family: var(--ui); font-size: 38px; color: #fff; }
.profile-card .name { font-family: var(--ui); font-size: 24px; }
.profile-card .sash-chip { display: inline-block; margin-top: 6px; padding: 2px 10px; border-radius: 6px; font-size: 14px; border: 1px solid rgba(0,0,0,0.25); }

/* Forms (setup / settings) */
.form-grid { display: grid; grid-template-columns: 220px 1fr; gap: 14px 18px; align-items: center; }
.form-grid label.lbl { font-family: var(--ui); font-size: 20px; }
.seg { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  font-family: var(--ui); font-size: 18px; padding: 7px 14px; border-radius: 10px; cursor: pointer;
  border: 2px solid #cdb68a; background: #fff; color: var(--ink);
}
.seg button.on { background: var(--red); color: #fff; border-color: var(--red-dark); }
input.text {
  font-family: var(--ui); font-size: 22px; padding: 8px 12px; border-radius: 10px; border: 2px solid #cdb68a; width: 280px;
}
.hint { font-size: 14px; color: #6b5444; }
.swatches { display: flex; gap: 10px; }
.swatch { width: 38px; height: 38px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; }
.swatch.on { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
.keytest { display: inline-block; width: 120px; text-align: center; padding: 6px; border: 2px dashed #cdb68a; border-radius: 10px; font-size: 16px; }

/* Hall menu */
.hall-menu { position: absolute; top: 120px; left: 60px; display: flex; flex-direction: column; gap: 14px; width: 360px; }
.hall-menu.right { left: auto; right: 60px; }
.menu-btn {
  display: flex; align-items: center; gap: 14px; padding: 12px 18px; border-radius: 16px; cursor: pointer;
  background: rgba(251,243,226,0.95); border: 3px solid #e0cba0; box-shadow: 0 5px 0 rgba(0,0,0,0.3); text-align: left;
}
.menu-btn:hover { border-color: var(--gold); transform: translateY(-1px); }
.menu-btn .k { font-family: var(--ui); font-size: 22px; background: var(--red); color: #fff; border-radius: 10px; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; flex: none; }
.menu-btn .t { font-family: var(--ui); font-size: 24px; color: var(--ink); }
.menu-btn .s { font-size: 14px; color: #6b5444; }
.hall-top { position: absolute; top: 18px; left: 0; right: 0; text-align: center; color: #fff3d6; }
.hall-top .who { font-family: var(--ui); font-size: 28px; text-shadow: 0 3px 6px rgba(0,0,0,0.5); }

/* Scroll wall */
.scroll-wall { position: absolute; left: 40px; right: 40px; top: 80px; bottom: 30px; overflow-y: auto; padding: 4px 8px 20px; }
.scroll-row { background: var(--paper); border-radius: 16px; padding: 14px 18px; margin-bottom: 14px; border: 3px solid #e0cba0; }
.scroll-row h3 { display: flex; align-items: center; gap: 10px; }
.scroll-row.locked { opacity: 0.6; }
.stones { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.stone {
  min-width: 118px; padding: 8px 12px; border-radius: 40px; background: #d9cbb3; border: 3px solid #b8a68a; cursor: pointer;
  text-align: center; font-family: var(--ui); font-size: 17px; color: var(--ink);
}
.stone:hover:not(.locked) { border-color: var(--gold); }
.stone.locked { cursor: default; opacity: 0.5; }
.stone.done { background: #f1e2bf; }
.stone .keys { font-family: var(--mono); font-size: 15px; display: block; color: #5b4636; }
.stone .paws { display: block; font-size: 15px; letter-spacing: 2px; min-height: 18px; }
.stone.test { background: var(--red); color: #fff; border-color: var(--red-dark); }
.stone.test .keys { color: #ffe; }
.paw-on { color: #8a4a2a; }
.paw-off { color: rgba(0,0,0,0.18); }

/* Typing screen */
.type-top { position: absolute; left: 30px; right: 30px; top: 70px; }
.steps { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
.steps span { font-family: var(--ui); font-size: 16px; padding: 4px 14px; border-radius: 20px; background: rgba(255,255,255,0.25); color: #fff3d6; }
.steps span.on { background: var(--gold); color: var(--ink); }
.steps span.done { background: rgba(46,155,74,0.8); color: #fff; }
.textbox {
  background: var(--paper); border-radius: 16px; padding: 18px 26px; min-height: 120px;
  font-family: var(--mono); font-size: 40px; line-height: 1.5; color: #9a8a78; letter-spacing: 1px;
  border: 3px solid #e0cba0; box-shadow: 0 6px 0 rgba(0,0,0,0.25); white-space: pre-wrap; word-break: break-word;
}
.textbox.small { font-size: 30px; }
.textbox .c { position: relative; }
.textbox .done { color: var(--ok); }
.textbox .err { color: var(--bad); background: rgba(214,58,44,0.12); border-radius: 3px; }
.textbox .cur { color: var(--ink); background: rgba(242,194,48,0.55); border-radius: 4px; box-shadow: inset 0 -4px 0 var(--ink); }
.textbox .cur.wrong { background: rgba(214,58,44,0.35); animation: shake 0.18s; }
.textbox .sp::after { content: "·"; position: absolute; left: 0; right: 0; text-align: center; color: rgba(0,0,0,0.15); }
.textbox .sp.cur::after { color: rgba(0,0,0,0.45); }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.trial-box { height: 248px; overflow: hidden; }
.trial-inner { transition: transform 0.15s; }

.tipbox { display: flex; gap: 14px; align-items: center; margin-top: 12px; color: #fff3d6; font-size: 19px; min-height: 66px; }
.tipbox canvas { flex: none; }
.tipbox .bubble { background: rgba(251,243,226,0.95); color: var(--ink); border-radius: 14px; padding: 10px 16px; position: relative; }
.timer { position: absolute; right: 36px; top: 20px; font-family: var(--ui); font-size: 30px; color: #fff3d6; }
.status-line { position: absolute; left: 0; right: 0; top: 22px; text-align: center; font-family: var(--ui); font-size: 22px; color: #fff3d6; }
.xi { position: absolute; font-family: var(--ui); font-size: 30px; color: var(--bad); background: #fff; padding: 2px 12px; border-radius: 14px; pointer-events: none; animation: xi 0.8s forwards; z-index: 20; }
@keyframes xi { from { transform: translateY(0) scale(0.6); opacity: 1; } to { transform: translateY(-40px) scale(1.1); opacity: 0; } }
.caps { position: absolute; right: 30px; top: 60px; background: var(--bad); color: #fff; padding: 4px 12px; border-radius: 10px; font-family: var(--ui); }

.kbd-area { position: absolute; left: 50%; transform: translateX(-50%); bottom: 18px; width: 900px; }
.kbd { background: rgba(30,18,14,0.82); padding: 10px; border-radius: 14px; display: flex; flex-direction: column; gap: 6px; transition: opacity 0.3s; }
.kbd.faded { opacity: 0.35; }
.kbd.hidden { visibility: hidden; }
.kbd-row { display: flex; gap: 6px; }
.key {
  height: 46px; border-radius: 8px; background: #efe6d6; color: #3b2a20; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-family: var(--mono); font-size: 18px; position: relative;
  box-shadow: 0 3px 0 #9c8a72; line-height: 1;
}
.key.mod { background: #b9ab96; font-size: 13px; font-family: system-ui, sans-serif; }
.key.enter2 { border-top-left-radius: 0; border-top-right-radius: 0; margin-top: -9px; height: 55px; box-shadow: 0 3px 0 #9c8a72; }
.key .cap-shift { font-size: 12px; opacity: 0.65; }
.key.learned, .kbd.all-fingers .key[data-finger] { background: color-mix(in srgb, var(--fc) 38%, #fff); }
.key.bump::after { content: ""; position: absolute; bottom: 7px; width: 12px; height: 2px; background: #3b2a20; border-radius: 1px; }
.key.next { background: var(--fc); color: #fff; outline: 3px solid #fff; animation: nextpulse 0.9s infinite; z-index: 1; }
.key.pressed { transform: translateY(2px); box-shadow: 0 1px 0 #9c8a72; }
.key.flash-bad { animation: badflash 0.5s; }
.key.heat { background: color-mix(in srgb, #d63a2c calc(var(--heat) * 100%), #efe6d6); }
@keyframes nextpulse { 50% { outline-color: var(--fc); } }
@keyframes badflash { 0%, 60% { box-shadow: 0 0 0 4px var(--bad); } }
.finger-label { text-align: center; color: #fff3d6; font-size: 17px; margin-top: 6px; min-height: 22px; font-family: var(--ui); }

.hands { position: absolute; right: 26px; bottom: 270px; width: 220px; opacity: 0; transition: opacity 0.3s; }
.hands.hinting { opacity: 1; }
.hands rect[data-f] { opacity: 0.35; }
.hands rect[data-f].lit { opacity: 1; stroke: #fff; stroke-width: 3; }

/* Show step */
.show-keys { display: flex; gap: 18px; justify-content: center; margin: 4px 0 6px; }
.show-key {
  width: 110px; height: 110px; border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 56px; color: #fff; box-shadow: 0 6px 0 rgba(0,0,0,0.3); transition: transform 0.15s;
}
.show-key small { font-family: var(--ui); font-size: 13px; }
.show-key.got { transform: scale(0.9); opacity: 0.55; }

/* Results */
.results { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 760px; text-align: center; }
.big-stats { display: flex; justify-content: center; gap: 46px; margin: 10px 0 14px; }
.big-stats .v { font-family: var(--ui); font-size: 56px; line-height: 1; }
.big-stats .l { font-size: 16px; color: #6b5444; }
.paws-big { font-size: 48px; letter-spacing: 10px; }
.sifu-says { display: flex; align-items: center; gap: 14px; justify-content: center; margin: 10px 0 16px; font-size: 20px; }
.row-btns { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

/* Games */
.hud { position: absolute; top: 16px; left: 0; right: 0; display: flex; justify-content: center; gap: 40px; font-family: var(--ui); font-size: 26px; color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,0.6); pointer-events: none; }
.game-msg { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 6; }
.yard-cards { display: flex; gap: 30px; justify-content: center; }
.yard-card { width: 400px; }
.score-list { list-style: none; padding: 0; margin: 8px 0; font-size: 17px; }
.score-list li { display: flex; justify-content: space-between; border-bottom: 1px dashed #d9c7a4; padding: 3px 0; }

.run-sentence { position: absolute; left: 30px; right: 30px; top: 70px; }

/* Speed trial results & progress */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.chart svg { width: 100%; height: 190px; background: #fff; border-radius: 10px; }
.mini-kbd .kbd { transform: scale(0.62); transform-origin: top left; width: 161%; }
.mini-kbd { height: 190px; overflow: hidden; }
.missed-keys { font-family: var(--mono); font-size: 34px; letter-spacing: 12px; }
.legend { font-size: 14px; display: flex; gap: 16px; justify-content: center; margin-top: 4px; }
.legend i { display: inline-block; width: 14px; height: 4px; vertical-align: middle; margin-right: 4px; }

/* Banner and overlays */
#banner {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%); z-index: 30; background: #fff7d6;
  border: 3px solid var(--gold); border-top: 0; border-radius: 0 0 14px 14px; padding: 10px 18px; display: flex; gap: 10px; align-items: center;
  font-family: var(--ui); font-size: 19px;
}
#focus-overlay {
  position: absolute; inset: 0; z-index: 40; background: rgba(20,10,8,0.6); display: flex; align-items: center; justify-content: center;
  font-family: var(--ui); font-size: 36px; color: #fff; cursor: pointer;
}
#banner[hidden], #focus-overlay[hidden] { display: none; }
.modal-back { position: absolute; inset: 0; background: rgba(20,10,8,0.55); z-index: 35; display: flex; align-items: center; justify-content: center; }
.modal { max-width: 640px; }
.notice { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: rgba(255,247,214,0.95); padding: 6px 14px; border-radius: 10px; font-size: 15px; z-index: 25; }
