:root {
  color-scheme: light;
  --navy: #17233e;
  --navy-2: #223458;
  --blue: #3266b1;
  --teal: #14958c;
  --orange: #dc7927;
  --red: #c3473d;
  --gold: #d9a727;
  --ink: #1f2937;
  --muted: #64748b;
  --line: #dbe2ec;
  --paper: #ffffff;
  --canvas: #f2f5f9;
  --soft-blue: #eaf1fb;
  --soft-teal: #e8f5f3;
  --soft-orange: #fbf0e6;
  --soft-red: #fbecec;
  --soft-gold: #fbf5dd;
  --shadow: 0 18px 45px rgba(23, 35, 62, 0.12);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(50, 102, 177, 0.11), transparent 28rem),
    linear-gradient(180deg, #f8fafc 0%, var(--canvas) 100%);
}

button, textarea, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 3px solid rgba(50, 102, 177, 0.35);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 99;
  padding: .75rem 1rem;
  color: white;
  background: var(--navy);
  border-radius: .5rem;
}
.skip-link:focus { top: 1rem; }

.topbar {
  height: 4.25rem;
  padding: 0 clamp(1rem, 4vw, 3rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  background: var(--navy);
  border-bottom: 4px solid var(--teal);
}

.brand { display: flex; align-items: center; gap: .65rem; font-weight: 800; letter-spacing: .01em; }
.brand-mark {
  display: grid; place-items: center;
  width: 2rem; height: 2rem;
  color: var(--navy); background: white;
  border-radius: .55rem;
}
.prototype-tag {
  margin-left: .25rem;
  padding: .25rem .55rem;
  font-size: .78rem;
  font-weight: 700;
  color: #dce7fa;
  border: 1px solid #536887;
  border-radius: 999px;
}

.text-button {
  padding: .45rem .75rem;
  color: white;
  background: transparent;
  border: 1px solid #7183a0;
  border-radius: .55rem;
}

main { width: min(1420px, 100%); margin: 0 auto; }
.view { padding: clamp(1.25rem, 4vw, 3rem); }

.setup-heading { max-width: 48rem; margin-bottom: 2rem; }
.eyebrow {
  margin: 0 0 .4rem;
  color: var(--teal);
  font-size: .85rem;
  font-weight: 850;
  letter-spacing: .12em;
  text-transform: uppercase;
}
h1, h2, p { text-wrap: pretty; }
h1 { margin: 0; color: var(--navy); font-size: clamp(2rem, 4vw, 3.25rem); line-height: 1.12; }
h2 { margin: 0; color: var(--navy); font-size: 1.2rem; line-height: 1.35; }
.setup-heading > p:last-child, .feedback-heading > p:last-child { color: var(--muted); font-size: 1.05rem; line-height: 1.75; }

.case-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.case-card {
  position: relative;
  min-height: 22rem;
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  text-align: left;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--role-color);
  border-radius: 1.2rem;
  box-shadow: 0 10px 24px rgba(23, 35, 62, .08);
  transition: transform .18s ease, box-shadow .18s ease;
}
.case-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.case-card[aria-pressed="true"] { box-shadow: 0 0 0 4px color-mix(in srgb, var(--role-color) 20%, transparent), var(--shadow); }
.case-card-top { display: flex; align-items: flex-start; justify-content: space-between; color: var(--role-color); font-weight: 850; }
.case-card-rank { font-size: 1.85rem; line-height: 1; }
.case-card-band { margin: 1.4rem -1.15rem 1.2rem; padding: .6rem 1rem; color: white; background: var(--role-color); font-weight: 800; }
.case-card-name { margin: 0 0 .25rem; color: var(--muted); font-size: .9rem; }
.case-card h3 { margin: 0 0 .8rem; color: var(--navy); font-size: 1.3rem; line-height: 1.35; }
.case-card-summary { margin: 0; color: #475569; line-height: 1.65; }
.case-card-lenses { margin-top: auto; padding-top: 1rem; color: var(--role-color); font-weight: 800; }

.session-settings {
  margin-top: 1.25rem;
  padding: 1.25rem;
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) auto auto auto;
  gap: 1.25rem;
  align-items: end;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: 0 8px 24px rgba(23, 35, 62, .06);
}
fieldset { margin: 0; padding: 0; border: 0; }
legend { margin-bottom: .45rem; color: var(--muted); font-size: .85rem; font-weight: 800; }
.segmented { display: flex; padding: .25rem; gap: .2rem; background: #eef2f7; border-radius: .7rem; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { padding: .55rem .7rem; min-width: 4.8rem; text-align: center; border-radius: .5rem; font-weight: 750; color: #506079; }
.segmented label:has(input:checked) { color: white; background: var(--navy); }

.primary-button, .secondary-button, .send-button {
  min-height: 2.8rem;
  padding: .7rem 1.1rem;
  border-radius: .7rem;
  border: 1px solid transparent;
  font-weight: 850;
}
.primary-button, .send-button { color: white; background: var(--teal); }
.primary-button:hover, .send-button:hover { background: #0f7f78; }
.primary-button:disabled { opacity: .45; cursor: not-allowed; }
.secondary-button { color: var(--navy); background: white; border-color: #aeb9ca; }
.secondary-button:hover { background: #f7f9fc; }

.practice-view { padding-top: 1.5rem; }
.practice-status { margin-bottom: 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.practice-status h1 { font-size: clamp(1.55rem, 3vw, 2.2rem); }
.status-actions { display: flex; align-items: center; gap: .75rem; }
.timer { min-width: 7rem; padding: .65rem .85rem; color: white; background: var(--navy); border-radius: .7rem; text-align: center; font-variant-numeric: tabular-nums; font-weight: 850; }

.practice-layout {
  min-height: calc(100vh - 10rem);
  display: grid;
  grid-template-columns: minmax(15rem, .78fr) minmax(24rem, 1.7fr) minmax(14rem, .7fr);
  gap: 1rem;
}
.scenario-panel, .conversation-panel, .evidence-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: 0 8px 24px rgba(23, 35, 62, .06);
}
.scenario-panel { padding: 1.25rem; border-top: 6px solid var(--blue); }
.mini-card-head { display: flex; justify-content: space-between; color: var(--blue); font-size: .85rem; font-weight: 850; }
.card-rank { font-size: 1.8rem; }
.card-type { display: inline-block; margin: 1rem 0 .8rem; padding: .35rem .6rem; color: white; background: var(--blue); border-radius: .35rem; font-size: .8rem; font-weight: 850; }
.card-type.gold { background: var(--gold); }
.scenario-panel > p:not(.card-type) { color: #475569; line-height: 1.7; }
.lens-row { margin: 1rem 0; display: flex; flex-wrap: wrap; gap: .45rem; }
.lens-chip { padding: .35rem .55rem; color: var(--navy); background: var(--soft-gold); border: 1px solid #ead780; border-radius: 999px; font-size: .84rem; font-weight: 800; }
.mission-box { margin-top: 1.2rem; padding: 1rem; display: grid; gap: .35rem; background: var(--soft-blue); border-radius: .75rem; }
.mission-box strong { color: var(--blue); }

.conversation-panel { min-height: 36rem; display: flex; flex-direction: column; overflow: hidden; }
.messages { flex: 1; min-height: 23rem; max-height: calc(100vh - 20rem); padding: 1.25rem; overflow-y: auto; }
.message { max-width: 84%; margin-bottom: 1rem; display: flex; gap: .65rem; align-items: flex-start; }
.message.user { margin-left: auto; flex-direction: row-reverse; }
.avatar { flex: 0 0 2rem; height: 2rem; display: grid; place-items: center; color: white; background: var(--teal); border-radius: 50%; font-size: .8rem; font-weight: 850; }
.message.user .avatar { background: var(--navy); }
.bubble { padding: .8rem 1rem; border-radius: .9rem; background: var(--soft-teal); line-height: 1.65; white-space: pre-wrap; }
.message.user .bubble { color: white; background: var(--navy-2); border-top-right-radius: .2rem; }
.message.candidate .bubble { border-top-left-radius: .2rem; }
.message-meta { margin-top: .25rem; color: var(--muted); font-size: .75rem; }
.message.thinking .bubble { display: flex; align-items: center; gap: .65rem; color: #526173; background: #eef6f5; }
.thinking-label { font-size: .86rem; font-weight: 750; }
.thinking-dots { display: inline-flex; gap: .24rem; align-items: center; }
.thinking-dots span { width: .38rem; height: .38rem; background: var(--teal); border-radius: 50%; animation: thinking-bounce 1.05s ease-in-out infinite; }
.thinking-dots span:nth-child(2) { animation-delay: .14s; }
.thinking-dots span:nth-child(3) { animation-delay: .28s; }
@keyframes thinking-bounce {
  0%, 60%, 100% { opacity: .35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-.22rem); }
}

.composer { padding: 1rem; border-top: 1px solid var(--line); background: #f8fafc; }
.composer > label { display: block; margin-bottom: .45rem; color: var(--navy); font-weight: 850; }
.composer-row { display: flex; gap: .6rem; align-items: stretch; }
textarea { width: 100%; min-height: 4rem; resize: vertical; padding: .75rem; color: var(--ink); background: white; border: 1px solid #aeb9ca; border-radius: .7rem; line-height: 1.5; }
.composer-help { margin: .45rem 0 0; color: var(--muted); font-size: .8rem; }

.evidence-panel { padding: 1.25rem; border-top: 6px solid var(--gold); }
.score-ring { width: 7.2rem; height: 7.2rem; margin: 1.4rem auto .7rem; display: grid; place-content: center; grid-template-columns: auto auto; align-items: baseline; color: var(--navy); background: conic-gradient(var(--gold) var(--score-angle, 0deg), #e9edf3 0); border-radius: 50%; box-shadow: inset 0 0 0 12px white; }
.score-ring strong { font-size: 2.6rem; line-height: 1; }
.score-ring span { color: var(--muted); font-weight: 800; }
#scoreLabel { text-align: center; color: var(--muted); font-weight: 800; }
.progress-track { height: .55rem; margin: 1rem 0; overflow: hidden; background: #e9edf3; border-radius: 999px; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--gold); transition: width .2s ease; }
.evidence-list { padding: 0; list-style: none; }
.evidence-list li { margin: .6rem 0; padding-left: 1.55rem; position: relative; color: #475569; line-height: 1.45; }
.evidence-list li::before { content: "○"; position: absolute; left: 0; color: #9aa7b9; }
.evidence-list li.done { color: var(--ink); font-weight: 700; }
.evidence-list li.done::before { content: "●"; color: var(--teal); }
.privacy-note { margin-top: 1rem; padding: .75rem; color: var(--muted); background: #f5f7fa; border-radius: .6rem; font-size: .8rem; line-height: 1.55; }

.feedback-view { max-width: 1100px; margin: 0 auto; }
.feedback-heading { margin-bottom: 1.5rem; }
.feedback-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.feedback-grid article, .rewrite-card { padding: 1.25rem; background: white; border: 1px solid var(--line); border-radius: 1rem; box-shadow: 0 8px 24px rgba(23,35,62,.06); }
.feedback-grid article ul { padding-left: 1.25rem; line-height: 1.75; }
.feedback-score-card { background: var(--navy) !important; color: white; }
.feedback-score-card h2 { color: white; }
.score-kicker { color: #bfd1ec; font-weight: 800; }
.big-score { margin: .7rem 0; }
.big-score strong { font-size: 4rem; }
.big-score span { color: #bfd1ec; font-size: 1.2rem; }
.risk-card { border-top: 5px solid var(--red) !important; }
.risk-pill { display: inline-block; margin: .25rem .25rem .25rem 0; padding: .4rem .55rem; color: #842c27; background: var(--soft-red); border-radius: 999px; font-size: .82rem; font-weight: 800; }
.rewrite-card { margin-top: 1rem; border-top: 5px solid var(--orange); }
.rewrite-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
.rewrite-columns span { color: var(--muted); font-size: .82rem; font-weight: 800; }
blockquote { margin: .45rem 0 0; padding: 1rem; min-height: 6rem; background: var(--soft-orange); border-left: 4px solid var(--orange); line-height: 1.65; }
.rewrite-columns > div:last-child blockquote { background: var(--soft-teal); border-color: var(--teal); }
.feedback-actions { margin-top: 1rem; display: flex; gap: .75rem; justify-content: flex-end; }

.loading-state { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; color: white; background: var(--navy); font-size: 1.1rem; font-weight: 800; }
.loading-state[hidden] { display: none; }

@media (max-width: 1080px) {
  .case-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .session-settings { grid-template-columns: 1fr 1fr; }
  .practice-layout { grid-template-columns: minmax(14rem, .72fr) 1.5fr; }
  .evidence-panel { grid-column: 1 / -1; display: grid; grid-template-columns: auto 8rem 1fr; gap: 1rem; align-items: center; }
  .evidence-panel .card-type, .evidence-panel h2, .evidence-panel .privacy-note { grid-column: 1 / -1; }
  .evidence-panel .score-ring { margin: 0; }
  .evidence-panel .progress-track { display: none; }
}

@media (max-width: 720px) {
  .prototype-tag { display: none; }
  .topbar { padding: 0 .9rem; }
  .view { padding: 1rem; }
  .case-grid, .feedback-grid, .rewrite-columns { grid-template-columns: 1fr; }
  .case-card { min-height: 18rem; }
  .session-settings { grid-template-columns: 1fr; }
  .practice-status { align-items: flex-start; flex-direction: column; }
  .status-actions { width: 100%; justify-content: space-between; }
  .practice-layout { grid-template-columns: 1fr; }
  .scenario-panel { order: 1; }
  .conversation-panel { order: 2; min-height: 32rem; }
  .evidence-panel { order: 3; display: block; }
  .evidence-panel .score-ring { margin: 1rem auto; }
  .messages { max-height: 28rem; }
  .composer-row { flex-direction: column; }
  .send-button { width: 100%; }
  .feedback-actions { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
  .thinking-dots span { animation: none !important; opacity: .7; }
}
