:root {
  color-scheme: light;
  --ink: #172431;
  --muted: #617183;
  --navy: #15304a;
  --navy-2: #214867;
  --teal: #1f716d;
  --teal-soft: #e6f2f0;
  --gold: #a26d18;
  --paper: #f4f1ea;
  --surface: #fffefa;
  --surface-2: #f8f7f3;
  --line: #d7d9d5;
  --line-strong: #b7bec1;
  --danger: #9f3f39;
  --success: #2f7662;
  --shadow: 0 18px 48px rgba(28, 42, 53, .10);
  --radius: 18px;
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px clamp(18px, 4vw, 52px);
  background: rgba(244, 241, 234, .96);
  border-bottom: 1px solid rgba(23, 36, 49, .10);
  backdrop-filter: blur(12px);
}

.brand { display: grid; gap: 2px; }
.brand-kicker, .eyebrow {
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.brand strong { font-size: clamp(17px, 2vw, 22px); }
.header-actions { display: flex; gap: 8px; }

.app-shell {
  width: min(1480px, calc(100% - 28px));
  margin: 0 auto;
  padding: clamp(22px, 4vw, 48px) 0 64px;
}

.login-shell, .dashboard, .reader-layout, .completion-card {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr);
  gap: clamp(24px, 5vw, 72px);
  align-items: center;
  min-height: 60vh;
}
.hero-copy h1 { margin: 10px 0 18px; font-size: clamp(36px, 5vw, 64px); line-height: 1.06; letter-spacing: -.03em; }
.hero-copy p { max-width: 720px; margin: 0; color: var(--muted); font-size: clamp(17px, 2vw, 21px); line-height: 1.8; }
.hero-note { margin-top: 22px; padding-left: 15px; border-left: 3px solid var(--teal); color: var(--navy); line-height: 1.7; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-card { padding: clamp(22px, 4vw, 38px); }
.login-card h2 { margin: 6px 0 8px; font-size: 24px; }
.login-card p { color: var(--muted); line-height: 1.65; }
.form-grid { display: grid; gap: 16px; margin-top: 22px; }
.field { display: grid; gap: 7px; }
.field label { font-weight: 750; }
.field small { color: var(--muted); }
.field input, .field select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(31, 113, 109, .13); }
.error-text { min-height: 1.4em; margin: 6px 0 0; color: var(--danger); font-weight: 700; }

