/* tuner.koodeksi.fi — mobile-first redesign (design hand-off: 1a "String
   rail + settings sheet"). Tokens, spacing, radii and interaction states are
   the hand-off's final values. Fonts self-hosted for the offline PWA. */

@font-face {
  font-family: 'Archivo';
  src: url('fonts/Archivo.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/JetBrainsMono.woff2') format('woff2');
  font-weight: 100 800;
  font-display: swap;
}

:root {
  --bg: #100e0b;
  --bg-inset: #0d0b09;
  --surface: #17140f;
  --border: rgba(217, 164, 65, 0.16);
  --border-neutral: rgba(236, 229, 216, 0.14);
  --hairline: rgba(236, 229, 216, 0.07);
  --amber: #d9a441;
  --green: #9ec44f;
  --red: #d4402a;
  --text: #ece5d8;
  --dim: #8a8175;
  --faint: #5f5a52;
  --faint2: #6d675d;
  --sans: 'Archivo', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* the app must never be taller than the window: size everything off the
   html/body 100% chain (tracks window resizes reliably — dvh measured at
   PWA launch on Android can be stale until a reload) and let ONLY the
   inner .scroll area scroll */
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  overscroll-behavior: none;
}

button { font: inherit; -webkit-tap-highlight-color: transparent; }
a { color: var(--amber); text-decoration: none; }
a:hover { color: #f0c574; }
button:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

@keyframes pulseDot { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
/* keep the centering translateX in every frame — a translateY-only keyframe
   would drop it for the duration of the slide on wide screens */
@keyframes sheetUp { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }

/* single column at every width; centred at 480px on wide screens */
.app {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* ===== header ===== */

.hdr {
  flex: 0 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 10px var(--red);
  animation: pulseDot 1.6s ease-in-out infinite;
}
.hdr-kicker { font-family: var(--mono); font-size: 11px; letter-spacing: 0.3em; color: var(--dim); }
.hdr-title { font-size: 17px; font-weight: 800; letter-spacing: 0.06em; }
.hdr-spacer { flex: 1; }
.hdr-status {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--green);
  text-align: right;
}
.hdr-status.error { color: var(--red); letter-spacing: 0.02em; }

/* ===== scroll area ===== */

.scroll {
  flex: 1;
  min-height: 0; /* without this a flex child refuses to shrink below its
                    content and pushes the dock off-screen */
  overflow: auto;
  padding: 4px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  scrollbar-width: none;
}
.scroll::-webkit-scrollbar { width: 0; height: 0; }

/* ===== hero ===== */

.hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px 16px 14px;
}
.hero-row { display: flex; align-items: flex-end; gap: 14px; }
.hero-note { display: flex; align-items: baseline; line-height: 0.82; }
#tuner-note {
  font-size: 96px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--dim);
}
#tuner-oct { font-size: 30px; font-weight: 600; color: var(--dim); margin-left: 2px; }
.hero-data {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  padding-bottom: 6px;
}
#tuner-cents { font-family: var(--mono); font-size: 30px; font-weight: 700; color: var(--dim); }
#tuner-dir { font-family: var(--mono); font-size: 12px; letter-spacing: 0.16em; color: var(--dim); }
#tuner-hz { font-family: var(--mono); font-size: 12px; color: var(--faint2); }

.cents-bar {
  position: relative;
  height: 46px;
  margin-top: 6px;
  border-radius: 12px;
  background: var(--bg-inset);
  overflow: hidden;
}
.cb-band {
  position: absolute;
  left: calc(50% - 7%);
  width: 14%;
  top: 0;
  bottom: 0;
  background: rgba(158, 196, 79, 0.14);
}
.cb-center {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(236, 229, 216, 0.5);
  transform: translateX(-1px);
}
.cb-needle {
  position: absolute;
  left: 50%;
  top: 5px;
  bottom: 5px;
  width: 5px;
  border-radius: 3px;
  background: var(--dim);
  transform: translateX(-2.5px);
  transition: left 0.06s linear;
}
.cb-min, .cb-max {
  position: absolute;
  bottom: 4px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
}
.cb-min { left: 12px; }
.cb-max { right: 12px; }

