:root {
  --ink: #1c1d1f;
  --muted: #6f7175;
  --paper: #fffef9;
  --canvas: #f3f1e9;
  --line: #dcded7;
  --brand: #353638;
  --brand-strong: #191a1c;
  --brand-soft: #ececed;
  --student: #2864dc;
  --teacher: #e5533d;
  --amber: #f2b84b;
  --shadow: 0 18px 48px rgba(20, 20, 22, .12);
  font-family: "Noto Sans TC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.sidebar { padding: 28px 20px; background: #1d1e20; color: white; display: flex; flex-direction: column; gap: 28px; }
.brand { display: flex; gap: 12px; align-items: center; font-weight: 700; letter-spacing: .02em; }
.nav { display: grid; gap: 8px; }
.nav button { border: 0; border-radius: 11px; padding: 11px 12px; background: transparent; color: #c9cace; text-align: left; display:flex; align-items:center; gap:10px; }
.nav button.active, .nav button:hover { color: white; background: rgba(255,255,255,.11); }
.sidebar-note { margin-top: auto; color: #a7a8ac; font-size: 12px; line-height: 1.7; }

.content { padding: 36px clamp(24px, 5vw, 72px); overflow: auto; }
.topbar { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.eyebrow { margin: 0 0 6px; color: var(--brand); font-weight: 700; font-size: 13px; letter-spacing: .12em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font: 700 clamp(28px, 4vw, 42px)/1.2 "Plus Jakarta Sans", "Noto Sans TC"; letter-spacing: -.035em; }
h2 { font-size: 21px; }
.muted { color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 18px; }
.card { background: var(--paper); border: 1px solid rgba(25,26,28,.09); border-radius: 18px; box-shadow: 0 5px 20px rgba(20,20,22,.05); padding: 22px; }
.metric { grid-column: span 4; min-height: 140px; display: flex; flex-direction: column; justify-content: space-between; }
.metric strong { font: 700 38px/1 "Plus Jakarta Sans"; }
.metric span { color: var(--muted); font-size: 14px; }
.wide { grid-column: span 8; }
.narrow { grid-column: span 4; }
.full { grid-column: 1 / -1; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.card-head h2 { margin: 0; }

.btn { border: 0; border-radius: 11px; padding: 10px 15px; background: var(--brand); color: white; font-weight: 600; transition: .15s ease; }
.btn:hover { background: var(--brand-strong); transform: translateY(-1px); }
.btn.secondary { background: var(--brand-soft); color: var(--brand-strong); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: #a93c31; }
.btn.small { font-size: 13px; padding: 7px 11px; }
.btn:disabled { opacity: .45; pointer-events: none; }

.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; }
.field input, .field select { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--ink); outline: none; }
.field input:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.inline-form { display: flex; gap: 10px; align-items: end; }
.inline-form .field { flex: 1; margin: 0; }

.list { display: grid; gap: 9px; }
.list-row { padding: 14px; border: 1px solid var(--line); border-radius: 12px; display: flex; align-items: center; justify-content: space-between; gap: 14px; background: white; }
.list-row strong { display: block; margin-bottom: 3px; }
.list-row small { color: var(--muted); }
.row-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.empty { padding: 36px 18px; border: 1px dashed #bbc3bf; border-radius: 14px; color: var(--muted); text-align: center; }
.status { display: inline-flex; padding: 4px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; background: #edf0ee; color: #58615f; }
.status.live { background: #e5e5e6; color: #303134; }
.status.locked { background: #eee9e5; color: #725c50; }
.student-avatar { width: 42px; height: 42px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; }

.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr; background: #f5f2e9; }
.login-hero { padding: clamp(40px, 8vw, 110px); display: flex; flex-direction: column; justify-content: space-between; background: #1d1e20; color: white; position: relative; overflow: hidden; }
.login-hero::after { content: ""; position: absolute; width: 430px; height: 430px; border: 1px solid rgba(255,255,255,.18); border-radius: 48% 52% 58% 42%; right: -150px; bottom: -120px; transform: rotate(22deg); }
.login-hero h1 { max-width: 680px; font-size: clamp(42px, 7vw, 78px); line-height: 1.05; }
.login-hero p { max-width: 540px; color: #cfd0d2; font-size: 17px; line-height: 1.8; }
.login-panel { display: grid; place-items: center; padding: 32px; }
.login-card { width: min(430px, 100%); padding: 34px; background: var(--paper); border-radius: 22px; box-shadow: var(--shadow); }
.google-btn { width: 100%; padding: 13px; border: 1px solid var(--line); background: white; border-radius: 11px; font-weight: 600; }
.dev-note { margin: 18px 0 0; font-size: 12px; line-height: 1.6; color: var(--muted); }

.student-home { min-height: 100vh; }
.student-header { padding: 24px clamp(24px, 7vw, 90px); background: #1d1e20; color: white; display: flex; align-items: center; justify-content: space-between; }
.student-content { max-width: 1100px; margin: 0 auto; padding: 48px 24px; }
.hero-card { padding: 30px; border-radius: 22px; background: linear-gradient(135deg, #e7e7e8, #f4f2ee); margin-bottom: 30px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); padding: 11px 16px; color: white; background: #1d1e20; border-radius: 10px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; z-index: 1000; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Classroom */
.classroom-body { overflow: hidden; background: #e2e3e8; }
.classroom { height: 100vh; display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.classbar { min-height: 66px; padding: 10px 16px; background: #1d1e20; color: white; display: flex; align-items: center; gap: 14px; position: relative; z-index: 20; }
.class-title { min-width: 190px; }
.class-title strong { display: block; }
.class-title small { color: #c4c5c8; }
.tools { display: flex; align-items: center; gap: 7px; flex: 1; justify-content: center; }
.tool { min-width: 42px; height: 42px; border-radius: 10px; border: 1px solid rgba(255,255,255,.16); color: #ebedf6; background: transparent; padding: 0 11px; }
.tool:hover, .tool.active { background: #f1f1f2; color: #202124; }
.class-actions { display: flex; gap: 8px; align-items: center; }
.class-actions .btn { white-space: nowrap; }
.workspace { min-height: 0; display: grid; grid-template-columns: 1fr 300px; }
.workspace.answers-closed { grid-template-columns: 1fr 0; }
.document-scroll { overflow: auto; position: relative; padding: 30px max(24px, calc((100vw - 1050px)/2)); scroll-behavior: smooth; }
.pdf-pages { display: grid; gap: 24px; justify-content: center; }
.pdf-page { position: relative; background: white; box-shadow: 0 8px 25px rgba(20,20,22,.16); line-height: 0; user-select: none; }
.pdf-page canvas { display: block; max-width: 100%; height: auto; }
.annotation-layer { position: absolute; inset: 0; line-height: 1.4; overflow: hidden; }
.annotation { position: absolute; min-width: 20px; min-height: 18px; pointer-events: auto; }
.annotation.text { padding: 4px 7px; border-radius: 5px; background: rgba(255,255,255,.86); font-size: 16px; white-space: pre-wrap; line-height: 1.5; border: 1px solid currentColor; cursor: pointer; }
.annotation.student { color: var(--student); }
.annotation.teacher { color: var(--teacher); }
.annotation.highlight { background: rgba(255, 218, 73, .43); mix-blend-mode: multiply; border-radius: 3px; }
.annotation.ellipse { border: 3px solid var(--teacher); border-radius: 50%; }
.annotation.selected { outline: 3px solid rgba(40,40,42,.28); outline-offset: 3px; }
.draft-box { position: absolute; border: 2px dashed var(--brand); background: rgba(40,40,42,.07); pointer-events: none; }
.answer-panel { min-width: 0; overflow: hidden; background: var(--paper); border-left: 1px solid var(--line); display: flex; flex-direction: column; transition: .2s; }
.answer-head { padding: 18px; border-bottom: 1px solid var(--line); }
.answer-list { padding: 12px; display: grid; gap: 9px; overflow: auto; }
.answer-item { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: white; cursor: pointer; }
.answer-item:hover { border-color: var(--student); }
.answer-item small { color: var(--muted); }
.answer-item p { margin: 5px 0 0; color: var(--student); line-height: 1.5; }
.sync { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #c9cace; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: #bfc0c3; }

.icon { display: inline-block; flex: 0 0 auto; vertical-align: -0.18em; }
.btn, .tool { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.loading { min-height: 70vh; display: grid; place-items: center; color: var(--muted); }
.locked-banner { padding: 9px 16px; text-align: center; background: #f5e7c6; color: #694f16; font-size: 13px; }

dialog { border: 0; border-radius: 16px; width: min(480px, calc(100% - 32px)); padding: 0; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(18,18,20,.45); backdrop-filter: blur(3px); }
.dialog-inner { padding: 24px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.text-editor { width: 100%; min-height: 110px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; resize: vertical; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { padding: 16px 20px; flex-direction: row; align-items: center; }
  .nav { display: flex; margin-left: auto; }
  .sidebar-note { display: none; }
  .metric, .wide, .narrow { grid-column: 1 / -1; }
  .login { grid-template-columns: 1fr; }
  .login-hero { min-height: 44vh; padding: 45px 28px; }
  .workspace { grid-template-columns: 1fr; }
  .answer-panel { position: fixed; z-index: 30; right: 0; top: 66px; bottom: 0; width: min(340px, 90vw); box-shadow: var(--shadow); }
  .workspace.answers-closed .answer-panel { transform: translateX(105%); }
  .class-title { min-width: 0; }
  .tools .tool span { display: none; }
}

@media (max-width: 620px) {
  .content { padding: 24px 16px; }
  .topbar, .hero-card { align-items: flex-start; flex-direction: column; }
  .nav button { font-size: 0; }
  .nav button::first-letter { font-size: 16px; }
  .classbar { flex-wrap: wrap; }
  .class-title { flex: 1; }
  .tools { order: 3; width: 100%; overflow-x: auto; justify-content: flex-start; }
  .class-actions .btn { padding: 8px 10px; font-size: 12px; }
}