.button-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.primary-button, .secondary-button, .ghost-button, .danger-button, .icon-button {
  border-radius: 11px;
  border: 1px solid transparent;
  min-height: 44px;
  padding: 10px 15px;
  font-weight: 800;
}
.primary-button { background: var(--navy); color: #fff; }
.primary-button:hover { background: var(--navy-2); }
.primary-button:disabled { opacity: .38; cursor: not-allowed; }
.secondary-button { background: var(--teal-soft); color: #195d59; border-color: #b8d8d4; }
.ghost-button { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.danger-button { background: #fff3f1; border-color: #e6b7b1; color: var(--danger); }
.icon-button { width: 42px; padding: 0; background: transparent; border-color: var(--line); font-size: 24px; }

.profile-list { display: grid; gap: 10px; margin: 18px 0; }
.profile-card {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}
.profile-card strong { display: block; }
.profile-card small { color: var(--muted); }

.reader-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}
.reader-topbar h1 { margin: 6px 0 3px; font-size: clamp(27px, 3.5vw, 42px); }
.reader-topbar p { margin: 0; color: var(--muted); }
.autosave { display: flex; align-items: center; gap: 7px; color: var(--success); font-size: 13px; font-weight: 800; white-space: nowrap; }
.autosave::before { content: ""; width: 8px; height: 8px; border-radius: 99px; background: var(--success); }

.progress-wrap { display: grid; gap: 8px; margin: 16px 0 22px; }
.progress-meta { display: flex; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 14px; }
.progress-track { height: 8px; overflow: hidden; border-radius: 99px; background: #dde1df; }
.progress-bar { height: 100%; width: 0; background: var(--teal); transition: width .2s ease; }

.phase-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 18px 0 26px; }
.phase-card {
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
}
.phase-card.active { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(31, 113, 109, .10); }
.phase-card.locked { opacity: .52; cursor: not-allowed; }
.phase-card strong { display: block; margin-bottom: 4px; }
.phase-card span { color: var(--muted); font-size: 14px; }

.rating-stage, .pair-stage {
  display: grid;
  gap: 18px;
}
.image-panel { padding: 12px; overflow: hidden; }
.image-toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 4px 4px 12px; }
.image-code { font-weight: 850; letter-spacing: .04em; }
.image-hint { color: var(--muted); font-size: 13px; }
.mpi-image {
  display: block;
  width: 100%;
  max-height: 75vh;
  object-fit: contain;
  background: #0a0a0a;
  border-radius: 10px;
  cursor: zoom-in;
}

.score-panel { padding: clamp(18px, 3vw, 28px); }
.score-intro { margin-bottom: 12px; color: var(--muted); line-height: 1.65; }
.score-block { padding: 17px 0; border-top: 1px solid var(--line); }
.score-block:first-of-type { border-top: 0; }
.score-head { display: flex; gap: 14px; justify-content: space-between; align-items: flex-start; margin-bottom: 11px; }
.score-head strong { font-size: 17px; }
.score-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.score-options { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.score-options.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.score-option input { position: absolute; opacity: 0; pointer-events: none; }
.score-option label {
  display: grid;
  align-content: center;
  gap: 3px;
  min-height: 64px;
  padding: 8px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: #fff;
  text-align: center;
  transition: .14s ease;
}
.score-option label strong { font-size: 18px; }
.score-option label span { font-size: 12px; color: var(--muted); line-height: 1.3; }
.score-option input:checked + label { border-color: var(--teal); background: var(--teal-soft); box-shadow: 0 0 0 2px rgba(31, 113, 109, .12); }
.score-option input:focus-visible + label { outline: 3px solid rgba(31, 113, 109, .24); outline-offset: 2px; }

.reader-actions {
  position: sticky;
  bottom: 10px;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  padding: 12px;
  border: 1px solid rgba(183, 190, 193, .8);
  border-radius: 14px;
  background: rgba(255, 254, 250, .95);
  box-shadow: 0 14px 35px rgba(28, 42, 53, .12);
  backdrop-filter: blur(10px);
}

.pair-images { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.pair-image-card { padding: 10px; }
.pair-label { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 3px 5px 10px; }
.pair-label strong { font-size: 22px; }
.pair-label span { color: var(--muted); font-size: 12px; }
.pair-image-card .mpi-image { max-height: 56vh; }
.pair-choice { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.pair-choice input { position: absolute; opacity: 0; }
.pair-choice label { display: grid; min-height: 62px; place-items: center; padding: 10px; border: 1px solid var(--line-strong); border-radius: 11px; background: #fff; font-weight: 800; text-align: center; }
.pair-choice input:checked + label { border-color: var(--teal); background: var(--teal-soft); box-shadow: 0 0 0 2px rgba(31, 113, 109, .12); }

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dashboard-card { padding: 24px; }
.dashboard-card h2 { margin: 6px 0 8px; }
.dashboard-card p { color: var(--muted); line-height: 1.7; }
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.stat { min-width: 120px; padding: 13px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.stat strong { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 13px; }

.completion-card { padding: clamp(24px, 5vw, 46px); text-align: center; }
.completion-card h1 { margin: 8px 0 12px; font-size: clamp(30px, 5vw, 54px); }
.completion-card p { max-width: 720px; margin: 0 auto 22px; color: var(--muted); line-height: 1.75; }

.dialog { border: 0; padding: 0; background: transparent; max-width: none; max-height: none; }
.dialog::backdrop { background: rgba(11, 19, 26, .72); }
.dialog-card { width: min(900px, calc(100vw - 28px)); max-height: calc(100vh - 40px); overflow: auto; padding: clamp(20px, 4vw, 34px); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.dialog-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.dialog-title-row h2 { margin: 5px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 20px; }
.rubric-table { width: 100%; border-collapse: collapse; margin: 18px 0 26px; font-size: 14px; }
.rubric-table th, .rubric-table td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; line-height: 1.55; }
.rubric-table th { background: var(--surface-2); }
.guide-section h3 { margin: 24px 0 8px; }
.guide-section p, .guide-section li { color: #425365; line-height: 1.75; }

.zoom-shell { position: relative; width: 100vw; height: 100vh; margin: 0; padding: 30px; display: grid; place-items: center; background: #090c0f; }
.zoom-shell img { max-width: 100%; max-height: 100%; object-fit: contain; }
.zoom-close { position: fixed; top: 14px; right: 16px; z-index: 2; width: 46px; height: 46px; border: 1px solid rgba(255,255,255,.35); border-radius: 99px; background: rgba(0,0,0,.55); color: #fff; font-size: 27px; }

@media (min-width: 1100px) {
  .rating-stage {
    grid-template-columns: minmax(0, 1.2fr) minmax(430px, .8fr);
    align-items: start;
  }
  .rating-stage .image-panel {
    position: sticky;
    top: 88px;
  }
  .rating-stage .mpi-image {
    max-height: calc(100vh - 170px);
  }
  .rating-stage .reader-actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 840px) {
  .hero { grid-template-columns: 1fr; min-height: auto; }
  .hero-copy h1 { font-size: 42px; }
  .dashboard-grid, .pair-images { grid-template-columns: 1fr; }
  .reader-topbar { grid-template-columns: 1fr; align-items: start; }
  .phase-nav { grid-template-columns: 1fr; }
  .pair-image-card .mpi-image { max-height: 48vh; }
}

@media (max-width: 620px) {
  .site-header { align-items: flex-start; padding: 10px 12px; }
  .brand-kicker { display: none; }
  .brand strong { font-size: 16px; }
  .header-actions { gap: 5px; }
  .ghost-button { padding: 8px 10px; min-height: 38px; font-size: 13px; }
  .app-shell { width: min(100% - 16px, 1480px); padding-top: 18px; }
  .score-options { grid-template-columns: repeat(5, minmax(56px, 1fr)); overflow-x: auto; padding-bottom: 3px; }
  .score-option label { min-width: 56px; }
  .score-head { display: block; }
  .reader-actions { bottom: 6px; }
  .reader-actions .secondary-button, .reader-actions .primary-button { flex: 1; }
  .progress-meta { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