/* ===== panels ===== */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px;
  display: flex;
  flex-direction: column;
}
.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.panel-label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.22em; color: var(--dim); }
.panel-note { font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; color: var(--faint2); }
.link-btn {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--amber);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin: -8px;
}

/* roll + analyzers grow into free viewport space (min = the hand-off sizes);
   flex-shrink 0 keeps the minimums and lets the scroll area take over when
   the content no longer fits */
#panel-roll { flex: 3 0 auto; }
#panel-spec { flex: 2 0 auto; }
#panel-fall { flex: 2 0 auto; }
#cv-roll { width: 100%; flex: 1 1 170px; min-height: 170px; display: block; border-radius: 11px; }
#cv-spec { width: 100%; flex: 1 1 96px; min-height: 96px; display: block; border-radius: 11px; }
#cv-fall { width: 100%; flex: 1 1 110px; min-height: 110px; display: block; border-radius: 11px; }

.seg-mini { display: flex; gap: 4px; }
.seg-mini button {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--dim);
  background: var(--bg-inset);
  border: 1px solid var(--border-neutral);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}
.seg-mini button.active { background: var(--amber); color: var(--surface); border-color: var(--amber); }


.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--amber);
  background: none;
  border: 1px solid rgba(217, 164, 65, 0.3);
  border-radius: 8px;
  padding: 8px 11px;
  cursor: pointer;
}
.chip.pinned { background: rgba(217, 164, 65, 0.12); }

.free-chip {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  background: var(--bg-inset);
  border: none;
  border-radius: 9px;
  padding: 10px 12px;
  cursor: pointer;
}
.free-chip.active { background: var(--amber); color: var(--surface); }

.cal-row { display: flex; align-items: center; gap: 10px; }
.cal-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border-neutral);
  background: var(--bg-inset);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}
#a4-value {
  flex: 1;
  text-align: center;
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 700;
}

.footnote {
  font-size: 12px;
  color: var(--faint);
  text-align: center;
  margin: 0;
  padding: 2px 20px 4px;
  text-wrap: pretty;
}

/* ===== dock ===== */

.dock {
  flex: 0 0 auto;
  padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
  border-top: 1px solid var(--hairline);
  background: linear-gradient(180deg, rgba(16, 14, 11, 0) 0%, var(--bg) 22%);
}
.string-rail { display: flex; gap: 6px; margin-bottom: 10px; }
.string-key {
  flex: 1;
  height: 56px;
  border-radius: 14px;
  border: 1px solid var(--border-neutral);
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.string-key.auto { flex: 1.1; }
.string-key.active { background: var(--amber); color: var(--surface); border-color: var(--amber); }

.dock-row { display: flex; gap: 10px; align-items: center; }
.dock-sq {
  width: 60px;
  height: 60px;
  border-radius: 18px;
  border: 1px solid var(--border-neutral);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dock-sq.active { background: var(--amber); color: var(--surface); border-color: var(--amber); }
.dock-mic {
  flex: 1;
  height: 60px;
  border-radius: 18px;
  border: none;
  background: var(--amber);
  color: var(--surface);
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2em;
  cursor: pointer;
}
.dock-mic.running { background: var(--surface); color: var(--text); }

/* ===== layout sheet ===== */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 7, 6, 0.72);
  z-index: 40;
}
.sheet {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  max-height: 85dvh;
  overflow: auto;
  z-index: 41;
  background: var(--surface);
  border-top: 1px solid rgba(217, 164, 65, 0.24);
  border-radius: 24px 24px 0 0;
  padding: 12px 14px calc(env(safe-area-inset-bottom, 0px) + 28px);
  animation: sheetUp 0.22s ease-out;
}
.sheet-handle {
  width: 44px;
  height: 4px;
  border-radius: 2px;
  background: rgba(236, 229, 216, 0.2);
  margin: 0 auto 14px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sheet-label { font-family: var(--mono); font-size: 11px; letter-spacing: 0.24em; color: var(--dim); }
.sheet-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 330px;
  overflow: auto;
  scrollbar-width: none;
}
.sheet-rows::-webkit-scrollbar { width: 0; }
.sheet-row {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 54px;
  flex: 0 0 auto;
  padding: 0 14px;
  border-radius: 14px;
  background: var(--bg-inset);
  border: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.sheet-row .row-label { flex: 1; font-size: 15px; font-weight: 500; color: var(--dim); }
.sheet-row.on .row-label { color: var(--text); }
.switch {
  width: 48px;
  height: 28px;
  border-radius: 14px;
  background: var(--border-neutral);
  position: relative;
  flex: 0 0 auto;
}
.sheet-row.on .switch { background: var(--amber); }
.switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--dim);
  transition: left 0.16s ease;
}
.sheet-row.on .switch-knob { left: 23px; background: var(--surface); }

