/* =========================================================================
   TM Trainer — Tuner 2.0 styles (RTL, light/dark via the app tokens)
   ========================================================================= */
.tuner-wrap {
  --ok: #15803d; --hi: #b45309; --lo: #0369a1;
  --ok-c: #22c55e; --hi-c: #f0a93b; --lo-c: #38bdf8;
  max-width: 460px;
  margin: 0 auto;
  padding: 12px clamp(12px, 4vw, 20px) 40px;
  display: flex; flex-direction: column; gap: 12px;
}
html[data-theme="dark"] .tuner-wrap { --ok: #4ade80; --hi: #fbbf24; --lo: #7dd3fc; }

/* ---------- header: tuning + settings ---------- */
.tuner-bar { display: flex; align-items: center; gap: 10px; }
.tuner-preset { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1 1 auto; }
.tp-kicker { font-size: 10.5px; font-weight: 700; color: var(--ink-3); letter-spacing: .02em; }
.tp-select { position: relative; display: flex; align-items: center; }
.tp-select select {
  appearance: none; -webkit-appearance: none;
  width: 100%; padding: 2px 0 2px 22px; padding-inline-start: 0; padding-inline-end: 22px;
  background: transparent; border: 0; color: var(--ink);
  font: inherit; font-size: 17px; font-weight: 800; cursor: pointer;
  text-overflow: ellipsis;
}
.tp-select select:focus { outline: none; }
.tp-select select:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
.tp-chev { position: absolute; inset-inline-end: 0; width: 16px; height: 16px; color: var(--ink-3); pointer-events: none; }
.tp-notes { align-self: flex-start; font-size: 11px; font-weight: 700; color: var(--ink-3); letter-spacing: .12em; text-align: start; }
.tuner-gear {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 14px; border: 1.5px solid var(--line-2);
  background: var(--surface); color: var(--ink-2);
  transition: all .18s;
}
.tuner-gear svg { width: 21px; height: 21px; }
.tuner-gear.on { background: var(--gold-soft); border-color: var(--gold); color: var(--gold-ink); }
html[data-theme="dark"] .tuner-gear.on { color: var(--gold); }

/* ---------- settings ---------- */
.tuner-settings {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 4px 14px; box-shadow: var(--shadow-s);
}
.tuner-settings[hidden] { display: none; }
.ts-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.ts-row:last-child { border-bottom: 0; }
.ts-lbl { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ts-lbl b { font-size: 13px; font-weight: 700; color: var(--ink); }
.ts-lbl small { font-size: 10.5px; color: var(--ink-3); }
.ts-step { display: flex; align-items: center; gap: 6px; flex: none; }
.ts-step button {
  min-width: 34px; height: 34px; padding: 0 8px; border-radius: 10px;
  background: var(--surface-2); border: 1.5px solid var(--line-2);
  font-size: 18px; font-weight: 700; color: var(--ink); line-height: 1;
}
.ts-step button:active { transform: scale(.92); }
.ts-step output { font-size: 17px; font-weight: 800; min-width: 34px; text-align: center; color: var(--ink); font-variant-numeric: tabular-nums; }
.ts-unit { font-size: 11px; color: var(--ink-3); font-weight: 700; margin-inline-end: 4px; }
.ts-step .ts-reset { font-size: 11px; font-weight: 700; color: var(--ink-3); }
.ts-sel {
  appearance: none; -webkit-appearance: none;
  height: 36px; padding: 0 10px; padding-inline-end: 28px; border-radius: 10px;
  background: var(--surface-2); border: 1.5px solid var(--line-2);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 12px 12px;
  background-position: left 10px center;
  color: var(--ink); font: inherit; font-size: 12.5px; font-weight: 600; max-width: 56%;
  cursor: pointer;
}
.ts-sw { cursor: pointer; }
.ts-sw input { position: absolute; opacity: 0; pointer-events: none; }
.ts-sw i {
  position: relative; flex: none; width: 46px; height: 28px; border-radius: 99px;
  background: var(--surface-3); border: 1.5px solid var(--line-2); transition: background .2s, border-color .2s;
}
.ts-sw i::after {
  content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 21px; height: 21px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); transition: inset-inline-start .2s;
}
.ts-sw input:checked + i { background: var(--ok-c); border-color: var(--ok-c); }
.ts-sw input:checked + i::after { inset-inline-start: 20px; }
.ts-sw input:focus-visible + i { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- mode switch ---------- */
.tmodes {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px;
  padding: 4px; border-radius: 15px; background: var(--surface-3);
}
.tmode {
  height: 36px; border-radius: 11px; font-size: 12.5px; font-weight: 700; color: var(--ink-3);
  transition: background .18s, color .18s, box-shadow .18s;
}
.tmode.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(11,23,48,.16); }
html[data-theme="dark"] .tmode.active { background: var(--surface-2); box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.tmode:active { transform: scale(.96); }

/* ---------- meter card ---------- */
.tuner-card {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  padding: 12px 14px 12px; box-shadow: var(--shadow-m);
  --tune: var(--ink-3);
  transition: border-color .25s, box-shadow .25s;
}
.tuner-card::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(110% 70% at 50% 18%, color-mix(in srgb, var(--tune) 20%, transparent), transparent 66%);
  opacity: .75; transition: opacity .35s, background .35s;
}
.tuner-card.state-in-tune { --tune: var(--ok-c); }
.tuner-card.state-sharp   { --tune: var(--hi-c); }
.tuner-card.state-flat    { --tune: var(--lo-c); }
.tuner-card.state-far     { --tune: #94a3b8; }
.tuner-card.is-off::before { opacity: 0; }
.tuner-card.is-locked { border-color: color-mix(in srgb, var(--ok-c) 60%, var(--line)); box-shadow: var(--shadow-m), 0 0 0 3px color-mix(in srgb, var(--ok-c) 22%, transparent); }
.tc-level { position: absolute; top: 0; left: 0; right: 0; height: 3px; direction: ltr; background: color-mix(in srgb, var(--ink-3) 14%, transparent); }
.tc-level i { display: block; height: 100%; width: 0; background: var(--tune); transition: width .08s linear; }

.tg { position: relative; margin: 6px 0 0; }
.tg svg { display: block; width: 100%; height: auto; overflow: visible; }
.tg-track { stroke: var(--surface-3); }
.tg-zone  { stroke: color-mix(in srgb, var(--ok-c) 38%, transparent); transition: stroke .2s; }
.tuner-card.state-in-tune .tg-zone { stroke: var(--ok-c); }
.tg-tick { stroke: var(--ink-3); stroke-width: 1.4; opacity: .55; }
.tg-tick.major { stroke-width: 2; opacity: .8; }
.tg-tick.zero { stroke: var(--ok); stroke-width: 2.6; opacity: 1; }
.tg-num { font-size: 10.5px; font-weight: 700; fill: var(--ink-3); font-family: var(--font); }
.tg-num.zero { fill: var(--ok); }
.tg-needle { fill: var(--ink-3); opacity: .5; transition: fill .2s, opacity .2s; }
.tuner-card.state-in-tune .tg-needle, .tuner-card.state-sharp .tg-needle, .tuner-card.state-flat .tg-needle { fill: var(--tune); opacity: 1; }
.tuner-card.is-hold .tg-needle { opacity: .55; }

.tg-end { position: absolute; top: 36%; font-size: 20px; font-weight: 800; color: var(--ink-3); opacity: .6; }
.tg-flat { left: 3%; } .tg-sharp { right: 3%; }

.tg-note { position: absolute; left: 0; right: 0; bottom: 0; text-align: center; pointer-events: none; }
.tg-letter {
  font-size: clamp(48px, 14vw, 60px); font-weight: 900; line-height: .95; letter-spacing: -.02em;
  color: var(--ink); font-family: var(--font); transition: color .2s;
}
.tg-letter.is-empty { color: var(--ink-3); opacity: .4; }
.tuner-card.state-in-tune .tg-letter { color: var(--ok); }
.tuner-card.is-hold .tg-letter { opacity: .8; }
.tg-sub { display: flex; justify-content: center; gap: 8px; font-size: 13px; font-weight: 800; color: var(--ink-3); min-height: 18px; margin-top: 2px; direction: rtl; }

.tc-reads { position: relative; display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 6px; margin-top: 8px; }
.tc-read { display: flex; flex-direction: column; align-items: center; gap: 0; padding: 4px 4px 3px; border-radius: 12px; background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.tc-read span { font-size: 10px; color: var(--ink-3); font-weight: 700; }
.tc-read b { font-size: 15px; font-weight: 800; color: var(--ink); line-height: 1.35; font-variant-numeric: tabular-nums; direction: ltr; }
.tc-read small { font-size: 9.5px; color: var(--ink-3); font-weight: 600; }
.tc-cents b { font-size: 19px; }
.tuner-card.state-in-tune .tc-cents b { color: var(--ok); }
.tuner-card.state-sharp .tc-cents b { color: var(--hi); }
.tuner-card.state-flat .tc-cents b { color: var(--lo); }

.tc-status {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; margin-top: 8px; padding: 6px 12px; border-radius: 13px;
  font-size: 13px; font-weight: 700; line-height: 1.5; text-align: center;
  background: var(--surface-2); color: var(--ink-2); transition: background .2s, color .2s;
}
.tc-status svg { width: 17px; height: 17px; flex: none; }
.tc-status.idle { color: var(--ink-3); }
.tc-status.in-tune { background: color-mix(in srgb, var(--ok-c) 16%, transparent); color: var(--ok); }
.tc-status.sharp { background: color-mix(in srgb, var(--hi-c) 18%, transparent); color: var(--hi); }
.tc-status.flat { background: color-mix(in srgb, var(--lo-c) 18%, transparent); color: var(--lo); }
.tc-status.far { background: var(--surface-2); color: var(--ink-3); }
.tuner-card.is-hold .tc-status { opacity: .9; }

/* ---------- headstock ---------- */
.tuner-head {
  display: grid; grid-template-columns: 62px minmax(0, 1fr) 62px; align-items: center; justify-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  padding: 8px 6px 4px; box-shadow: var(--shadow-s);
  /* The headstock drawing is a front view of a right-handed guitar: the three
     bass strings (6·5·4) go to the LEFT posts, the treble ones (1·2·3) to the
     RIGHT. The page is RTL, which used to flip the two button columns and make
     the buttons sit on the opposite side of the strings they belong to. Lock
     the geometry to LTR so buttons and pegs always line up. */
  direction: ltr;
}
.tuner-head .th-col,
.tuner-head .tuner-progress-row { direction: rtl; }
.th-col { display: grid; grid-template-rows: repeat(3, 1fr); height: 206px; align-items: center; justify-items: center; }
.th-stock { display: flex; justify-content: center; }
.headstock-svg { width: 110px; height: auto; display: block; }
.headstock-svg .hs-body { fill: url(#hsWood); stroke: url(#hsRim); stroke-width: 3; }
.headstock-svg .hs-strings line { stroke: #cfd5de; transition: stroke .2s, filter .2s; }
.headstock-svg .hs-strings line.is-on { stroke: var(--gold); filter: drop-shadow(0 0 3px color-mix(in srgb, var(--gold) 80%, transparent)); }

.string-btn {
  position: relative; width: 54px; height: 54px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  background: var(--surface-2); border: 2px solid var(--line-2); color: var(--ink);
  transition: background .18s, border-color .18s, box-shadow .18s, transform .1s;
}
.string-btn:active { transform: scale(.93); }
.sb-letter { font-size: 18px; font-weight: 900; line-height: 1; }
.sb-oct { position: absolute; top: 9px; inset-inline-end: 9px; font-size: 9px; font-weight: 800; color: var(--ink-3); line-height: 1; }
.sb-fa { font-size: 9.5px; font-weight: 700; color: var(--ink-3); line-height: 1.1; margin-top: 1px; min-height: 10px; }
.sb-arrow { position: absolute; bottom: -7px; width: 0; height: 0; display: none; }
.string-btn[data-dir] .sb-arrow { display: block; }
.string-btn[data-dir="up"] .sb-arrow { border-inline: 6px solid transparent; border-bottom: 8px solid var(--lo-c); }
.string-btn[data-dir="down"] .sb-arrow { border-inline: 6px solid transparent; border-top: 8px solid var(--hi-c); }
.sb-done {
  position: absolute; top: -3px; inset-inline-start: -3px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; background: var(--ok-c); color: #04160a; border: 2px solid var(--surface);
  transform: scale(0); transition: transform .22s cubic-bezier(.3,1.6,.5,1);
}
.sb-done svg { width: 11px; height: 11px; }
.string-btn.is-done .sb-done { transform: scale(1); }
.string-btn.is-active { border-color: var(--gold); box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 24%, transparent); }
.string-btn.is-in-tune { background: color-mix(in srgb, var(--ok-c) 24%, var(--surface)); border-color: var(--ok-c); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok-c) 26%, transparent); }
.string-btn.is-sharp { background: color-mix(in srgb, var(--hi-c) 20%, var(--surface)); border-color: var(--hi-c); box-shadow: 0 0 0 4px color-mix(in srgb, var(--hi-c) 20%, transparent); }
.string-btn.is-flat { background: color-mix(in srgb, var(--lo-c) 20%, var(--surface)); border-color: var(--lo-c); box-shadow: 0 0 0 4px color-mix(in srgb, var(--lo-c) 20%, transparent); }
.string-btn.is-tone { border-color: var(--teal); box-shadow: 0 0 0 4px color-mix(in srgb, var(--teal) 24%, transparent); animation: tn-pulse 1.4s ease-in-out infinite; }
@keyframes tn-pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--teal) 10%, transparent); } }

