/*
 * 設計依據：ai/wiki/design/design-references.md
 * - mobile-native：去掉點擊閃光、輸入框 ≥16px、touch-action、100dvh、safe area、hover 只給滑鼠
 * - emil-design-eng：按下回饋 scale(0.97)、ease-out 自訂曲線、動畫 < 300ms、只動 transform 與 opacity
 * - 網路參考：淺米灰背景、大標題、大量留白、一個畫面一個主要按鈕
 */
* { box-sizing: border-box; }

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  background: var(--page);
}

body { margin: 0; background: var(--page); }

button, a, label, [role="button"] {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.shell {
  max-width: 440px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--page);
  display: flex;
  flex-direction: column;
}

@media (min-width: 480px) {
  .shell {
    min-height: calc(100dvh - 48px);
    margin: 24px auto;
    border: 1px solid var(--border);
    border-radius: 24px;
    overflow: hidden;
  }
}

main {
  flex: 1;
  padding: max(28px, env(safe-area-inset-top, 0px)) 22px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.proto-note {
  font-size: 12px;
  color: var(--faint);
  text-align: center;
  padding: 10px 16px max(14px, env(safe-area-inset-bottom, 0px));
}

h1, h2, h3, p { margin: 0; }

/* 換頁時進場：只在路由改變時播一次，勾選、輸入都不播（常用動作不動畫） */
main.enter > * {
  animation: enter 220ms var(--ease-out) both;
}
main.enter > *:nth-child(2) { animation-delay: 40ms; }
main.enter > *:nth-child(3) { animation-delay: 80ms; }
main.enter > *:nth-child(4) { animation-delay: 120ms; }
main.enter > *:nth-child(n + 5) { animation-delay: 160ms; }

@keyframes enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
}

.brand-name { font-size: 15px; font-weight: 700; letter-spacing: 0.02em; }

.page-title { font-size: 30px; font-weight: 800; line-height: 1.25; letter-spacing: 0.01em; }
.page-lead { color: var(--muted); font-size: 16px; }

.role-chev { color: var(--faint); flex: none; }

.role-evaluator { --role: var(--primary); --role-weak: var(--primary-weak); }

.back {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  padding: 6px 10px 6px 2px;
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}

.back:active { transform: scale(0.97); }

.role-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  font-size: 14px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--role-weak);
  color: var(--role);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 16px; font-weight: 700; }

.input {
  height: 54px;
  padding: 0 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 17px; /* ≥16px，iOS 才不會放大頁面 */
  color: inherit;
  background: var(--surface);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
.input[aria-invalid="true"] { border-color: var(--danger); }

.error { font-size: 15px; color: var(--danger); font-weight: 600; }

.btn {
  height: 56px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  transition: transform 160ms var(--ease-out), background-color 160ms ease;
}

.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-small { height: 40px; font-size: 15px; width: auto; padding: 0 14px; }

@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: var(--page); }
  .btn-primary:hover { background: var(--primary-hover); }
  .chip:hover { border-color: var(--faint); }
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--faint);
  font-size: 14px;
}

.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.hint {
  font-size: 14px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.hint code { font-family: inherit; font-weight: 800; color: var(--text); }

.scan-frame {
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  background: #1b2430;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.scan-box {
  position: relative;
  width: 62%;
  aspect-ratio: 1;
  border: 3px solid #ffffff;
  border-radius: 14px;
  overflow: hidden;
}

/* 掃描線：元素和框一樣高，只畫上緣，移動自己的高度（transform 才不會觸發重排） */
.scan-line {
  position: absolute;
  inset: 0;
  border-top: 2px solid #7fb2ff;
  animation: scan 1.8s cubic-bezier(0.77, 0, 0.175, 1) infinite alternate;
}

@keyframes scan {
  from { transform: translateY(0); }
  to { transform: translateY(calc(100% - 2px)); }
}

.scan-text {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  color: #d7dee8;
  font-size: 15px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.greet { font-size: 26px; font-weight: 800; line-height: 1.3; }

.card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-title { font-size: 15px; font-weight: 700; color: var(--muted); }

.kv-row { display: flex; gap: 28px; }
.kv { display: flex; flex-direction: column; gap: 2px; }
.kv-label { font-size: 13px; color: var(--muted); }
.kv-value { font-size: 18px; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }

select.input { appearance: auto; }

.chips { display: flex; flex-direction: column; gap: 8px; }

.chip {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-size: 17px;
  transition: transform 160ms var(--ease-out), border-color 160ms ease, background-color 160ms ease;
}

.chip:active { transform: scale(0.98); }
.chip input { width: 24px; height: 24px; accent-color: var(--primary); flex: none; }
.chip:has(input:checked) { border-color: var(--primary); background: var(--primary-weak); }
.chip:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }
.chip-text { flex: 1; font-weight: 700; }
.chip-sub { display: block; font-size: 14px; font-weight: 400; color: var(--muted); }

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--slate-weak);
  color: var(--slate);
  flex: none;
}

.badge-assigned { background: var(--primary); color: #fff; }

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
}

.notice svg { flex: none; margin-top: 2px; }
.notice-ok { background: var(--ok-weak); color: var(--ok); }
.notice-warn { background: var(--warn-weak); color: var(--warn); }
.notice-danger { background: var(--danger-weak); color: var(--danger); }

