:root {
  --bg: #10130f;
  --bg-raise: #171c15;
  --cream: #f4efe6;
  --cream-soft: #ddd4c6;
  --muted: #b7b0a3;
  --gold: #d7b98a;
  --gold-2: #f3e6cc;
  --sage: #b7cbb0;
  --sage-deep: #6f8f72;
  --copper: #e0a07a;
  --rose: #c45c6a;
  --rose-gold: #e4c2b8;
  --line: rgba(215, 185, 138, 0.22);
  --line-strong: rgba(215, 185, 138, 0.45);
  --serif: "EB Garamond", "Palatino Linotype", Palatino, "Noto Serif", "Times New Roman", serif;
  --sans: "Source Sans 3", "Segoe UI", "Noto Sans", "Noto Sans Arabic", "Noto Naskh Arabic", "Noto Sans Devanagari", "Noto Sans CJK SC", "Noto Sans JP", sans-serif;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --radius: 20px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

html { scroll-behavior: smooth; }

html.booting body { visibility: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--cream);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.45;
  background:
    radial-gradient(900px 420px at 50% -12%, rgba(196, 154, 90, 0.16), transparent 60%),
    radial-gradient(480px 320px at 0% 0%, rgba(196, 92, 106, 0.09), transparent 62%),
    radial-gradient(700px 480px at 110% 80%, rgba(90, 122, 96, 0.12), transparent 55%),
    var(--bg);
}

button, input, textarea { font: inherit; color: inherit; }

button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

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

.app {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 8px 0 calc(88px + env(safe-area-inset-bottom));
}

.top { text-align: center; padding: 2px 0 8px; }

.lang {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.lang select {
  min-height: 36px;
  max-width: 11.5rem;
  border-radius: 999px;
  border: 1px solid rgba(196, 92, 106, 0.45);
  background: rgba(8, 10, 8, 0.45);
  color: var(--gold-2);
  padding-block: 0;
  padding-inline: 12px 28px;
  font-size: 0.86rem;
  font-weight: 600;
}

.monogram {
  width: 32px;
  height: 32px;
  margin: 2px auto 2px;
  color: var(--gold);
  display: block;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  color: var(--gold-2);
}

h1 .name {
  display: block;
  font-size: clamp(1.85rem, 6.4vw, 3.1rem);
  line-height: 0.92;
  letter-spacing: 0.01em;
}

h1 .rose-mark {
  font-size: 0.92em;
  line-height: 1;
}

h1 .rest {
  display: block;
  margin-top: 2px;
  font-size: clamp(0.98rem, 3.1vw, 1.25rem);
  font-weight: 500;
  color: var(--cream-soft);
}

.tagline {
  margin: 6px auto 0;
  max-width: 38rem;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  color: var(--cream-soft);
  line-height: 1.25;
}

.tagline.line2 { font-size: 0.86rem; }

.tagline.line3 {
  margin-top: 8px;
  max-width: 36rem;
  font-size: clamp(0.92rem, 3.4vw, 1.08rem);
  font-style: normal;
  font-weight: 500;
  color: var(--cream);
  line-height: 1.3;
}

.meander {
  width: min(180px, 52%);
  height: 10px;
  margin: 8px auto 0;
  color: var(--gold);
  opacity: 0.75;
}

.columns { display: grid; gap: 14px; }

.card {
  background: linear-gradient(180deg, rgba(255, 244, 220, 0.04), rgba(255, 244, 220, 0.015));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 244, 220, 0.05);
  padding: 12px 14px;
}