.tuner-progress-row { grid-column: 1 / -1; justify-self: stretch; display: flex; align-items: center; justify-content: space-between; padding: 0 10px; min-height: 26px; border-top: 1px solid var(--line); margin-top: 4px; }
.tuner-progress { font-size: 11.5px; font-weight: 700; color: var(--ink-3); transition: color .2s; }
.tuner-progress.on { color: var(--ok); }
.tuner-link { font-size: 11.5px; font-weight: 700; color: var(--ink-3); padding: 4px 6px; border-radius: 8px; }
.tuner-link:active { background: var(--surface-3); }

/* ---------- controls ---------- */
.tuner-controls {
  position: sticky; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px;
  margin: 0 calc(-1 * clamp(12px, 4vw, 20px)); padding: 22px clamp(12px, 4vw, 20px) calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to bottom, transparent 0, var(--bg) 34%);
}
.tuner-start {
  height: 54px; display: flex; align-items: center; justify-content: center; gap: 9px;
  border-radius: 17px; color: var(--primary-ink); font-size: 14.5px; font-weight: 800;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  box-shadow: 0 10px 22px -12px color-mix(in srgb, var(--primary) 80%, transparent);
  transition: transform .12s, box-shadow .2s, background .2s;
}
.tuner-start svg { width: 20px; height: 20px; }
.tuner-start:active { transform: scale(.985); }
.tuner-start.on { background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%); color: #fff; box-shadow: 0 10px 22px -12px rgba(220,38,38,.8); }
html[data-theme="dark"] .tuner-start { color: var(--gold-ink); }
html[data-theme="dark"] .tuner-start.on { background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%); color: #fff; }
.tuner-ref {
  width: 58px; height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border-radius: 17px; border: 1.5px solid var(--line-2); background: var(--surface); color: var(--ink-2); transition: all .18s;
}
.tuner-ref svg { width: 19px; height: 19px; }
.tuner-ref span { font-size: 9px; font-weight: 800; }
.tuner-ref.on { border-color: var(--teal); background: var(--teal-soft); color: var(--teal); }