.scene-list { display: flex; flex-direction: column; gap: 10px; }
.scene-group-title { font-size: 14px; font-weight: 800; color: var(--muted); margin-top: 6px; }

.scene-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 17px;
  font-weight: 600;
}

.sticky-action {
  position: sticky;
  bottom: 0;
  padding: 12px 0 max(4px, env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to bottom, rgba(242, 241, 237, 0), var(--page) 30%);
}

.demo-bar {
  margin-top: auto;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--faint);
}

.demo-bar button {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
}

/* 減少動態：保留淡入淡出，拿掉位移與縮放 */
@media (prefers-reduced-motion: reduce) {
  main.enter > * { animation: fade 150ms ease-out both; animation-delay: 0ms !important; }
  .btn:active, .chip:active, .back:active { transform: none; }
  .scan-line { animation: none; transform: translateY(50%); }
}

/* ---------- 評分流程 ---------- */

/* 場景清單與評分畫面會來回很多次：只淡入，不位移、不依序出現 */
main.enter-quiet { animation: fade 120ms ease-out both; }

.ring { position: relative; display: inline-block; flex: none; }
.ring svg { display: block; transform: rotate(-90deg); }
.ring-track, .ring-bar { fill: none; stroke-width: 4; }
.ring-track { stroke: var(--border); }
.ring-bar {
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-dasharray: 100;
  transition: stroke-dashoffset 240ms var(--ease-out);
}

.progress-card {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}

.progress-num { font-size: 34px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.progress-num span { font-size: 20px; font-weight: 700; color: var(--muted); }
.progress-text { font-size: 14px; color: var(--muted); }

.stage-title { font-size: 14px; font-weight: 700; color: var(--primary); margin-top: 2px; }

.scene-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  padding: 10px 10px 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}

.scene-row:active { transform: scale(0.98); }
.scene-row:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.scene-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.scene-row-name { font-size: 17px; font-weight: 700; overflow-wrap: anywhere; }
.scene-row-sub { font-size: 13px; color: var(--muted); }

.badge-done { background: var(--ok-weak); color: var(--ok); }
.badge-draft { background: var(--warn-weak); color: var(--warn); }

.q-progress { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }

.scene-head { display: flex; flex-direction: column; gap: 4px; }
.scene-path { font-size: 14px; font-weight: 700; color: var(--muted); }

.q-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-margin: 16px;
}

.q-card.q-missing { border-color: var(--danger); }
.q-index { font-size: 14px; font-weight: 700; color: var(--muted); }
.q-text { font-size: 19px; font-weight: 700; line-height: 1.5; overflow-wrap: anywhere; }

.q-options { display: flex; flex-direction: column; gap: 8px; }
.score-row { display: grid; gap: 8px; }

/* 真正的 radio 只是看不見：鍵盤、螢幕報讀都照常。顏色只分「選了／沒選」，不用紅綠暗示分數好壞。 */
.score-btn input, .score-none input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.score-btn, .score-none {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition: transform 120ms var(--ease-out), background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.score-btn { min-height: 92px; padding: 8px 3px; gap: 2px; }
.score-btn:active, .score-none:active { transform: scale(0.97); }
.score-num { font-size: 30px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.score-label { font-size: 13px; line-height: 1.3; color: var(--muted); overflow-wrap: anywhere; transition: color 120ms ease; }

.score-none { min-height: 56px; padding: 7px 10px; border-style: dashed; justify-content: center; }
.score-none-label { font-size: 16px; font-weight: 700; }
.score-none-desc { font-size: 13px; color: var(--muted); transition: color 120ms ease; }

.score-btn:has(input:checked) { background: var(--primary); border-color: var(--primary); color: #fff; }
.score-btn:has(input:checked) .score-label { color: #fff; }
.score-none:has(input:checked) { background: var(--slate); border-color: var(--slate); border-style: solid; color: #fff; }
.score-none:has(input:checked) .score-none-desc { color: #fff; }
.score-btn:has(input:focus-visible), .score-none:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }

.comment-toggle {
  align-self: flex-start;
  min-height: 44px;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.comment-input { height: auto; min-height: 96px; padding: 12px 14px; line-height: 1.5; resize: vertical; }
[hidden] { display: none !important; }

.save-note { font-size: 14px; color: var(--muted); text-align: center; }

.btn:disabled { cursor: default; }
.btn:disabled:active { transform: none; }

.btn-sent, .btn-sent:disabled { background: var(--ok); border-color: var(--ok); color: #fff; }

.draw-check { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 220ms var(--ease-out) forwards; }

@keyframes draw { to { stroke-dashoffset: 0; } }

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  animation: spin 600ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.sticky-action .error { margin-bottom: 8px; }
.done-actions { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }

.done-mark {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--ok-weak);
  color: var(--ok);
  display: grid;
  place-items: center;
}

@media (hover: hover) and (pointer: fine) {
  .scene-row:hover, .score-btn:hover, .score-none:hover { border-color: var(--faint); }
  .score-btn:has(input:checked):hover { border-color: var(--primary); }
}

@media (prefers-reduced-motion: reduce) {
  main.enter-quiet { animation: fade 120ms ease-out both; }
  .scene-row:active, .score-btn:active, .score-none:active { transform: none; }
  .ring-bar { transition: none; }
  .draw-check { animation: none; stroke-dashoffset: 0; }
}
