:root {
  --bg: #f6f5fb;
  --card: #ffffff;
  --text: #1d1b2c;
  --muted: #6c6884;
  --line: #e4e1f0;
  --accent: #5b4bdb;
  --accent-soft: #ebe8ff;
  --target: #3b82f6;
  --ok: #16a34a;
  --warn: #f97316;
  --bad: #dc2626;
  --grid: #eceaf5;
  --roll-bg: #fbfaff;
  --wk: 34px;
  --bk: 22px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14131c; --card: #1f1d2b; --text: #ece9f8; --muted: #a29dbd; --line: #333047;
    --accent: #8b7cff; --accent-soft: #2b2650; --grid: #2a2839; --roll-bg: #191824;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14131c; --card: #1f1d2b; --text: #ece9f8; --muted: #a29dbd; --line: #333047;
  --accent: #8b7cff; --accent-soft: #2b2650; --grid: #2a2839; --roll-bg: #191824;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 16px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 14px; }

.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); flex: 1; }
.mic-state { color: var(--bad); font-size: 13px; }

main { max-width: 860px; margin: 0 auto; padding: 16px; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; text-align: center; padding: 8px 0 6px; font-size: 12px; color: var(--muted); text-decoration: none;
}
.tabs a span { display: block; font-size: 20px; line-height: 1.2; }
.tabs a.on { color: var(--accent); font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; }

button, .btn {
  font: inherit; border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600; touch-action: manipulation;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: var(--accent-soft); color: var(--accent); }
button.small { padding: 6px 12px; font-size: 14px; }
button.big { width: 100%; padding: 16px; font-size: 18px; }
button.danger { background: transparent; color: var(--bad); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

input[type="text"], input[type="password"], input[type="url"] {
  font: inherit; width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}

/* 音準表 */
.tuner { text-align: center; padding: 8px 0 4px; }
.tuner .note { font-size: 56px; font-weight: 800; line-height: 1.1; }
.tuner .letter { color: var(--muted); font-size: 16px; }
.tuner .verdict { font-size: 20px; font-weight: 700; min-height: 30px; margin-top: 6px; }
.tuner .target-line { color: var(--target); font-weight: 600; min-height: 24px; }
.meter { position: relative; height: 34px; margin: 12px auto 4px; max-width: 420px; }
.meter .scale { position: absolute; inset: 14px 0 auto; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--bad), var(--warn) 30%, var(--ok) 42%, var(--ok) 58%, var(--warn) 70%, var(--bad)); opacity: .35; }
.meter .center { position: absolute; left: 50%; top: 4px; bottom: 4px; width: 2px; background: var(--ok); }
.meter .needle { position: absolute; left: 50%; top: 0; width: 6px; height: 34px; margin-left: -3px;
  border-radius: 3px; background: var(--text); transition: left .08s linear; }
.meter-labels { display: flex; justify-content: space-between; max-width: 420px; margin: 0 auto; font-size: 12px; color: var(--muted); }
.v-ok { color: var(--ok); } .v-warn { color: var(--warn); } .v-bad { color: var(--bad); }

/* 鋼琴 */
.piano { overflow-x: auto; overflow-y: hidden; border-radius: 10px; border: 1px solid var(--line); background: #222;
  -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.piano-inner { position: relative; height: 130px; display: flex; }
.key { padding: 0; border-radius: 0 0 6px 6px; font-weight: 500; transition: background .06s; }
.key.white { flex: 0 0 var(--wk); height: 100%; background: #fff; color: #555; border: 1px solid #bbb;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center; padding-bottom: 6px; font-size: 10px; }
.key.white .lbl { font-size: 11px; }
.key.white b { font-size: 10px; color: var(--accent); }
.key.white i { font-size: 9px; font-style: normal; color: #999; }
.key.black { position: absolute; top: 0; width: var(--bk); height: 62%; background: #222; border: 1px solid #000; z-index: 2; }
.key.in-range.white { background: #f1efff; }
.key.target { background: var(--target) !important; color: #fff !important; }
.key.target b, .key.target i { color: #fff; }
.key.ok { background: var(--ok) !important; color: #fff !important; }
.key.user { background: var(--warn) !important; color: #fff !important; }
.key.pressed { filter: brightness(.85); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

canvas.roll { width: 100%; height: 240px; display: block; border-radius: 10px; background: var(--roll-bg); border: 1px solid var(--line); touch-action: pan-y; }

.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }

/* 歌曲清單 */
.song { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.song:first-child { border-top: 0; }
.song img { width: 88px; height: 50px; object-fit: cover; border-radius: 8px; background: var(--line); flex: none; }
.song .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.song a { text-decoration: none; color: inherit; }

/* 播放控制 */
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.keybox { display: flex; align-items: center; gap: 6px; background: var(--accent-soft); border-radius: 10px; padding: 4px; }
.keybox span { min-width: 54px; text-align: center; font-weight: 700; color: var(--accent); }
.keybox button { padding: 6px 12px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.chip { flex: none; padding: 6px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13px; border: 0; font-weight: 600; }
.chip.on { background: var(--accent); color: #fff; }
.chip.bad { background: #fde8e8; color: var(--bad); }
.now { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; margin: 8px 0; }
.now b { font-size: 18px; }

/* 報告 */
.score { font-size: 54px; font-weight: 800; color: var(--accent); line-height: 1; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.stats div { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.stats b { display: block; font-size: 20px; }
.stats span { font-size: 12px; color: var(--muted); }
.advice li { margin-bottom: 8px; }
.phrase-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; }
.overlay .card { max-width: 420px; width: 100%; }

.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1d1b2c; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 30; font-size: 14px; max-width: calc(100% - 32px); }

.ring { width: 120px; height: 120px; margin: 8px auto; }
.big-msg { font-size: 22px; font-weight: 700; text-align: center; margin: 8px 0; }
.steps { padding-left: 20px; margin: 0; }
.steps li { margin-bottom: 6px; }

@media (min-width: 700px) {
  :root { --wk: 40px; --bk: 26px; }
  canvas.roll { height: 300px; }
  .piano-inner { height: 150px; }
}

/* 歌詞 */
.lyr { text-align: center; margin: 10px 0 2px; }
.lyr .l1 { font-size: 22px; font-weight: 700; min-height: 33px; line-height: 1.5; }
.lyr .l2 { color: var(--muted); font-size: 15px; min-height: 23px; }
/* AI 建議 */
.ai-box { margin-top: 12px; padding: 14px; border-radius: 12px; background: var(--accent-soft); }
.ai-box h3 { margin-top: 12px; }
.ai-issue { background: var(--card); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.ai-issue p { margin: 4px 0 0; font-size: 15px; }
