/* ============================================================
   ChankArts Piano — Core styles
   Theme tokens, layout, boot screen, top bar, keyboard.
   ============================================================ */

/* --- Tokens --- */
:root {
  --bg: #07070d;
  --bg-2: #0b0b14;
  --panel: #101019;
  --panel-2: #161624;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #e9e9f3;
  --muted: #8b8ba4;
  --brand: #c9a96e;
  --brand-soft: rgba(201, 169, 110, 0.14);
  --tech: #7c5cff;
  --tech-2: #3d8bff;
  --accent: #7c5cff;
  --accent-soft: rgba(124, 92, 255, 0.16);
  --accent-glow: rgba(124, 92, 255, 0.45);
  --grad: linear-gradient(135deg, #7c5cff 0%, #3d8bff 100%);
  --ok: #3ddc97;
  --warn: #ffb454;
  --danger: #ff5470;

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", ui-monospace, monospace;

  --radius: 10px;
  --radius-sm: 7px;
  --kw: 52px;               /* white key width */
  --topbar-h: 52px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

body.theme-classic {
  --accent: #c9a96e;
  --accent-soft: rgba(201, 169, 110, 0.16);
  --accent-glow: rgba(201, 169, 110, 0.45);
  --grad: linear-gradient(135deg, #c9a96e 0%, #e6cf9c 100%);
  --tech: #c9a96e;
  --tech-2: #e6cf9c;
}

/* --- Reset --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

[hidden] { display: none !important; }

html, body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 15% -10%, rgba(124, 92, 255, 0.16), transparent 60%),
    radial-gradient(900px 460px at 90% 0%, rgba(61, 139, 255, 0.12), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection {
  background: var(--accent);
  color: #07070d;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.noscript {
  padding: 32px 24px;
  text-align: center;
  color: var(--text);
}
.noscript strong { display: block; margin-bottom: 8px; color: var(--brand); }

.mono { font-family: var(--font-mono); font-size: 0.92em; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- App shell --- */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}

body.is-playing .app {
  opacity: 1;
  transform: none;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
  padding: 12px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  overflow-y: auto;
  overflow-x: hidden;
}

/* --- Top bar --- */
.topbar {
  flex: 0 0 auto;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: rgba(8, 8, 14, 0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: 0.9rem;
  color: #fff;
  white-space: nowrap;
}
.topbar__brand svg { color: var(--brand); flex: 0 0 auto; }
.topbar__sep { color: var(--muted); font-weight: 400; }
.topbar__product {
  color: var(--brand);
  background: var(--brand-soft);
  border: 1px solid rgba(201, 169, 110, 0.3);
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
}

.topbar__nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar__link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  transition: color 0.2s, background 0.2s;
}
.topbar__link:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.topbar__link--labs img { border-radius: 4px; }
.topbar__link--labs:hover { color: var(--brand); background: var(--brand-soft); }

.topbar__btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.topbar__btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* --- Boot / loading screen --- */
.boot {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 480px at 50% 0%, rgba(124, 92, 255, 0.2), transparent 60%),
    radial-gradient(700px 420px at 50% 100%, rgba(201, 169, 110, 0.12), transparent 60%),
    var(--bg);
  transition: opacity 0.42s var(--ease), visibility 0.42s;
}
.boot--done { opacity: 0; visibility: hidden; pointer-events: none; }

.boot__inner {
  width: min(440px, 100%);
  text-align: center;
}

.boot__logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
  border-radius: 18px;
  object-fit: contain;
  box-shadow: 0 10px 40px rgba(124, 92, 255, 0.25);
}

.boot__eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: 10px;
}

.boot__title {
  font-size: clamp(2rem, 9vw, 2.9rem);
  font-weight: 800;
  letter-spacing: 0.09em;
  line-height: 1;
  color: #fff;
  margin-bottom: 22px;
}

.boot__status {
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 22px;
  margin-bottom: 12px;
}

.boot__bar {
  height: 4px;
  width: 100%;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-bottom: 24px;
}

.boot__fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: var(--grad);
  transition: width 0.4s var(--ease);
}

.boot__error {
  font-size: 0.85rem;
  color: var(--warn);
  background: rgba(255, 180, 84, 0.1);
  border: 1px solid rgba(255, 180, 84, 0.28);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 18px;
}

.boot__enter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 200px;
  padding: 14px 34px;
  border: none;
  border-radius: 8px;
  background: var(--grad);
  color: #fff;
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: transform 0.2s var(--ease), box-shadow 0.2s, opacity 0.2s;
  box-shadow: 0 10px 30px rgba(124, 92, 255, 0.3);
}
.boot__enter:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(124, 92, 255, 0.4); }
.boot__enter:disabled { opacity: 0.45; cursor: progress; box-shadow: none; }

