:root {
  --bg: #0b0f14;
  --panel: #121922;
  --panel2: #1a2430;
  --panel3: #22303f;
  --line: #263241;
  --text: #eef3f8;
  --muted: #93a3b5;
  --accent: #3ddc97;
  --accent-ink: #062016;
  --blue: #4aa8ff;
  --warn: #ffb547;
  --danger: #ff6b6b;
  --radius: 22px;
  --tap: 72px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 500 20px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
input, textarea { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
[hidden] { display: none !important; }

.i { width: 1em; height: 1em; fill: currentColor; flex: none; }

/* ---------- Shell ---------- */
#app {
  display: grid;
  grid-template-columns: 116px 1fr;
  grid-template-rows: 1fr auto;
  height: 100vh; height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
main { position: relative; overflow: hidden; min-width: 0; }
.view { height: 100%; overflow-y: auto; padding: 20px 24px 24px; }

.rail {
  grid-row: 1 / 3;
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  padding: 12px 10px;
  background: var(--panel); border-right: 1px solid var(--line);
}
.rail-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 92px; border-radius: 20px;
  color: var(--muted); font-size: 15px; font-weight: 600;
}
.rail-btn .i { font-size: 38px; }
.rail-btn[aria-current="page"] { background: var(--panel3); color: var(--text); }
.rail-btn:active { background: var(--panel3); }
.rail-spacer { flex: 1; }

.net-chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 13px; font-weight: 700; padding: 8px 0 10px; color: var(--muted);
}
.net-chip .i { font-size: 28px; }
.net-chip.online .i { color: var(--accent); }
.net-chip.offline .i { color: var(--warn); }

