/* Liquid-glass style: content runs edge to edge under floating translucent bars. */
:root {
  --bg: #f4efe6; --bg-glow-1: #f9e2c4; --bg-glow-2: #d8eadf;
  --surface: #fffdf8; --surface-2: #ece5d7; --ink: #23221f; --muted: #6e695f; --line: rgba(60, 50, 30, .12);
  --accent: #2f6f5e; --accent-soft: rgba(47, 111, 94, .13); --on-accent: #fff; --danger: #b23b2b;
  --notice: #fff1cf; --notice-ink: #6d4c00;
  --glass-fill: rgba(255, 253, 248, .58); --glass-edge: rgba(255, 255, 255, .75); --glass-shade: rgba(70, 55, 30, .14);
  --safe-top: env(safe-area-inset-top); --safe-bottom: env(safe-area-inset-bottom);
  --nav-h: 52px; --tab-h: 64px; --dock-h: 156px; --float-gap: max(12px, var(--safe-bottom));
  --radius: 22px; --spring: cubic-bezier(.32, 1.25, .5, 1); --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121210; --bg-glow-1: #2c2416; --bg-glow-2: #12291f;
    --surface: #1e1d1b; --surface-2: #2a2926; --ink: #f1ede6; --muted: #a7a095; --line: rgba(255, 255, 255, .1);
    --accent: #82c9b0; --accent-soft: rgba(130, 201, 176, .16); --on-accent: #0e241c; --danger: #ff8f7e;
    --notice: #3a3120; --notice-ink: #f1d79a;
    --glass-fill: rgba(38, 37, 34, .55); --glass-edge: rgba(255, 255, 255, .14); --glass-shade: rgba(0, 0, 0, .45);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; color: var(--ink); font-size: 17px; line-height: 1.6; min-height: 100dvh; letter-spacing: -.01em;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(60vmax 50vmax at 0% 0%, var(--bg-glow-1), transparent 60%),
    radial-gradient(60vmax 50vmax at 100% 100%, var(--bg-glow-2), transparent 60%), var(--bg);
  background-attachment: fixed;
}
body.has-tabs { padding-bottom: calc(var(--tab-h) + var(--float-gap) + 24px); }
body.has-dock { padding-bottom: calc(var(--dock-h) + var(--float-gap) + 24px); }
html:has(body.has-tabs) { scroll-padding-bottom: calc(var(--tab-h) + var(--float-gap) + 24px); }
html:has(body.has-dock) { scroll-padding-bottom: calc(var(--dock-h) + var(--float-gap) + 24px); }
[hidden] { display: none !important; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h1, h2 { letter-spacing: -.02em; }
p { margin: .35rem 0; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: .95rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Glass material */
.glass, .glass-card, .glass-button, dialog {
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(28px) saturate(1.8); backdrop-filter: blur(28px) saturate(1.8);
  border: 1px solid var(--glass-edge);
  box-shadow: 0 10px 34px -8px var(--glass-shade), inset 0 1px 0 var(--glass-edge);
}
.glass-card { border-radius: var(--radius); padding: 14px; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass, .glass-card, .glass-button, dialog { background: var(--surface); }
}

/* Navigation: large title in content, compact glass bar once scrolled */
.nav {
  position: fixed; inset: 0 0 auto 0; z-index: 4; display: flex; align-items: center; gap: 8px;
  height: calc(var(--nav-h) + var(--safe-top)); padding: var(--safe-top) 12px 0;
  border-bottom: 1px solid transparent; transition: background-color .25s, border-color .25s;
}
body.scrolled .nav {
  background: var(--glass-fill); -webkit-backdrop-filter: blur(28px) saturate(1.8); backdrop-filter: blur(28px) saturate(1.8);
  border-bottom-color: var(--line);
}
.nav-title {
  position: absolute; left: 64px; right: 64px; text-align: center; font-weight: 600; font-size: 1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; transform: translateY(6px);
  transition: opacity .2s, transform .25s var(--ease);
}
body.scrolled .nav-title { opacity: 1; transform: none; }
.pane { padding: calc(var(--safe-top) + var(--nav-h)) 16px 28px; max-width: 640px; margin: 0 auto; }
.large-title { margin: 4px 4px 16px; }
.large-title h1 { font-size: 2.1rem; line-height: 1.15; font-weight: 750; margin: 0; }
.large-title .sub { margin: 4px 0 0; color: var(--muted); font-size: .92rem; }
#view-detail .large-title h1 { font-size: 1.75rem; }
.section { font-size: 1.15rem; margin: 28px 4px 10px; }
.banner {
  position: fixed; inset: 0 0 auto 0; z-index: 9; text-align: center; font-size: .88rem; padding: calc(var(--safe-top) + 6px) 16px 8px;
  background: var(--notice); color: var(--notice-ink);
}
.notice { background: var(--notice); color: var(--notice-ink); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.notice p { margin: .2rem 0 0; }

/* Controls */
button, .tabs a {
  font: inherit; color: inherit; min-height: 50px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  padding: 10px 20px; touch-action: manipulation; user-select: none; -webkit-user-select: none; cursor: pointer;
  transition: transform .35s var(--spring), background-color .2s, opacity .2s;
}
button:active:not(:disabled), .tabs a:active { transform: scale(.95); transition-duration: .1s; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.icon-button { min-width: 44px; min-height: 44px; padding: 0; display: inline-grid; place-items: center; border: none; background: transparent; position: relative; }
.glass-button { width: 44px; height: 44px; min-height: 44px; padding: 0; display: grid; place-items: center; border-radius: 50%; position: relative; z-index: 1; }
.text-danger { border: none; background: transparent; color: var(--danger); align-self: center; }
.text-link { color: var(--accent); text-align: center; font-size: .92rem; padding: 6px; }
input, textarea {
  font: inherit; font-size: max(16px, 1rem); width: 100%; padding: 13px 16px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); color: var(--ink); resize: none;
}
.stack { display: flex; flex-direction: column; gap: 10px; }
.glass-card textarea { border: none; padding: 4px; background: transparent; }
.glass-card textarea:focus-visible { outline: none; }
#note-form:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; } /* replaces the textarea's own ring */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-between button { min-height: 40px; padding: 6px 22px; }

/* Pair */
.pair { min-height: 100dvh; max-width: 420px; margin: 0 auto; padding: calc(var(--safe-top) + 64px) 24px 32px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pair img { border-radius: 22px; box-shadow: 0 12px 30px -10px var(--glass-shade); }
.pair h1 { font-size: 1.9rem; margin: 10px 0 0; font-weight: 750; }
.pair .lead { color: var(--muted); margin-bottom: 18px; }
.pair form { width: 100%; text-align: left; padding: 18px; }
.pair label { font-size: .88rem; color: var(--muted); padding-left: 4px; }
#pair-code { letter-spacing: .14em; text-transform: uppercase; text-align: center; font-size: 1.3rem; font-variant-numeric: tabular-nums; }

/* Install hint */
.install { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; margin-bottom: 16px; }
.install img { border-radius: 11px; }
.install p { margin: 2px 0 0; }
.install .close { margin: -8px -8px 0 0; color: var(--muted); }

.install-copy { margin-top: 8px; min-height: 36px; padding: 4px 16px; font-size: .88rem; background: var(--accent); color: var(--on-accent); border-color: transparent; }

/* Pull to refresh (home-screen mode only) */
.ptr {
  position: fixed; z-index: 6; left: 50%; top: calc(var(--safe-top) + 10px); width: 40px; height: 40px; margin-left: -20px; border-radius: 50%;
  display: grid; place-items: center; color: var(--accent); background: var(--surface); box-shadow: 0 6px 18px -6px var(--glass-shade);
  opacity: var(--pull, 0); transform: translateY(calc(var(--pull, 0) * 24px)) rotate(calc(var(--pull, 0) * 180deg));
}
.ptr svg { width: 20px; height: 20px; transition: transform .2s; }
.ptr.ready svg { transform: rotate(180deg); }
.ptr.loading { opacity: 1; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: translateY(24px) rotate(360deg); } }

/* List */
.group { margin: 22px 4px 8px; font-size: .82rem; font-weight: 600; color: var(--muted); text-transform: uppercase; }
.group:first-child { margin-top: 4px; }
.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.cards a {
  display: block; padding: 15px 16px; border-radius: var(--radius); color: inherit; text-decoration: none;
  background: var(--glass-fill); -webkit-backdrop-filter: blur(20px) saturate(1.6); backdrop-filter: blur(20px) saturate(1.6);
  border: 1px solid var(--glass-edge); box-shadow: 0 6px 22px -10px var(--glass-shade), inset 0 1px 0 var(--glass-edge);
  transition: transform .35s var(--spring);
}
.cards a:active { transform: scale(.975); transition-duration: .1s; }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head .when { font-weight: 650; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.card-head .duration { color: var(--muted); font-size: .86rem; font-variant-numeric: tabular-nums; }
.chev { margin-left: auto; color: var(--muted); width: 18px; height: 18px; }
.preview { margin: 6px 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tag { font-size: .76rem; padding: 1px 9px; border-radius: 999px; background: var(--notice); color: var(--notice-ink); white-space: nowrap; }
.skeleton { height: 96px; border-radius: var(--radius); margin-bottom: 10px; background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; opacity: .7; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 56px 12px; }
.empty-title { font-weight: 600; margin: 0; }

/* Detail */
.lines { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.lines button {
  width: 100%; text-align: left; display: flex; gap: 12px; align-items: baseline; background: transparent; border-color: transparent;
  padding: 11px 14px; border-radius: 18px; line-height: 1.7; font-size: 1.05rem; transition: background-color .3s, transform .35s var(--spring);
}
.lines .time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .8rem; flex: none; min-width: 2.6em; }
.lines button[aria-current="true"] { background: var(--accent-soft); }
.lines button[aria-current="true"] .time { color: var(--accent); font-weight: 650; }
.group-card { margin-top: 24px; padding: 4px 16px; }
.status-box summary { cursor: pointer; padding: 12px 0; font-size: .95rem; list-style: none; display: flex; justify-content: space-between; }
.status-box summary::after { content: "›"; color: var(--muted); transition: transform .3s var(--spring); }
.status-box[open] summary::after { transform: rotate(90deg); }
.status-box summary::-webkit-details-marker { display: none; }
.status { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 14px; font-size: .92rem; }
.status dt { color: var(--muted); }
.status dd { margin: 0; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }

/* Floating player */
.dock {
  position: fixed; left: 12px; right: 12px; bottom: var(--float-gap); z-index: 5; max-width: 560px; margin: 0 auto;
  border-radius: 30px; padding: 12px 20px 12px;
}
.dock.disabled { opacity: .5; pointer-events: none; }
.times { display: flex; justify-content: space-between; font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: -4px; padding: 0 2px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 30px; padding: 0; border: none; background: transparent; --fill: 0%;
}
input[type="range"]::-webkit-slider-runnable-track { height: 7px; border-radius: 4px; background: linear-gradient(to right, var(--accent) var(--fill), var(--line) var(--fill)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -8.5px; border-radius: 50%; background: #fff; border: none; box-shadow: 0 2px 8px rgba(0, 0, 0, .28); }
input[type="range"]::-moz-range-track { height: 7px; border-radius: 4px; background: var(--line); }
input[type="range"]::-moz-range-progress { height: 7px; border-radius: 4px; background: var(--accent); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: none; box-shadow: 0 2px 8px rgba(0, 0, 0, .28); }
.controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; max-width: 340px; margin: 2px auto 0; }
.controls #rewind { justify-self: start; }
.controls .badge { position: absolute; font-size: .55rem; font-weight: 700; margin-top: 1px; }
.play { width: 64px; height: 64px; padding: 0; border-radius: 50%; border: none; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; box-shadow: 0 8px 20px -6px var(--accent); }
.play svg { width: 28px; height: 28px; fill: currentColor; stroke: none; }
.play .icon-pause, .play.playing .icon-play { display: none; }
.play.playing .icon-pause { display: block; }
.speed { justify-self: end; min-height: 38px; min-width: 62px; padding: 4px 12px; font-weight: 650; font-variant-numeric: tabular-nums; background: transparent; }

/* Notes */
.notes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.notes li {
  padding: 13px 16px; border-radius: var(--radius); background: var(--glass-fill); border: 1px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.notes time { display: block; color: var(--muted); font-size: .78rem; }
.notes li.muted { background: transparent; border-style: dashed; border-color: var(--line); text-align: center; }

/* Floating tab bar: shrinks while scrolling down, like the system tab bar */
.tabs {
  position: fixed; z-index: 5; left: 50%; bottom: var(--float-gap); transform: translateX(-50%);
  width: min(360px, calc(100vw - 32px)); height: var(--tab-h); border-radius: 999px; padding: 6px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  transition: width .45s var(--spring), height .45s var(--spring);
}
.tabs a, .tabs button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 0; height: 100%;
  padding: 0 8px; border: none; border-radius: 999px; background: transparent; color: var(--ink); text-decoration: none; font-size: .7rem; font-weight: 550;
}
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.tabs span { transition: opacity .2s, max-height .3s var(--ease); max-height: 1.2em; overflow: hidden; }
.tabs.compact { width: min(200px, calc(100vw - 32px)); height: 50px; }
.tabs.compact span { opacity: 0; max-height: 0; }

/* Dialog and toast */
dialog { border-radius: 30px; padding: 24px 20px 16px; width: min(380px, calc(100vw - 32px)); color: var(--ink); background: var(--glass-fill); }
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { dialog { background: color-mix(in srgb, var(--surface) 78%, transparent); } }
dialog[open] { animation: pop .38s var(--spring); }
dialog::backdrop { background: rgba(0, 0, 0, .28); }
dialog h2 { margin: 0; font-size: 1.15rem; text-align: center; }
dialog p { text-align: center; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.dialog-actions button { background: var(--surface-2); border-color: transparent; }
.dialog-actions .danger { background: var(--danger); color: #fff; font-weight: 600; }
.dialog-actions .primary { background: var(--accent); }
@keyframes pop { from { opacity: 0; transform: scale(.9); } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 14px) scale(.96); } }
.toast {
  position: fixed; left: 50%; z-index: 10; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--float-gap) + 14px);
  max-width: calc(100vw - 32px); padding: 11px 20px; border-radius: 999px; font-size: .94rem; font-weight: 550; white-space: nowrap;
  animation: rise .4s var(--spring);
}
body.has-dock .toast { bottom: calc(var(--dock-h) + var(--float-gap) + 14px); }

/* Views fade and lift in each time they are shown (display toggling restarts the animation). */
.view:not([hidden]) .pane, .view:not([hidden]) .pair { animation: view-in .38s var(--ease); }
#view-detail:not([hidden]) .dock { animation: dock-in .5s var(--spring); }
@keyframes view-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes dock-in { from { opacity: 0; transform: translateY(40px) scale(.96); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Kept last so it wins over every glass rule above, including the scrolled nav, cards and the dialog. */
@media (prefers-reduced-transparency: reduce) {
  .glass, .glass-card, .glass-button, dialog, body.scrolled .nav, .cards a, .notes li, .dock, .tabs, .toast {
    background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none;
  }
}