.kicker {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

.composer-note, .hint, .fine {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.composer-note { margin-top: 4px; font-size: 0.82rem; }

textarea {
  display: block;
  width: 100%;
  min-height: 0;
  resize: vertical;
  border: 0;
  border-radius: 14px;
  padding: 6px 8px;
  background: rgba(8, 10, 8, 0.35);
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 500;
  line-height: 1.25;
}

textarea::placeholder { color: #8f877a; font-style: italic; }

.toolbar, .transport, .share-actions, .bit-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.toolbar { margin-top: 0; gap: 2px; }

.text-btn, .ghost, .solid {
  min-height: 44px;
  border-radius: 999px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--cream-soft);
}

.text-btn {
  min-height: 44px;
  padding: 0 6px;
  color: var(--sage);
  border-color: transparent;
  font-size: 0.92rem;
}

.solid {
  background: #314233;
  border-color: rgba(196, 92, 106, 0.45);
  color: var(--gold-2);
  font-weight: 600;
}

.ghost { background: rgba(255, 244, 220, 0.03); }

button:disabled { opacity: 0.45; }

.banner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

.banner p { margin: 0; font-family: var(--serif); font-size: 1.25rem; }

.combo { min-height: 4.5rem; }

.invite {
  margin: 8px 0;
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.2rem;
}

.combo-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  row-gap: 8px;
}

.chunk {
  display: grid;
  grid-template-rows: 1fr auto;
  grid-auto-flow: column;
  align-items: stretch;
  justify-items: center;
}

.sep,
.pair {
  display: grid;
  grid-template-rows: subgrid;
  grid-row: 1 / -1;
  align-items: center;
  justify-items: center;
}

.sep {
  padding: 0 3px;
  color: rgba(215, 185, 138, 0.62);
  font-family: var(--serif);
  line-height: 1;
}

.pair {
  min-width: 44px;
  min-height: 48px;
  padding: 0 6px;
  border: 0;
  border-radius: 12px;
  background: transparent;
}

.chunk.is-hz-only {
  grid-template-rows: auto;
  align-items: center;
}

.chunk.is-hz-only .sep,
.chunk.is-hz-only .pair {
  display: flex;
  grid-template-rows: none;
  grid-row: auto;
  align-items: center;
}

.pair[aria-pressed="true"] {
  background: rgba(215, 185, 138, 0.1);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.pair.is-on {
  background: rgba(215, 185, 138, 0.16);
  box-shadow: inset 0 0 0 1px var(--gold);
}

.pair-word,
.sep-word {
  font-family: var(--serif);
  font-size: 1.12rem;
  font-weight: 500;
  line-height: 1.05;
}

.sep-word,
.sep-hz {
  position: relative;
  top: -0.1em;
}

.pair-word {
  max-width: 11rem;
  overflow-wrap: anywhere;
  text-align: center;
}

.pair-hz,
.sep-hz {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.15;
  align-self: start;
}

.pair-hz {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--gold);
}

.pair-hear {
  max-width: 5.4rem;
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.05;
  text-align: center;
  color: var(--copper);
}

.pair-hz.is-faint .pair-hear { color: var(--muted); }

.pair-hz.is-over { color: var(--copper); }
.pair-hz.is-zero { color: var(--muted); }

.total-block { text-align: center; margin-top: 4px; }

.total-num {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.15rem, 8vw, 3.4rem);
  line-height: 0.9;
  color: var(--gold-2);
  font-variant-numeric: tabular-nums;
}

.hz-unit {
  font-size: 0.42em;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.meta-line, .pyth {
  margin: 2px 0 0;
  color: var(--cream-soft);
}

.pyth { font-family: var(--serif); font-size: 1.02rem; }

.total-block.is-on .total-num { text-shadow: 0 0 28px rgba(215, 185, 138, 0.35); }

.digit-note {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 8px;
}

.digit-line, .digit-skip {
  margin: 0;
  font-family: var(--serif);
}

.digit-line {
  color: var(--cream);
  font-size: 0.98rem;
}

.digit-skip {
  width: 100%;
  color: var(--muted);
  font-size: 0.82rem;
}

.above-note { color: var(--copper); }

.stats { margin: 0; }

.stats div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(215, 185, 138, 0.12);
}

.stats div:last-child { border-bottom: 0; }

.stats dt { color: var(--cream-soft); font-weight: 400; }

.stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--gold-2);
}

.tip-stack {
  position: fixed;
  z-index: 21;
  left: 50%;
  bottom: calc(62px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(1120px, calc(100% - 16px));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hear-tip {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 16px;
  background: #243026;
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}

.hear-tip p {
  margin: 0;
  flex: 1;
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--cream-soft);
}

.hear-tip button {
  flex: none;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--gold-2);
  padding: 0 12px;
}

.dock {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(1120px, calc(100% - 12px));
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(16, 20, 14, 0.94);
  border: 1px solid var(--line-strong);
  border-top-color: rgba(196, 92, 106, 0.55);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.35);
}

.transport { margin: 0; }

.dock .status {
  flex: 1;
  margin: 0;
  min-height: 0;
  font-size: 0.86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#play, #stop {
  min-width: 44px;
  min-height: 46px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  padding: 0 22px;
  font-weight: 600;
}

