:root {
  --bg: #e3f2fd;
  --fg: #0d47a1;
  --panel: #ffffff;
  --ok: #4caf50;
  --err: #f44336;
  --key: #e0e7ff;
  --key-active: #ffeb3b;
}
:root.dark {
  --bg: #0b1220;
  --fg: #cbd5e1;
  --panel: #111827;
  --key: #1f2937;
  --key-active: #f59e0b;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Noto Sans, Arial; background: var(--bg); color: var(--fg); }
.app { display: grid; grid-template-rows: auto 1fr auto; height: 100%; min-height: 100dvh; }
.app .scale-practice, .app .scale-keyboard, .app .scale-fingers { transform-origin: center; }
.topbar { display:grid; grid-template-columns: 1fr 1fr 1fr; align-items:center; gap: 8px; padding: 8px 12px; background: var(--panel); box-shadow: 0 1px 2px rgb(0 0 0 / 0.1); padding-left: calc(12px + env(safe-area-inset-left)); padding-right: calc(12px + env(safe-area-inset-right)); padding-top: calc(8px + env(safe-area-inset-top)); }
.controls { display:flex; gap: 8px; align-items:center; flex-wrap: wrap; }
.run-controls { display:flex; gap: 8px; align-items:center; }
.btn { font-size: 14px; padding: 6px 10px; border-radius: 6px; border: none; box-shadow: 0 1px 0 rgb(0 0 0 / .15); background: #e5e7eb; color: #111827; }
.btn.primary { background: #2563eb; color: #fff; }
.brand { justify-self: start; grid-column: 1; }
.top-hud { grid-column: 2; justify-self: center; font-weight: 700; font-size: 14px; display:flex; gap: 12px; align-items: baseline; white-space: nowrap; }
.controls { grid-column: 3; justify-self: end; }
.main { display: grid; grid-template-rows: 1fr auto auto; gap: 8px; padding: 12px; }
.center-controls { display:flex; justify-content:center; align-items:center; gap: 16px; }
.big-btn { font-size: 22px; padding: 10px 18px; border-radius: 10px; border: none; box-shadow: 0 2px 0 rgb(0 0 0 / .15); }
.big-btn.primary { background: #2563eb; color: #fff; }
.practice { display:grid; place-items:center; background: var(--panel); border-radius: 8px; padding: 10px; min-height: 160px; position: relative; }
.timed-view .word { font-size: 68px; font-weight: 800; letter-spacing: 1px; }
.timed-view #current { background: var(--key-active); color: #111827; padding: 4px 6px; border-radius: 6px; box-shadow: 0 2px 0 rgb(0 0 0 / .15); animation: appear .25s ease; }
@keyframes appear { from { transform: scale(0.9); opacity: 0.5; } to { transform: scale(1); opacity: 1; } }
.flash-ok { animation: flashOk .25s ease; }
.flash-err { animation: flashErr .35s ease; }
@keyframes flashOk { from { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.5);} to { box-shadow: 0 0 0 16px rgba(76, 175, 80, 0);} }
@keyframes flashErr { 0% { background: rgba(244, 67, 54, 0.08);} 100% { background: transparent; } }
.hidden { display:none; }
.keyboard { background: var(--panel); border-radius: 8px; padding: 16px; display: grid; gap: 12px; }
.row { display:flex; gap: 12px; justify-content:center; }
.key { background: var(--key); padding: 16px 12px; min-width: 48px; text-align: center; border-radius: 8px; user-select: none; transition: transform .05s ease, background .2s; box-shadow: inset 0 -2px 0 rgb(0 0 0 / .06); font-size: 18px; }
.key.active { background: var(--key-active); transform: translateY(1px) scale(0.98); }
.key.target { outline: 3px solid var(--key-active); animation: pulse 1s infinite ease-in-out; }
.key.ok { animation: keyOk .25s ease; }
.key.err { animation: keyErr .35s ease; }
.timed-view #current { background: var(--key-active); color: #111827; padding: 2px 4px; border-radius: 4px; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5);} 70% { box-shadow: 0 0 0 8px rgba(245, 158, 11, 0);} 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);} }
@keyframes keyOk { from { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);} to { box-shadow: 0 0 0 12px rgba(52, 211, 153, 0);} }
@keyframes keyErr { 0% { background: rgba(244, 67, 54, 0.2);} 100% { background: var(--key);} }
.key.wide { min-width: 96px; }
.key.space { min-width: 420px; }
#hud { display:none; }
.status { display:none; }
.fingers { display:flex; gap: 80px; align-items:center; font-size: 20px; justify-content: center; }
.hand-group { display:flex; gap: 16px; align-items:center; }
.finger { padding: 4px 6px; border-radius: 12px; background: #e5e7eb; color: #111827; position: relative; }
.finger.active { background: #a7f3d0; animation: fingerPulse 0.9s ease-in-out infinite; }
.finger.active::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 140%; height: 140%; border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
  animation: fingerRipple 1.2s ease-out infinite;
}
@keyframes fingerPulse { 0% { transform: scale(1); } 50% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes fingerRipple { 0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.4);} 100% { box-shadow: 0 0 0 16px rgba(52, 211, 153, 0);} }
.finger.left { border: 1px solid #60a5fa; }
.finger.right { border: 1px solid #f87171; }
.ok { color: var(--ok); }
.err { color: var(--err); }
.primary { background: #2563eb; color: white; border: none; padding: 8px 12px; border-radius: 6px; }
.hud-number { font-variant-numeric: tabular-nums; display: inline-block; min-width: 4ch; text-align: right; }
.hud-number.time { min-width: 5ch; }
.footer { display:flex; flex-direction: column; gap: 8px; align-items: stretch; justify-content: center; padding: 8px 12px; background: var(--panel); padding-left: calc(12px + env(safe-area-inset-left)); padding-right: calc(12px + env(safe-area-inset-right)); padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.footer-bar { display:grid; grid-template-columns: 1fr 1fr 1fr; align-items:center; }
.footer-center { justify-self: center; }
.footer-center.scalable { display: flex; justify-content: center; }
.history { max-height: 180px; overflow:auto; font-size: 12px; }
canvas.falling-view { width: 100%; height: 260px; background: linear-gradient(180deg, rgb(59 130 246 / .08), transparent); border-radius: 8px; }

/* Responsive adjustments for mobile and tablets */
@media (max-width: 1024px) {
  .top-hud { font-size: 12px; gap: 8px; }
  .timed-view .word { font-size: 48px; }
  .keyboard .key { font-size: 16px; padding: 14px 10px; min-width: 44px; }
  .key.space { min-width: 360px; }
  .fingers { gap: 64px; }
  .finger { font-size: 20px; padding: 10px 14px; }
}
/* iPad-friendly tuning */
@media (min-width: 768px) and (max-width: 1080px) {
  .top-hud { font-size: 13px; }
  .timed-view .word { font-size: 56px; }
  .key.space { min-width: clamp(300px, 50vw, 420px); }
  .fingers { gap: 72px; }
}
@media (max-width: 768px) {
  .topbar { grid-template-columns: 1fr; gap: 6px; }
  .brand { display: none; }
  .controls { grid-column: 1; justify-self: center; }
  .top-hud { grid-column: 1; justify-self: center; font-size: 12px; flex-wrap: wrap; }
  .main { grid-template-rows: auto 1fr auto; padding: 8px; }
  .practice { min-height: 140px; }
  .timed-view .word { font-size: 40px; }
  .keyboard { gap: 8px; padding: 10px; }
  .row { gap: 6px; }
  .key { font-size: 14px; min-width: 36px; padding: 12px 8px; }
  .key.wide { min-width: 72px; }
  .key.space { min-width: 240px; }
  .fingers { gap: 48px; font-size: 16px; }
  .hand-group { gap: 10px; }
  .finger { font-size: 18px; padding: 8px 12px; }
}
