/* Great Tones — digital pitch pipe UI.
   Base tokens/reset from great-apps/framework.css via CDN. */

/* Disable text selection / long-press callout app-wide — otherwise the
   press-and-hold-to-remove gesture on Sounding chips (and holding keys) trips
   the mobile text-selection / callout menu. Editable fields opt back in. */
.view, .settings-overlay {
  -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
input, select, textarea {
  -webkit-user-select: text; -moz-user-select: text; -ms-user-select: text; user-select: text;
}

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

.app-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  display: flex;
  flex-direction: column;
}

/* ── Tuning bar ─────────────────────────── */
.tuning-bar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }

.ref-control { display: flex; align-items: center; justify-content: center; gap: 8px; }
.ref-label { font-weight: 600; font-size: 1.05rem; color: var(--text); }
.ref-label sub { font-size: 0.6em; }
.ref-value {
  width: 66px; text-align: center; padding: 8px 6px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 1.05rem; font-weight: 600; outline: none;
  -moz-appearance: textfield;
}
.ref-value:focus { border-color: var(--accent); }
.ref-value::-webkit-outer-spin-button,
.ref-value::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ref-unit { color: var(--text-muted); font-size: 0.85rem; }

.step-btn {
  width: 38px; height: 38px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 1.3rem; line-height: 1; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.step-btn:hover { border-color: var(--accent); }
.step-btn:active { background: var(--bg-active); }

.tuning-row { display: flex; align-items: center; gap: 12px; justify-content: center; flex-wrap: wrap; }
.seg-control { display: flex; gap: 6px; }
.seg-btn {
  padding: 8px 18px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-muted); font-size: 0.85rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.seg-btn.active { color: #fff; background: var(--accent-dim); border-color: var(--accent); }

.key-control { display: flex; align-items: center; gap: 6px; }
.key-control label { color: var(--text-muted); font-size: 0.85rem; }
.key-control select {
  padding: 8px 10px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.9rem; outline: none; cursor: pointer;
}
.key-control.disabled { opacity: 0.4; }

/* ── Keyboard ───────────────────────────── */
.piano {
  position: relative; width: 100%; height: 210px;
  --bk-w: 8.6%;
  margin: 6px 0 12px;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.white-row { display: flex; height: 100%; }
.key {
  position: relative;
  display: flex; align-items: flex-end; justify-content: center;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background 0.08s, box-shadow 0.08s, color 0.08s;
}
.key-name { pointer-events: none; font-size: 0.8rem; }
.key.white {
  flex: 1 1 0; min-width: 0;
  background: linear-gradient(#21212e, #16161f);
  border: 1px solid #000; border-top: none;
  border-radius: 0 0 7px 7px;
  color: var(--text-muted);
  padding-bottom: 12px;
}
.key.white:first-child { border-radius: 0 0 7px 8px; }
.key.white.active {
  background: linear-gradient(var(--accent), var(--accent-dim));
  color: #fff;
  box-shadow: 0 0 16px rgba(124, 111, 255, 0.45), 0 0 22px rgba(124, 111, 255, 0.3) inset;
}
.key.black {
  position: absolute; top: 0;
  width: var(--bk-w); height: 62%;
  background: linear-gradient(#101018, #000);
  border: 1px solid #000; border-radius: 0 0 6px 6px;
  color: #a0a0b8; z-index: 2;
  padding-bottom: 9px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.55);
}
.key.black .key-name { font-size: 0.68rem; }
.key.black.active {
  background: linear-gradient(var(--accent), #4a3fc0);
  color: #fff;
  box-shadow: 0 0 16px rgba(124, 111, 255, 0.7);
}

/* Held-but-muted key (note still latched, silenced). */
.key.note-muted {
  background: linear-gradient(#2a2a3a, #202028);
  color: var(--text-muted);
  box-shadow: 0 0 8px rgba(124, 111, 255, 0.18) inset;
}
.key.black.note-muted { background: linear-gradient(#20202c, #14141c); }

/* Tonic (just-intonation key) marker. */
.key.tonic .key-name { color: #ffd166; }
.key.white.tonic::after,
.key.black.tonic::after {
  content: ""; position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  width: 6px; height: 6px; border-radius: 50%; background: #ffd166;
  box-shadow: 0 0 6px rgba(255, 209, 102, 0.8);
}

/* Denser labels when several octaves are shown. */
.piano[data-octaves="2"] .key-name,
.piano[data-octaves="3"] .key-name { font-size: 0.6rem; }
.piano[data-octaves="2"] .key.black .key-name,
.piano[data-octaves="3"] .key.black .key-name { display: none; }

/* ── Circular pitch-pipe layout ─────────────── */
.piano.pipe-layout { height: auto; }
.pipe {
  position: relative; width: min(320px, 82vw); margin: 6px auto 14px;
  aspect-ratio: 1 / 1; --r: 118px; border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #1a1a26, #101016 70%);
  border: 1px solid var(--border);
}
.wedge {
  position: absolute; top: 50%; left: 50%;
  width: 15%; height: 15%; min-width: 42px; min-height: 42px; max-width: 54px; max-height: 54px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transform: translate(-50%, -50%) rotate(var(--ang)) translateY(calc(-1 * var(--r))) rotate(calc(-1 * var(--ang)));
  transition: background 0.08s, box-shadow 0.08s, color 0.08s;
}
.wedge.nat { background: linear-gradient(#26263440, #1a1a2440); border: 1px solid var(--border); color: var(--text); }
.wedge.acc { background: linear-gradient(#12121a, #0a0a10); border: 1px solid #000; color: #a0a0b8; }
.wedge-label { pointer-events: none; font-size: 0.85rem; font-weight: 600; }
.wedge.active {
  background: linear-gradient(var(--accent), var(--accent-dim)); color: #fff;
  box-shadow: 0 0 16px rgba(124, 111, 255, 0.6);
}
.wedge.note-muted { background: linear-gradient(#2a2a3a, #202028); color: var(--text-muted); }
.wedge.tonic { border-color: #ffd166; box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.55); }
.wedge.tonic .wedge-label { color: #ffd166; }
.pipe-hub {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  pointer-events: none; text-align: center;
}
.hub-oct { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.hub-sub { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }

/* ── Layout + sustain quick toggles ─────────── */
.play-bar { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; margin: 2px 0 12px; }

/* ── Keyboard controls ──────────────────── */
.kbd-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 10px; flex-wrap: wrap; }
.octave-control { display: flex; align-items: center; gap: 8px; }
#size-control[hidden], #pos-row[hidden] { display: none; }

/* Piano position slider — pick which white key sits lowest. */
.pos-row { display: flex; align-items: center; gap: 12px; margin: 0 0 14px; }
.pos-label { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }
.pos-label b { color: var(--accent); }
.pos-row input[type="range"] { flex: 1; accent-color: var(--accent); }

/* Highest implied fundamental readout. */
.fundamental {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; margin: 0 0 12px;
  background: var(--bg-active); border: 1px solid var(--border); border-radius: var(--radius);
}
.fundamental.empty { opacity: 0.6; }
.fund-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 600;
}
.fund-value { font-size: 0.9rem; color: var(--text); }
.fund-value b { color: var(--accent); font-size: 1rem; }
.fund-cents { color: #ffd166; }
.fund-ratio { color: #ffd166; font-variant-numeric: tabular-nums; }
.octave-readout { font-size: 0.95rem; color: var(--text); min-width: 56px; text-align: center; }
.octave-readout b { color: var(--accent); }
.stop-btn {
  padding: 9px 18px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-muted); font-size: 0.9rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.stop-btn:not(:disabled):hover { border-color: var(--accent); color: var(--text); }
.stop-btn:disabled { opacity: 0.4; cursor: default; }

/* ── Now sounding ───────────────────────── */
.sounding-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.sounding-head > span:first-child {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 600;
}
.sounding-hint { font-size: 0.75rem; color: var(--text-muted); }
.sounding { display: flex; flex-wrap: wrap; gap: 8px; }
.sound-chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 12px; min-width: 64px;
  background: var(--bg-active); border: 1px solid var(--accent); border-radius: var(--radius);
  cursor: pointer;
}
.chip-note { font-weight: 700; font-size: 1rem; color: #fff; }
.chip-hz { font-size: 0.72rem; color: var(--text-muted); }
.chip-hz .cents { color: #ffd166; margin-left: 4px; }
.sound-chip.muted { opacity: 0.55; border-color: var(--border); background: var(--bg); }
.sound-chip.muted .chip-note { color: var(--text-muted); text-decoration: line-through; }
.chip-badge {
  font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin-top: 1px;
}
.sounding-empty { color: var(--text-muted); font-size: 0.9rem; padding: 8px 2px; line-height: 1.4; }

/* ── Settings drawer (shared pattern) ───── */
.settings-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 50; display: flex; justify-content: flex-end; }
.settings-panel { width: min(400px, 88vw); background: var(--bg-surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; height: 100%; }
.settings-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
}
.settings-head h2 { font-size: 1.1rem; font-weight: 600; }
.settings-scroll { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 24px; }
.setting-block h3 {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin-bottom: 10px; font-weight: 600;
}

.inst-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.inst-btn {
  padding: 9px 4px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-muted); font-size: 0.8rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent; transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.inst-btn:hover { border-color: var(--accent); }
.inst-btn.active { color: #fff; background: var(--accent-dim); border-color: var(--accent); }

.slider-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; font-size: 0.9rem; }
.slider-row input[type="range"] { flex: 1; accent-color: var(--accent); }

.preset-row { display: flex; gap: 6px; }
.seg-control.full { display: flex; gap: 6px; margin-bottom: 12px; }
.seg-control.full .seg-btn { flex: 1; text-align: center; }
.stepper-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.9rem; padding: 6px 0; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper b { min-width: 18px; text-align: center; color: var(--accent); font-size: 1rem; }
.preset-btn {
  flex: 1; padding: 9px 6px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.85rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.preset-btn:hover { border-color: var(--accent); }
.preset-btn.active { color: #fff; background: var(--accent-dim); border-color: var(--accent); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.9rem; padding: 6px 0; }
.toggle-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.setting-note { font-size: 0.78rem; color: var(--text-muted); margin-top: 8px; line-height: 1.45; }

.settings-foot {
  padding: 12px 16px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
}
.foot-note { font-size: 0.78rem; color: var(--text-muted); }

/* ── Mobile ─────────────────────────────── */
@media (max-width: 420px) {
  .piano { height: 190px; }
  .seg-btn { padding: 8px 14px; }
  .key-name { font-size: 0.72rem; }
}