.tuning-label { margin: 16px 0 8px; font-size: 10px; letter-spacing: 0.22em; }
.tuning-row { display: flex; gap: 7px; }
.tuning-chip {
  flex: 1;
  height: 48px;
  border-radius: 13px;
  border: 1px solid var(--border-neutral);
  background: var(--bg-inset);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.tuning-chip.active { background: var(--amber); color: var(--surface); border-color: var(--amber); }
.sheet-label-hint {
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--faint2);
}
.sheet-foot { font-size: 12px; color: var(--faint); margin-top: 14px; }

/* ===== about screen: full height, content scrolls, close always visible ===== */

.about {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.about-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 32px) 24px 28px;
  scrollbar-width: none;
}
.about-scroll::-webkit-scrollbar { width: 0; }
.about-close-bar {
  flex: 0 0 auto;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 10px 24px calc(env(safe-area-inset-bottom, 0px) + 12px);
  border-top: 1px solid var(--hairline);
  background: linear-gradient(180deg, rgba(16, 14, 11, 0) 0%, var(--bg) 22%);
}
.about-close-bar .sheet-done { margin-top: 0; }

/* big hero header — scales down and fades as the page scrolls (JS drives
   transform/opacity from scrollTop); past the threshold the compact sticky
   bar below slides in over it */
.ab-head {
  text-align: center;
  margin-bottom: 38px;
  transform-origin: top center;
  will-change: transform, opacity;
}
.ab-logo { width: 116px; height: 116px; border-radius: 26px; }
.ab-title { font-size: 32px; font-weight: 800; letter-spacing: 0.07em; margin-top: 16px; }
.ab-by { font-family: var(--mono); font-size: 13px; letter-spacing: 0.3em; color: var(--dim); margin-top: 8px; }
.ab-by a { color: var(--amber); }

/* compact sticky version: icon left, name and credit beside it */
.ab-topbar {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -110%);
  width: 100%;
  max-width: 480px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 24px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--hairline);
  opacity: 0;
  transition: transform 0.28s ease, opacity 0.28s ease;
  pointer-events: none;
}
.ab-topbar.show { transform: translate(-50%, 0); opacity: 1; }
.ab-topbar-logo { width: 26px; height: 26px; border-radius: 7px; }
.ab-topbar-title { font-size: 16px; font-weight: 800; letter-spacing: 0.06em; }
.ab-topbar-by { font-family: var(--mono); font-size: 11px; letter-spacing: 0.22em; color: var(--dim); }

.ab-intro {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  text-align: center;
  margin: 0 0 40px;
  text-wrap: pretty;
}

.ab-sec { margin-bottom: 40px; }
.ab-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--amber);
  margin-bottom: 12px;
}
.ab-vis { width: 100%; height: auto; display: block; margin-bottom: 12px; }
.ab-text {
  font-size: 14px;
  line-height: 1.55;
  color: #b6ada0;
  margin: 0;
  text-wrap: pretty;
}
.ab-cap {
  font-size: 13px;
  line-height: 1.5;
  color: #b6ada0;
  margin: 8px 0 18px;
}
.ab-chips { margin-bottom: 12px; }
.ab-chips .chip { cursor: default; }

.ab-foot {
  font-size: 12px;
  line-height: 1.8;
  color: var(--faint);
  text-align: center;
  margin: 8px 0 0;
}

.about-row { margin-top: 8px; }
.about-row .row-label { color: var(--text); }
.row-chev { color: var(--dim); font-size: 20px; line-height: 1; }

/* primary close action: full-width, thumb-sized (was a small text link) */
.sheet-done {
  width: 100%;
  height: 54px;
  margin-top: 12px;
  border: none;
  border-radius: 14px;
  background: var(--amber);
  color: var(--surface);
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2em;
  cursor: pointer;
}