#play {
  background: #3c5340;
  color: var(--gold-2);
  border-color: rgba(196, 92, 106, 0.72);
  flex: 1;
}

#stop {
  background: transparent;
  color: var(--cream);
}

body.is-playing #play { box-shadow: 0 0 0 6px rgba(215, 185, 138, 0.14); }

.status { color: var(--sage); font-weight: 600; }

.field { margin: 14px 0; }

.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8, 10, 8, 0.35);
}

.seg button {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--cream-soft);
  padding: 0 8px;
}

.seg button[aria-pressed="true"] {
  background: #2c382c;
  color: var(--gold-2);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.seg.wrap { flex-wrap: wrap; border-radius: 16px; }

.seg.wrap button { flex: 1 1 40%; }

.slider-row { margin: 12px 0; }

.slider-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 2px;
}

.slider-label span { color: var(--gold); font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 36px;
  background: transparent;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: rgba(215, 185, 138, 0.4);
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--gold-2);
  border: 2px solid var(--sage-deep);
}

input[type="range"]::-moz-range-track {
  height: 2px;
  background: rgba(215, 185, 138, 0.4);
  border-radius: 999px;
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gold-2);
  border: 2px solid var(--sage-deep);
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid rgba(215, 185, 138, 0.1);
}

.toggle-row p { margin: 2px 0 0; }

.switch {
  position: relative;
  width: 64px;
  height: 44px;
  flex: none;
  border: 0;
  padding: 0;
  background: transparent;
}

.switch::before {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  top: 8px;
  bottom: 8px;
  border-radius: 999px;
  background: #121610;
  border: 1px solid var(--line);
}

.switch::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  top: 11px;
  inset-inline-start: 10px;
  border-radius: 50%;
  background: var(--cream-soft);
}

.switch[aria-checked="true"]::before {
  background: #3d5340;
  border-color: rgba(183, 203, 176, 0.55);
}

.switch[aria-checked="true"]::after {
  transform: translateX(22px);
  background: var(--gold-2);
}

html[dir="rtl"] .switch[aria-checked="true"]::after {
  transform: translateX(-22px);
}

.wave-wrap { margin: 8px 0 4px; }

canvas#wave {
  width: 100%;
  height: 72px;
  display: block;
}

.exact { margin: 0; color: var(--cream-soft); }

.exact strong {
  color: var(--gold-2);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.actions { display: flex; gap: 8px; margin-top: 14px; }

.actions .solid, .actions .ghost { flex: 1; }

.history-list { list-style: none; margin: 0; padding: 0; }

.history-item {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(215, 185, 138, 0.12);
}

.history-item:last-child { border-bottom: 0; }

.history-load {
  flex: 1;
  text-align: start;
  border: 0;
  background: transparent;
  padding: 4px 0;
  min-height: 44px;
}

.history-load strong {
  display: block;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.history-load span, .history-empty { color: var(--muted); font-size: 0.92rem; }

.icon-x {
  width: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 1.3rem;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 26px 8px 8px;
}

.footer p { margin: 0; }

.footer .credit {
  margin-top: 4px;
  letter-spacing: 0.08em;
}

.footer .read {
  margin-top: 8px;
  letter-spacing: 0;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 0.72rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.footer a {
  color: var(--rose-gold);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  width: min(520px, 100%);
  max-height: none;
  margin: auto auto 0;
}

dialog::backdrop { background: rgba(6, 8, 6, 0.72); }

.sheet {
  max-height: min(92vh, 860px);
  overflow: auto;
  background: #1a2018;
  border: 1px solid var(--line-strong);
  border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.sheet h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.8rem;
  color: var(--gold-2);
}

.choice { margin-top: 16px; padding-top: 12px; border-top: 1px solid rgba(215, 185, 138, 0.14); }

.choice h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--gold-2);
}

.about-body p { margin: 0 0 12px; color: var(--cream-soft); }

.about-body p:first-child { font-family: var(--serif); font-size: 1.15rem; color: var(--cream); }

#share-status { min-height: 1.3em; }

@media (min-width: 720px) {
  dialog { margin: auto; }
  .sheet { border-radius: 22px; }
}

@media (min-width: 960px) {
  .columns {
    grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.9fr);
    align-items: start;
  }
  .player-card { position: sticky; top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .switch::after { transition: none; }
}