.boot__hint {
  margin-top: 18px;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* --- Status bar --- */
.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 7px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.82rem;
  flex-wrap: wrap;
}

.statusbar__readouts { display: flex; gap: 16px; align-items: center; }

.readout {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  white-space: nowrap;
}
.readout__k {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.readout__v {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--accent);
}

.statusbar__edu { display: flex; gap: 8px; align-items: center; }

.statusbar__rec {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.statusbar__time {
  font-family: var(--font-mono);
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 5px;
  padding: 2px 7px;
}

.recdot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.5;
}
.recdot.is-live {
  background: var(--danger);
  opacity: 1;
  animation: recPulse 1.1s ease-in-out infinite;
}

@keyframes recPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 84, 112, 0.55); }
  50% { box-shadow: 0 0 0 6px rgba(255, 84, 112, 0); }
}

/* --- Keyboard --- */
.kbd {
  position: relative;
  flex: 1 1 auto;
  min-height: 172px;
  padding: 9px 9px 11px;
  background: linear-gradient(180deg, #0e0e18 0%, #08080f 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: inset 0 2px 14px rgba(0, 0, 0, 0.55);
}

.kbd__viewport {
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}
.kbd__viewport::-webkit-scrollbar { height: 8px; }
.kbd__viewport::-webkit-scrollbar-track { background: transparent; }
.kbd__viewport::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 99px;
}

/* Width = white-key width (--kw) × white-key count (--n), so the key strip
   always spans the viewport exactly. --kw is set by JS from the real
   viewport width; the :root values below are the per-breakpoint minimums. */
.kbd__keys {
  position: relative;
  display: flex;
  width: calc(var(--kw) * var(--n));
  margin-inline: auto;
  height: 100%;
}

.key {
  position: relative;
  display: block;
  border: none;
  padding: 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  transition: background 0.07s linear, box-shadow 0.07s linear, transform 0.05s linear;
}

.key--w {
  flex: 0 0 var(--kw);
  height: 100%;
  background: linear-gradient(180deg, #fdfdfd 0%, #f4f4f7 76%, #e2e2e8 100%);
  border-right: 1px solid #c4c4cf;
  border-radius: 0 0 6px 6px;
  box-shadow: inset 0 -7px 9px rgba(0, 0, 0, 0.07), 0 4px 6px rgba(0, 0, 0, 0.45);
  z-index: 1;
}

.key--b {
  position: absolute;
  top: 0;
  height: 62%;
  width: calc(var(--kw) * 0.62);
  left: calc(var(--i) * var(--kw));
  transform: translateX(-50%);
  background: linear-gradient(180deg, #2c2c3c 0%, #171722 62%, #05050b 100%);
  border-radius: 0 0 5px 5px;
  box-shadow:
    0 5px 7px rgba(0, 0, 0, 0.6),
    inset 0 -3px 4px rgba(255, 255, 255, 0.07),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  z-index: 2;
}

.key--w.is-active {
  background: linear-gradient(180deg, #ffffff 0%, #ece5ff 55%, #d4c6ff 100%);
  box-shadow:
    0 0 22px var(--accent-glow),
    inset 0 -6px 8px rgba(0, 0, 0, 0.05);
  transform: translateY(1px);
}
.key--b.is-active {
  background: linear-gradient(180deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 55%, #000) 100%);
  box-shadow: 0 0 20px var(--accent-glow), 0 3px 6px rgba(0, 0, 0, 0.5);
  transform: translateX(-50%) translateY(1px);
}

.key:hover:not(.is-active) { filter: brightness(1.04); }

.key:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
  z-index: 3;
}

.key__lab {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: #7b7b8f;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
}
.key--b .key__lab { bottom: 5px; font-size: 9px; color: #a9a9c2; }
.key--w.is-active .key__lab { color: #4b3ba0; }
.key--b.is-active .key__lab { color: #fff; }

.key__hint {
  position: absolute;
  top: 7px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--brand);
  opacity: 0;
  pointer-events: none;
}
.key--hinted .key__hint { opacity: 0.85; }
.key--b .key__hint { top: auto; bottom: 18px; font-size: 9px; color: #d9bb86; }
.key.is-active .key__hint { color: #4b3ba0; }
.key--b.is-active .key__hint { color: #fff; }

.key.is-scale::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 24px;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.55;
  pointer-events: none;
}
.key--b.is-scale::after { bottom: 20px; background: var(--tech-2); opacity: 0.75; }

/* Scroll affordances */
.kbd__scroll {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 54px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(10, 10, 18, 0.82);
  color: var(--text);
  cursor: pointer;
  z-index: 5;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.kbd__scroll:hover { border-color: var(--accent); color: var(--accent); }
.kbd__scroll--l { left: 6px; }
.kbd__scroll--r { right: 6px; }