.mic-btn {
  width: 96px; height: 96px; border-radius: 50%; align-self: center;
  display: grid; place-items: center;
  background: var(--blue); color: #001a33;
  box-shadow: 0 6px 24px #0008;
  position: relative;
}
.mic-btn .i { font-size: 46px; }
.mic-btn:active { transform: scale(.96); }
.mic-btn.handsfree { background: var(--accent); color: var(--accent-ink); }
.mic-btn.handsfree::after {
  content: ""; position: absolute; inset: -7px; border-radius: 50%;
  border: 3px solid var(--accent); opacity: .55; animation: ring 2.4s ease-out infinite;
}
.mic-btn.listening { background: var(--danger); color: #2a0000; }
.mic-btn.loading { background: var(--panel3); color: var(--muted); }
.mic-btn.unavailable { background: var(--panel3); color: var(--muted); }
@keyframes ring { 0% { transform: scale(.92); opacity: .7 } 100% { transform: scale(1.25); opacity: 0 } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: var(--tap); padding: 0 26px; border-radius: 18px;
  background: var(--panel3); font-weight: 700; font-size: 20px;
}
.btn .i { font-size: 30px; }
.btn:active { filter: brightness(1.2); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-danger { background: #3a1a1e; color: var(--danger); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 20px; border-radius: 999px; background: #000a; font-weight: 700; font-size: 18px;
}
.pill .i { font-size: 24px; }

.ctrl {
  width: 88px; height: 88px; border-radius: 50%;
  display: grid; place-items: center; background: var(--panel2);
}
.ctrl .i { font-size: 46px; }
.ctrl:active { background: var(--panel3); }
.ctrl-main { width: 124px; height: 124px; background: var(--text); color: var(--bg); }
.ctrl-main .i { font-size: 64px; }
.ctrl-main:active { background: #cfd8e2; }
.ctrl-sm {
  width: 72px; height: 72px; border-radius: 20px; display: grid; place-items: center;
  color: var(--muted); position: relative;
}
.ctrl-sm .i { font-size: 34px; }
.ctrl-sm[aria-pressed="true"] { color: var(--accent); background: #3ddc9718; }
.ctrl-sm:active { background: var(--panel2); }
.repeat-one {
  position: absolute; right: 12px; bottom: 10px; font-size: 13px;
  background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 0 4px;
}

/* ---------- Now Playing ---------- */
.view-now {
  display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 32px; align-items: center; padding: 24px 32px;
}
.stage {
  position: relative; width: 100%; aspect-ratio: 1; max-height: calc(100dvh - 64px);
  border-radius: 28px; overflow: hidden; background: var(--panel);
  display: grid; place-items: center;
}
.stage.video-visible { aspect-ratio: 16 / 9; background: #000; }
.art {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: radial-gradient(circle at 30% 25%, hsl(var(--h, 200) 70% 45%), hsl(calc(var(--h, 200) + 40) 60% 18%));
  background-size: cover; background-position: center;
}
.art .i { font-size: 38%; width: 38%; height: 38%; opacity: .85; }
.art.has-img .i { display: none; }
#media { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; display: none; }
.stage.video-visible #media { display: block; }
.stage.video-visible .art { display: none; }
.show-video { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); }
.stage.video-visible .show-video { display: none !important; }

.np-info { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.np-title { font-size: clamp(30px, 4.2vw, 52px); font-weight: 800; line-height: 1.1;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.np-sub { font-size: clamp(20px, 2.2vw, 28px); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.progress { padding: 18px 0 8px; cursor: pointer; touch-action: none; }
.progress-track { height: 12px; border-radius: 6px; background: var(--panel3); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 6px; }
.times { display: flex; justify-content: space-between; color: var(--muted); font-size: 18px; font-variant-numeric: tabular-nums; }

.controls { display: flex; align-items: center; justify-content: center; gap: 36px; margin-top: 8px; }
.sub-controls { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.vol { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; }
.vol-label { width: 52px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; font-size: 22px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; flex: 1; min-width: 60px; height: 56px; background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 12px; border-radius: 6px;
  background: linear-gradient(to right, var(--accent) var(--fill, 50%), var(--panel3) var(--fill, 50%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 40px; height: 40px; margin-top: -14px; border-radius: 50%;
  background: var(--text); box-shadow: 0 2px 8px #0008;
}
input[type="range"]::-moz-range-track { height: 12px; border-radius: 6px; background: var(--panel3); }
input[type="range"]::-moz-range-progress { height: 12px; border-radius: 6px; background: var(--accent); }
input[type="range"]::-moz-range-thumb { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--text); }

/* ---------- Library ---------- */
.lib-top { display: flex; gap: 14px; align-items: center; position: sticky; top: -20px; background: var(--bg); padding: 4px 0 10px; z-index: 2; }
.search {
  flex: 1; display: flex; align-items: center; gap: 12px;
  height: var(--tap); padding: 0 20px; border-radius: 18px; background: var(--panel2);
}
.search .i { font-size: 32px; color: var(--muted); }
.search input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent;
  color: var(--text); font: inherit; font-size: 22px;
}
.chips { display: flex; gap: 10px; padding: 4px 0 14px; overflow-x: auto; scrollbar-width: none; }
.chip {
  flex: none; min-height: 56px; padding: 0 22px; border-radius: 999px;
  background: var(--panel2); color: var(--muted); font-weight: 700; font-size: 18px;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 16px;
  min-height: 88px; padding: 8px 8px 8px 10px; border-radius: 20px; background: var(--panel);
  cursor: pointer;
}
.row:active { background: var(--panel2); }
.row.current { background: #3ddc9714; box-shadow: inset 4px 0 0 var(--accent); }
.row.unavail { opacity: .45; }
.tile {
  flex: none; width: 68px; height: 68px; border-radius: 16px; display: grid; place-items: center;
  background: linear-gradient(135deg, hsl(var(--h, 200) 65% 42%), hsl(calc(var(--h, 200) + 40) 55% 22%));
  background-size: cover; background-position: center;
}
.tile .i { font-size: 34px; opacity: .9; }
.meta { flex: 1; min-width: 0; }
.meta .t { font-size: 22px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta .s { font-size: 17px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.badge {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 700; padding: 6px 12px; border-radius: 999px;
  background: var(--panel3); color: var(--muted);
}
.badge .i { font-size: 18px; }
.badge.local { color: var(--accent); background: #3ddc9718; }
.icon-btn { flex: none; width: 72px; height: 72px; border-radius: 18px; display: grid; place-items: center; color: var(--muted); }
.icon-btn .i { font-size: 32px; }
.icon-btn:active { background: var(--panel3); }
.icon-btn .pct { font-size: 16px; font-weight: 800; color: var(--blue); }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 28px; margin: 0 0 8px; }
.empty .btn { margin: 18px 6px 0; }
.more { margin: 12px auto; display: flex; }

/* ---------- Mini player ---------- */
.mini {
  grid-column: 2; display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; background: var(--panel); border-top: 1px solid var(--line);
}
.mini-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; text-align: left; min-height: 80px; }
.mini-tile { width: 64px; height: 64px; border-radius: 14px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, hsl(var(--h, 200) 65% 42%), hsl(calc(var(--h, 200) + 40) 55% 22%)); background-size: cover; }
.mini-tile .i { font-size: 30px; }
.mini-text { min-width: 0; display: flex; flex-direction: column; }
.mini-text b { font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-text small { font-size: 16px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini .ctrl { width: 76px; height: 76px; }
.mini .ctrl .i { font-size: 40px; }

/* ---------- Settings ---------- */
.settings { max-width: 980px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; padding-bottom: 40px; }
.settings h1 { font-size: 34px; margin: 4px 0 4px; }
.card { background: var(--panel); border-radius: var(--radius); padding: 22px 24px; display: flex; flex-direction: column; gap: 16px; }
.card h2 { margin: 0; font-size: 26px; display: flex; align-items: center; gap: 12px; }
.card h2 .i { font-size: 32px; color: var(--blue); }
.card p, .hint { margin: 0; color: var(--muted); font-size: 18px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: var(--tap); }
.setting > div:first-child { min-width: 0; }
.setting .label { font-size: 21px; font-weight: 700; }
.setting .desc { font-size: 16px; color: var(--muted); margin-top: 2px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; background: var(--panel2); padding: 6px; border-radius: 18px; }
.seg button { min-height: 60px; padding: 0 18px; border-radius: 14px; color: var(--muted); font-weight: 700; font-size: 18px; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.switch {
  flex: none; width: 92px; height: 52px; border-radius: 999px; background: var(--panel3); position: relative;
}
.switch::after {
  content: ""; position: absolute; top: 6px; left: 6px; width: 40px; height: 40px; border-radius: 50%;
  background: var(--muted); transition: transform .15s, background .15s;
}
.switch[aria-checked="true"] { background: #3ddc9740; }
.switch[aria-checked="true"]::after { transform: translateX(40px); background: var(--accent); }
.text-input {
  width: 100%; min-height: 60px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font: inherit; font-size: 18px;
}
.row-inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-inline .text-input { flex: 1; min-width: 220px; }

.addon { display: flex; align-items: center; gap: 18px; padding: 16px 18px; border-radius: 18px; background: var(--panel2); flex-wrap: wrap; }
.addon .info { flex: 1; min-width: 220px; }
.addon .name { font-size: 21px; font-weight: 800; }
.addon .status { font-size: 16px; color: var(--muted); margin-top: 4px; }
.addon .status.ok { color: var(--accent); }
.addon .status.err { color: var(--danger); }
.bar { height: 10px; border-radius: 5px; background: var(--panel3); overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; width: 0; background: var(--blue); transition: width .2s; }
details summary { cursor: pointer; color: var(--muted); font-size: 17px; min-height: 44px; display: flex; align-items: center; }
.cheats { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.cheats div { background: var(--panel2); border-radius: 14px; padding: 12px 14px; font-size: 17px; }
.cheats b { display: block; color: var(--text); }
.cheats span { color: var(--muted); }

/* ---------- Files ---------- */
.files { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; padding-bottom: 32px; }
.files-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.files-title { min-width: 0; }
.files h1 { font-size: 34px; margin: 4px 0 2px; }
.storage-bar { height: 12px; border-radius: 6px; background: var(--panel3); overflow: hidden; }
.storage-bar > i { display: block; height: 100%; min-width: 4px; background: linear-gradient(90deg, var(--accent), var(--blue)); }
.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 16px 18px; border-radius: 18px; background: #ffb54714; border: 1px solid #ffb54755;
}
.notice b { color: var(--warn); font-size: 20px; }
.files .chips { padding: 0; }
.chip-gap { flex: none; width: 1px; margin: 8px 6px; background: var(--line); }
.bulk {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px; border-radius: 18px; background: var(--panel2); position: sticky; top: -20px; z-index: 2;
}
.bulk-count { flex: 1; font-weight: 700; font-size: 20px; min-width: 140px; }
.file-row.selected { background: #4aa8ff1f; box-shadow: inset 0 0 0 2px var(--blue); }
.checkbox {
  flex: none; width: 44px; height: 44px; border-radius: 12px; border: 3px solid var(--muted);
  display: grid; place-items: center; color: #001a33;
}
.checkbox[aria-checked="true"] { background: var(--blue); border-color: var(--blue); }
.checkbox .i { font-size: 30px; }
.file-facts { flex: none; display: flex; flex-direction: column; align-items: flex-end; font-size: 15px; color: var(--muted); min-width: 92px; }
.file-facts b { color: var(--text); font-size: 18px; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; font-size: 18px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; user-select: text; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-actions .btn { width: 100%; justify-content: center; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 17px; }
@media (max-width: 760px) {
  .file-facts, .file-row .badge { display: none; }
  .sheet-actions { grid-template-columns: 1fr; }
}

/* ---------- Microphone prompt ---------- */
.mic-hero {
  width: 96px; height: 96px; border-radius: 50%; margin: 4px auto 0; display: grid; place-items: center;
  background: var(--blue); color: #001a33;
}
.mic-hero .i { font-size: 52px; }
.mic-hero.blocked { background: var(--danger); color: #2a0000; }
.modal b { color: var(--text); }

/* ---------- Voice overlay ---------- */
.voice-overlay {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom)) 134px;
  background: linear-gradient(to top, #000d, #0000); pointer-events: none;
}
.voice-card {
  pointer-events: auto; display: flex; align-items: center; gap: 20px;
  background: var(--panel2); border: 2px solid var(--blue); border-radius: 28px; padding: 16px 18px;
  box-shadow: 0 10px 40px #000a;
}
.voice-pulse { width: 76px; height: 76px; border-radius: 50%; background: var(--danger); color: #2a0000; display: grid; place-items: center; flex: none; animation: pulse 1.2s ease-in-out infinite; }
.voice-pulse .i { font-size: 40px; }
.voice-overlay.loading .voice-pulse { background: var(--panel3); color: var(--muted); }
@keyframes pulse { 50% { transform: scale(1.08); } }
.voice-text { flex: 1; min-width: 0; }
.voice-state { font-size: 18px; color: var(--muted); font-weight: 700; }
.voice-partial { font-size: 28px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Toasts & modal ---------- */
.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: none; width: min(720px, calc(100vw - 32px)); }
.toast {
  background: var(--text); color: var(--bg); font-weight: 700; font-size: 21px;
  padding: 16px 24px; border-radius: 18px; box-shadow: 0 8px 30px #0009; text-align: center;
  animation: toastIn .18s ease-out;
}
.toast.err { background: var(--danger); color: #2a0000; }
@keyframes toastIn { from { transform: translateY(-12px); opacity: 0 } }

dialog {
  border: 0; border-radius: 28px; padding: 0; background: var(--panel); color: var(--text);
  width: min(680px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
}
dialog::backdrop { background: #000b; }
.modal { padding: 26px; display: flex; flex-direction: column; gap: 16px; }
.modal h2 { margin: 0; font-size: 28px; }
.modal p { margin: 0; color: var(--muted); }
.modal .btn { width: 100%; justify-content: flex-start; }
.modal .actions { display: flex; gap: 12px; justify-content: flex-end; }
.modal .actions .btn { width: auto; justify-content: center; }

/* ---------- Portrait / small screens ---------- */
@media (orientation: portrait), (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr auto auto; }
  .rail {
    grid-row: 3; flex-direction: row; justify-content: space-around; align-items: center;
    border-right: 0; border-top: 1px solid var(--line); padding: 6px 8px;
  }
  .rail-btn { flex: 1; min-height: 76px; }
  .rail-spacer, .net-chip { display: none; }
  .mic-btn { width: 84px; height: 84px; order: 2; margin-top: -24px; flex: none; }
  .rail-btn[data-view="files"] { order: 3; }
  .rail-btn[data-view="settings"] { order: 4; }
  .rail-btn span { font-size: 13px; }
  .mini { grid-column: 1; grid-row: 2; }
  .view-now { grid-template-columns: 1fr; align-content: start; gap: 18px; padding: 16px; }
  .stage { max-height: 42dvh; aspect-ratio: auto; height: 42dvh; }
  .controls { gap: 24px; }
  .sub-controls { flex-wrap: wrap; justify-content: center; }
  .vol { flex: 1 1 100%; order: 2; }
  .voice-overlay { padding-left: 18px; bottom: 96px; }
  .view { padding: 16px; }
}
@media (max-height: 640px) and (orientation: landscape) {
  .rail { gap: 4px; padding: 8px; }
  .rail-btn { min-height: 76px; }
  .rail-btn .i { font-size: 32px; }
  .net-chip { padding: 4px 0 6px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .ctrl-main { width: 104px; height: 104px; }
  .ctrl { width: 76px; height: 76px; }
  .rail-btn { min-height: 74px; }
  .mic-btn { width: 84px; height: 84px; }
}
