/* 唱一下 v0.3。主題「晚上的小舞台」：墨藍、米白、珊瑚橘三色（審美錨點規則 5）。
   頁面是米白紙，舞台永遠是暗的，只有現在要做的事有聚光（規則 9、1）。
   標題和夥伴說的話用霞鶩文楷（手寫感、可愛不幼稚，規則 3、10），內文思源黑體。 */
:root {
  --paper: #F3ECDF; --card: #FBF7EF; --ink: #1E2238; --ink-2: #4A4F66; --muted: #5C6177;
  --line: #E1D7C5; --line-strong: #C9BDA7; --accent: #E9774A; --accent-ink: #A34B26;
  --on-ink: #F7F1E6; --on-accent: #2A140A;
  --stage-top: #1A1F35; --stage-bot: #2B3152; --stage-floor: #232845; --stage-text: rgba(243, 236, 223, .55);
  --glow: rgba(255, 236, 205, .2); --target: #F3ECDF; --you: #F08A5D; --star: #F3ECDF;
  --slab: rgba(243, 236, 223, .09); --slab-edge: rgba(243, 236, 223, .55);
  --display: 'LXGW WenKai TC', 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', serif;
  --sans: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #11152A; --card: #1A1F36; --ink: #F1EADC; --ink-2: #B9B4A8; --muted: #A3A6B8;
    --line: #2C3250; --line-strong: #414870; --accent: #F08A5D; --accent-ink: #F4A47F;
    --on-ink: #11152A; --stage-top: #161A2E; --stage-bot: #242A48; --stage-floor: #1E2340;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #11152A; --card: #1A1F36; --ink: #F1EADC; --ink-2: #B9B4A8; --muted: #A3A6B8;
  --line: #2C3250; --line-strong: #414870; --accent: #F08A5D; --accent-ink: #F4A47F;
  --on-ink: #11152A; --stage-top: #161A2E; --stage-bot: #242A48; --stage-floor: #1E2340;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.65; -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
.app { max-width: 560px; margin: 0 auto; padding: 8px 16px 32px; padding-top: max(8px, env(safe-area-inset-top)); }
p { margin: 0; }

/* 標題列 */
.topbar { display: flex; align-items: center; gap: 10px; min-height: 56px; }
.brand { flex: 1; display: grid; line-height: 1.2; }
.brand-name { font-family: var(--display); font-weight: 700; font-size: 24px; letter-spacing: .06em; }
.brand-sub { font-size: 12px; color: var(--muted); }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line); font-size: 26px; line-height: 1; cursor: pointer; }
.chip { border: 0; border-radius: 999px; background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-strong); padding: 6px 14px; font-size: 14px; min-height: 36px; cursor: pointer; color: var(--ink-2); }
main { display: block; }
main > section { display: grid; gap: 14px; animation: rise .28s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 文字 */
.display { font-family: var(--display); font-weight: 700; font-size: 28px; line-height: 1.35; margin: 4px 0 0; letter-spacing: .02em; text-wrap: balance; }
.display.big { font-size: 32px; }
.kicker { font-size: 13px; font-weight: 700; color: var(--accent-ink); letter-spacing: .08em; }
.muted { color: var(--muted); }
.fine { font-size: 13px; color: var(--muted); line-height: 1.6; }
.center { text-align: center; }
.note { background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: inset 0 0 0 1.5px var(--line); }
/* 手寫感的底線（小巧思；不是漸層字） */
.mark { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 10' preserveAspectRatio='none'%3E%3Cpath d='M2 7 C 20 2, 40 9, 60 5 S 100 3, 118 6' fill='none' stroke='%23E9774A' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") left bottom / 100% 9px no-repeat; padding-bottom: 4px; }

/* 按鈕：平面、沒有反光（規則 4） */
.btn { appearance: none; border: 0; border-radius: 16px; min-height: 52px; padding: 12px 20px; font-family: var(--sans); font-weight: 700; font-size: 17px; letter-spacing: .03em; cursor: pointer; transition: transform .08s ease, opacity .15s; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn.primary { background: var(--ink); color: var(--on-ink); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line-strong); }
.btn.warm { background: var(--accent); color: var(--on-accent); }
.btn.big { width: 100%; min-height: 60px; font-size: 19px; }
.btn[disabled] { opacity: .4; cursor: default; transform: none; }
.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible, .mode:focus-visible, .buddy:focus-visible, .link:focus-visible, .seg button:focus-visible, summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions .btn { flex: 1 1 130px; }
.actions.tri .btn { flex: 1 1 64px; padding-inline: 10px; }
.actions.tri .btn:first-child { flex: 2 1 120px; }
.link { position: relative; border: 0; background: none; padding: 4px 2px; color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: inherit; }
.link::after { content: ''; position: absolute; inset: -9px -6px; } /* 點擊範圍加大，版面不變 */

/* 舞台 */
.stagewrap { position: relative; border-radius: 22px; overflow: hidden; background: var(--stage-top); box-shadow: inset 0 0 0 1px rgba(243, 236, 223, .06), 0 14px 30px -20px rgba(20, 24, 45, .55); }
canvas.stage { display: block; width: 100%; height: min(46vh, 340px); touch-action: none; }
canvas.stage.short { height: 150px; }
canvas.stage.hero { height: 190px; }
.pill { position: absolute; top: 10px; left: 12px; background: rgba(243, 236, 223, .14); color: #F3ECDF; font-family: var(--display); font-size: 15px; padding: 2px 12px; border-radius: 999px; pointer-events: none; }
.pill:empty { display: none; }
.hud { position: absolute; left: 12px; right: 12px; top: 10px; display: flex; justify-content: space-between; gap: 8px; pointer-events: none; }
.hud .pill { position: static; }
.stagewrap.hero .say { position: absolute; right: 14px; top: 18px; max-width: 58%; background: #F3ECDF; color: #1E2238; font-family: var(--display); font-size: 17px; padding: 6px 12px; border-radius: 14px 14px 4px 14px; }

/* 夥伴的對話泡泡：提示融進畫面（規則 9） */
.bubble { text-wrap: pretty; position: relative; background: var(--card); border-radius: 18px; padding: 14px 16px; font-family: var(--display); font-size: 20px; line-height: 1.5; box-shadow: inset 0 0 0 1.5px var(--line); margin-top: 6px; min-height: 60px; }
.bubble::before { content: ''; position: absolute; top: -7px; left: 34px; width: 14px; height: 14px; background: var(--card); transform: rotate(45deg); box-shadow: -1.5px -1.5px 0 0 var(--line); border-radius: 2px 0 0 0; }
.bubble.pop { animation: pop .22s ease-out; }
@keyframes pop { from { transform: scale(.97); } to { transform: scale(1); } }

/* 進度：先唱 ●● ｜練習 ●●● ｜不看提示 ●● */
.progress { display: grid; grid-template-columns: 2fr 3fr 2fr; gap: 12px; }
.pg { display: grid; gap: 5px; font-size: 12px; color: var(--muted); }
.pg.on { color: var(--ink); font-weight: 700; }
.dots { display: flex; gap: 4px; }
.dots i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.dots i.done { background: var(--ink-2); opacity: .55; }
.dots i.now { background: var(--accent); }

/* 首頁 */
.buddies { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.buddy { position: relative; border: 0; border-radius: 16px; background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line); padding: 10px 6px 8px; display: grid; justify-items: center; gap: 2px; font-family: var(--display); font-size: 16px; cursor: pointer; }
.buddy img { width: 50px; height: 50px; object-fit: contain; }
.buddy[aria-checked="true"] { box-shadow: inset 0 0 0 2.5px var(--ink); }
.buddy[aria-checked="true"]::after { content: '✦'; position: absolute; top: 4px; right: 10px; color: var(--accent); font-size: 14px; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.mode { display: grid; gap: 3px; text-align: left; border: 0; border-radius: 18px; padding: 14px; background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line); cursor: pointer; align-content: start; }
.mode .tag { font-size: 12px; font-weight: 700; color: var(--accent-ink); letter-spacing: .08em; }
.mode b { font-family: var(--display); font-size: 20px; line-height: 1.3; }
.mode small { font-size: 13px; color: var(--muted); line-height: 1.5; }

/* 收音條 */
.meter { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 5px; transition: width .1s; }

/* 挑戰關難度 */
.seg { display: flex; gap: 4px; background: var(--card); border-radius: 14px; padding: 4px; box-shadow: inset 0 0 0 1.5px var(--line); }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 8px; min-height: 40px; font-family: var(--display); font-size: 17px; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }

/* 結果 */
.bars { display: grid; gap: 8px; background: var(--card); border-radius: 16px; padding: 14px; box-shadow: inset 0 0 0 1.5px var(--line); }
.bar { display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 10px; font-size: 14px; }
.bar i { display: block; height: 12px; border-radius: 6px; background: var(--ink-2); opacity: .45; }
.bar.you i { background: var(--accent); opacity: 1; }
.self { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.self legend { font-size: 15px; margin-bottom: 4px; padding: 0; }
.self label { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }
input[type="radio"] { accent-color: var(--accent); width: 18px; height: 18px; }
details { background: var(--card); border-radius: 14px; padding: 4px 14px; box-shadow: inset 0 0 0 1.5px var(--line); }
details > *:not(summary) { margin: 8px 0; }
summary { cursor: pointer; min-height: 40px; padding: 8px 0; font-size: 15px; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
td, th { text-align: left; border-bottom: 1px solid var(--line); padding: 6px; white-space: nowrap; }
textarea { width: 100%; min-height: 80px; border: 0; border-radius: 10px; padding: 10px; background: var(--paper); box-shadow: inset 0 0 0 1.5px var(--line); resize: vertical; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--paper); border-radius: 10px; padding: 10px; font-size: 11px; max-height: 260px; overflow: auto; }
.card.error { background: var(--card); border-radius: 16px; padding: 14px 16px; box-shadow: inset 0 0 0 1.5px var(--line), inset 4px 0 0 var(--accent); }

.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--on-ink); padding: 10px 16px; border-radius: 14px; font-size: 15px; max-width: calc(100% - 32px); z-index: 5; }
footer { margin-top: 28px; text-align: center; font-size: 12px; color: var(--muted); line-height: 1.7; }

/* 測試頁 */
.pass { color: #2E6B4F; } .fail { color: #A34B26; }
.test-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.test-detail { font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }

@media (min-width: 720px) { canvas.stage { height: 360px; } .display.big { font-size: 36px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
