:root {
  color-scheme: dark;
  --paper: #0e0f11;
  --paper-2: #151619;
  --ink: #f0ece3;
  --ink-2: #9c988e;
  --ink-3: #605e58;
  --rule: rgba(240, 236, 227, .13);
  --rule-strong: rgba(240, 236, 227, .26);
  --accent: #d9634a;
  --accent-soft: rgba(217, 99, 74, .1);
  --error: #e0796a;
  --warn: #d9b06a;
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0; overflow: hidden;
  background: var(--paper);
  background-image: radial-gradient(900px 520px at 76% 28%, rgba(217, 99, 74, .055), transparent 72%);
  color: var(--ink);
  font: 14px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: rgba(217, 99, 74, .18);
}

button, .track, .lyric-line, .version a { -webkit-tap-highlight-color: rgba(217, 99, 74, .18); }
.track, .lyric-line, .version, .status, #footer-source, .brand-sub {
  user-select: none; -webkit-user-select: none;
}

.app { height: 100%; display: flex; flex-direction: column; }

.masthead {
  display: flex; align-items: center; justify-content: space-between; gap: 24px; flex: none;
  padding: 18px 34px; border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: baseline; gap: 18px; min-width: 0; }
.brand-mark { font: 15px var(--serif); letter-spacing: .22em; white-space: nowrap; }
.brand-sub { font: 10px var(--mono); letter-spacing: .1em; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source { display: flex; align-items: center; gap: 12px; min-width: 0; }
.source label { font: 10px var(--mono); letter-spacing: .2em; color: var(--ink-3); }
.source input {
  width: min(36vw, 360px); min-width: 0; padding: 7px 2px;
  border: 0; border-bottom: 1px solid var(--rule-strong); border-radius: 0;
  background: transparent; color: var(--ink); font: 12px var(--mono);
}
.source input::placeholder { color: var(--ink-3); }
.source input:focus { outline: none; border-bottom-color: var(--accent); }
.icon-btn {
  display: grid; place-items: center; width: 30px; height: 30px; padding: 0;
  border: 0; background: none; color: var(--ink-2); cursor: pointer; text-decoration: none;
}
.icon-btn svg {
  width: 17px; height: 17px; fill: none; stroke: currentColor;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn .dot { fill: currentColor; stroke: none; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }

.stage-tabs { display: none; }

.stage {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
}
.rail {
  display: flex; flex-direction: column; min-height: 0;
  padding: 30px 26px 20px 34px; border-right: 1px solid var(--rule);
}
.now { display: flex; gap: 18px; align-items: flex-start; }
.cover-frame {
  position: relative; width: 104px; height: 104px; flex: none;
  border: 1px solid var(--rule-strong); background: var(--paper-2); overflow: hidden;
}
.cover-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-fallback {
  position: absolute; inset: 0; display: grid; place-items: center;
  font: 10px var(--mono); letter-spacing: .1em; color: var(--ink-3);
}
.now-text { min-width: 0; }
.kicker { margin: 0 0 10px; font: 10px var(--mono); letter-spacing: .22em; color: var(--accent); }
.now-text h1 {
  margin: 0 0 10px; font: 400 21px/1.4 var(--serif); letter-spacing: .02em;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.now-text p:not(.kicker) { margin: 0 0 3px; font-size: 11px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#track-album { color: var(--ink-3); }
.rule { height: 1px; background: var(--rule); margin: 26px 0 16px; }
.list-head {
  display: flex; justify-content: space-between; gap: 10px; padding-bottom: 10px;
  font: 10px var(--mono); letter-spacing: .18em; color: var(--ink-3);
}
.track-list { flex: 1; min-height: 0; overflow: hidden auto; margin: 0; padding: 0; list-style: none; }
.track {
  position: relative; display: grid; grid-template-columns: 42px minmax(0, 1fr) 40px;
  gap: 12px; align-items: center; padding: 8px 0;
  border-bottom: 1px solid var(--rule); cursor: pointer;
}
.track-body { min-width: 0; overflow: hidden; }
.track.active { background: linear-gradient(90deg, var(--accent-soft), transparent 75%); }
.track.active::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 2px; background: var(--accent); }
.thumb {
  position: relative; width: 42px; height: 42px;
  background: var(--paper-2); border: 1px solid var(--rule); overflow: hidden;
}
.track-thumb {
  width: 100%; height: 100%; object-fit: cover; display: block;
  filter: saturate(.82) brightness(.82); transition: filter .25s ease;
}
.track.active .track-thumb { filter: none; }
.track.active .thumb { border-color: var(--accent); }
.track-time { font: 10px var(--mono); color: var(--ink-3); text-align: right; }
.track-name { font-size: 12.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-sub { margin-top: 2px; font-size: 10px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track.active .track-time { color: var(--accent); }
.track.active .track-name { color: var(--ink); }
.version { padding-top: 12px; font: 10px var(--mono); }
.version:empty { display: none; }
.version a { color: var(--ink-3); text-decoration: none; border-bottom: 1px solid var(--rule-strong); }

.lyrics-stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage-head {
  display: flex; align-items: center; gap: 18px; flex: none; flex-wrap: wrap;
  padding: 22px 34px 16px; border-bottom: 1px solid var(--rule);
}
.stage-head .kicker { margin: 0; }
#lyrics-state {
  font: 10px var(--mono); letter-spacing: .08em; color: var(--ink-3);
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.follow-btn {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: auto; padding: 5px 11px;
  border: 1px solid var(--accent); background: transparent;
  color: var(--accent); font: 10px var(--mono); letter-spacing: .08em; cursor: pointer;
}
.follow-btn svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }

.lyrics {
  position: relative; flex: 1; min-height: 0; overflow: hidden auto;
  padding: 26vh 6% 40vh; scroll-behavior: auto;
}
.lyric-line {
  position: relative; margin: 0; padding: .32em 0 .32em .8em;
  font: 400 clamp(26px, 2.65vw, 40px)/1.75 var(--serif); letter-spacing: .02em;
  color: var(--ink-3); opacity: .6; cursor: pointer; overflow-wrap: break-word;
  transition: color .35s ease, opacity .35s ease;
}
.lyric-line.active { color: var(--ink); opacity: 1; }
.lyric-line.active::before {
  content: ''; position: absolute; left: 0; top: .68em; bottom: .68em;
  width: 2px; background: var(--accent);
}
.lyric-time {
  position: absolute; right: 1%; top: 50%; transform: translateY(-50%);
  font: 10px var(--mono); color: var(--ink-3); opacity: 0; transition: opacity .2s ease;
}

.status {
  min-height: 30px; flex: none; padding: 8px 34px;
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  font: 10.5px/1.4 var(--mono); letter-spacing: .05em; color: var(--ink-3);
}
.status.error { color: var(--error); }
.status.warn { color: var(--warn); }

.transport { flex: none; padding: 14px 34px 18px; display: flex; flex-direction: column; gap: 12px; }
.progress { display: flex; align-items: center; gap: 14px; }
.progress span { min-width: 38px; font: 10px var(--mono); color: var(--ink-2); }
.progress span:last-child { text-align: right; }
input[type=range] {
  -webkit-appearance: none; appearance: none; height: 2px; flex: 1; min-width: 0;
  border-radius: 0; cursor: pointer;
  background-color: transparent;
  background-image:
    linear-gradient(to right, var(--accent) 0 var(--p, 0%), transparent var(--p, 0%)),
    linear-gradient(to right, var(--rule-strong) 0 var(--buffered, 0%), var(--rule) var(--buffered, 0%) 100%);
  background-repeat: no-repeat;
  background-size: 100% 2px;
  background-position: 0 center;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 2px; border-radius: 0; background: transparent;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 9px; height: 9px; margin-top: -3.5px; border-radius: 50%;
  background: var(--accent); border: none;
}
input[type=range]::-moz-range-track { height: 2px; border: none; background: transparent; }
input[type=range]::-moz-range-thumb {
  width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: none;
}
.control-row { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.controls { display: flex; align-items: center; gap: 16px; }
.ctrl {
  width: 34px; height: 34px; padding: 0; display: grid; place-items: center;
  border: 1px solid transparent; background: none; color: var(--ink-2); cursor: pointer;
}
.ctrl svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.ctrl-main { width: 42px; height: 42px; border: 1px solid var(--rule-strong); border-radius: 50%; color: var(--ink); }
#toggle svg { display: none; }
#toggle[data-state="paused"] .ico-play,
#toggle[data-state="playing"] .ico-pause,
#toggle[data-state="loading"] .ico-loading { display: block; }
#toggle[data-state="loading"] { border-color: var(--accent); color: var(--accent); }
#toggle[data-state="loading"] .ico-loading { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  #toggle[data-state="loading"] .ico-loading { animation: none; }
}
.extras { display: flex; align-items: center; gap: 18px; margin-left: auto; flex-wrap: wrap; }
#repeat { width: 34px; height: 34px; }
#repeat svg { display: none; }
#repeat[data-mode="0"] .mode-0,
#repeat[data-mode="1"] .mode-1,
#repeat[data-mode="2"] .mode-2 { display: block; }
.volume { display: flex; align-items: center; gap: 8px; }
.volume svg {
  width: 16px; height: 16px; flex: none; fill: none; stroke: var(--ink-2);
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}
.volume input { width: 84px; flex: none; }
#footer-source {
  max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 10px var(--mono); color: var(--ink-3);
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: var(--rule-strong); }
::-webkit-scrollbar-track { background: transparent; }

/* 悬停反馈只在真正支持悬停的设备生效，避免触屏上 hover 粘滞 */
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { color: var(--accent); }
  .track:hover .track-thumb { filter: saturate(.95) brightness(.95); }
  .track:hover .track-name { color: var(--ink); }
  .version a:hover { color: var(--accent); border-bottom-color: var(--accent); }
  .follow-btn:hover { background: var(--accent-soft); }
  .lyric-line:hover { color: var(--ink-2); opacity: .9; }
  .lyric-line:hover .lyric-time { opacity: 1; }
  .ctrl:hover { color: var(--ink); }
  .ctrl-main:hover { border-color: var(--accent); color: var(--accent); }
}

/* 触屏：点按给瞬时反馈 */
@media (hover: none) {
  .icon-btn:active, .ctrl:active, .ctrl-main:active { color: var(--accent); }
  .track:active .track-name { color: var(--ink); }
  .lyric-line:active { color: var(--ink-2); opacity: .9; }
}

/* 触屏：放大命中区，输入框字号提到 16px 以避免 iOS 聚焦时自动放大整页 */
@media (pointer: coarse) {
  input[type=range] { height: 26px; }
  input[type=range]::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -9px; }
  input[type=range]::-moz-range-thumb { width: 20px; height: 20px; }
  .icon-btn { width: 40px; height: 40px; }
  .ctrl { width: 42px; height: 42px; }
  .ctrl-main { width: 50px; height: 50px; }
  #repeat { width: 42px; height: 42px; }
  .follow-btn { min-height: 40px; padding: 8px 14px; }
  .source input { min-height: 40px; font-size: 16px; }
}

/* 窄屏一律给进度条留出可拖动的命中区 */
@media (max-width: 1000px) {
  input[type=range] { height: 26px; }
  input[type=range]::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -9px; }
  input[type=range]::-moz-range-thumb { width: 20px; height: 20px; }
}