/* ---------- guide ---------- */
.tuner-guide { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 0 14px; }
.tuner-guide summary { cursor: pointer; list-style: none; padding: 13px 0; font-size: 13px; font-weight: 800; color: var(--ink); display: flex; align-items: center; justify-content: space-between; }
.tuner-guide summary::-webkit-details-marker { display: none; }
.tuner-guide summary::after { content: ""; width: 9px; height: 9px; border-inline-end: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg); transition: transform .2s; margin-top: -4px; }
.tuner-guide[open] summary::after { transform: rotate(-135deg); margin-top: 4px; }
.tg-body { padding: 0 0 14px; font-size: 12.5px; line-height: 2; color: var(--ink-2); }
.tg-body h4 { font-size: 12.5px; font-weight: 800; color: var(--ink); margin: 10px 0 2px; }
.tg-body ul { margin: 0; padding-inline-start: 18px; }
.tg-body p { margin: 0; }

@media (max-width: 380px) {
  .tuner-head { grid-template-columns: 56px minmax(0, 1fr) 56px; }
  .string-btn { width: 50px; height: 50px; }
  .headstock-svg { width: 100px; }
  .th-col { height: 190px; }
}
@media (prefers-reduced-motion: reduce) {
  .string-btn.is-tone { animation: none; }
}