/* 窄屏：整页不滚动，歌词与歌单各自成面板，播放条固定在底部 */
@media (max-width: 1000px) {
  body { overflow: hidden; overflow-x: hidden; }
  .app { height: 100vh; height: 100dvh; }
  .stage { grid-template-columns: 1fr; }
  .app[data-tab="lyrics"] .rail { display: none; }
  .app[data-tab="list"] .lyrics-stage { display: none; }

  .stage-tabs {
    display: flex; flex: none; gap: 6px; padding: 8px 22px;
    border-bottom: 1px solid var(--rule);
  }
  .stage-tab {
    flex: 1; padding: 11px 0; border: 0; background: none;
    color: var(--ink-3); font: 11px var(--mono); letter-spacing: .18em; cursor: pointer;
  }
  .stage-tab[aria-selected="true"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }

  .masthead, .status, .transport, .stage-head {
    padding-left: calc(22px + env(safe-area-inset-left, 0px));
    padding-right: calc(22px + env(safe-area-inset-right, 0px));
  }
  .masthead { padding-top: calc(12px + env(safe-area-inset-top, 0px)); padding-bottom: 12px; }
  .transport { padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }

  .lyrics-stage { order: 1; height: auto; min-height: 0; }
  .rail { order: 2; border-right: 0; border-top: 1px solid var(--rule); padding: 20px 22px; }
  .lyrics { padding: 18px 6% 28px; }
  .track-list { max-height: none; }
}

@media (max-width: 620px) {
  .masthead { flex-direction: column; align-items: stretch; gap: 10px; }
  .source input { width: 100%; flex: 1; font-size: 16px; }
  .lyric-line { font-size: 25px; }
  .lyric-time { display: none; }
  .extras { gap: 12px; }
  .now-text h1 { font-size: 18px; }
  .now { gap: 12px; }
  .cover-frame { width: 76px; height: 76px; }
  .track { grid-template-columns: 36px minmax(0, 1fr) 38px; gap: 10px; }
}
