:root {
  color-scheme: light;
  --ink: #15243a;
  --muted: #6b7890;
  --line: #dbe3ef;
  --primary: #2563eb;
  --success: #14835c;
  --danger: #c53b45;
  --surface: #ffffff;
  --background: #f4f7fb;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--background);
  color: var(--ink);
  overscroll-behavior: none;
}

body { padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }

.auth-gate {
  min-height: calc(100vh - 38px);
  display: grid;
  place-items: center;
}

.auth-gate-card {
  display: grid;
  gap: 8px;
  padding: 24px 28px;
  text-align: center;
  color: var(--muted);
}

.auth-gate-card strong {
  color: var(--ink);
  font-size: 22px;
}

button, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.topbar {
  max-width: 1320px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

h1 { margin: 0; font-size: clamp(24px, 3vw, 36px); letter-spacing: -0.03em; }
.topbar p { margin: 6px 0 0; color: var(--muted); }
.session-actions, .toolbar { display: flex; gap: 10px; }
.header-controls { display: grid; justify-items: end; gap: 9px; }
.account-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.sync-indicator { border-radius: 999px; padding: 5px 9px; font-weight: 700; background: #eaf8f2; color: var(--success); }
.sync-indicator.pending { background: #fff5dd; color: #97640b; }
.sync-indicator.failed { background: #fff0f1; color: var(--danger); }

.layout {
  max-width: 1320px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid rgba(205, 216, 231, 0.9);
  border-radius: 20px;
  box-shadow: 0 14px 36px rgba(40, 60, 90, 0.08);
}

.workspace { padding: 22px; }
.sidebar { padding: 22px; }

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 18px;
  padding: 4px;
  border-radius: 12px;
  background: #edf1f6;
}
.mode-switch button {
  border: 0;
  border-radius: 9px;
  padding: 10px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-weight: 750;
}
.mode-switch button.active { color: var(--primary); background: #fff; box-shadow: 0 1px 5px #10243e18; }

.prompt-row, .sidebar-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.prompt-digit {
  margin-top: 2px;
  max-width: min(62vw, 680px);
  overflow-wrap: anywhere;
  font-size: 76px;
  line-height: 1.08;
  font-weight: 750;
  color: var(--primary);
}
.prompt-digit.long { font-size: 48px; }

.prompt-meta { text-align: right; display: grid; gap: 7px; }
.prompt-meta strong { font-size: 18px; }
.prompt-meta span { color: var(--muted); font-size: 14px; }

.canvas-shell {
  width: min(100%, 680px);
  aspect-ratio: 1;
  margin: 16px auto 18px;
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
  border: 1px solid #ccd7e6;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.8), 0 8px 24px rgba(30,50,80,.08);
}

#writingCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.canvas-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  text-align: center;
  color: #9aa7b8;
  font-size: 13px;
  pointer-events: none;
}

.recognition-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid #cbd9ed;
  border-radius: 14px;
  background: #f6f9ff;
}
.recognition-heading { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; }
.recognition-heading strong { color: var(--ink); }
.candidate-list { display: flex; flex-wrap: wrap; gap: 10px; min-height: 54px; margin: 12px 0; }
.candidate-button {
  min-width: 58px;
  height: 54px;
  border: 1px solid #b9cbe4;
  border-radius: 12px;
  color: var(--primary);
  background: #fff;
  font-size: 30px;
  font-weight: 750;
}
.candidate-button:active { transform: scale(.96); background: #e9f1ff; }
.manual-label { display: flex; gap: 9px; }
.manual-label input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font: inherit; }
.manual-label .button { padding: 9px 13px; }

.toolbar { justify-content: center; flex-wrap: wrap; }
.button {
  border: 0;
  border-radius: 12px;
  padding: 11px 17px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.button:active { transform: scale(.98); }
.button:disabled { opacity: .38; cursor: default; }
.primary { color: #fff; background: var(--primary); }
.success { color: #fff; background: var(--success); }
.secondary { color: var(--ink); background: #edf2f8; }
.danger-solid { color: #fff; background: var(--danger); }

.options {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 22px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 14px;
}
.options label { display: flex; align-items: center; gap: 9px; }
.options select, .options input[type="number"] { width: 82px; border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; background: #fff; }
.toggle-label input { width: 18px; height: 18px; }

.sidebar-title strong { display: block; margin-top: 5px; font-size: 22px; }
.text-button { border: 0; background: transparent; padding: 8px; font-weight: 650; cursor: pointer; }
.danger { color: var(--danger); }

.custom-label-panel {
  display: grid;
  gap: 9px;
  margin: 20px 0 14px;
}
.custom-label-panel label { color: var(--muted); font-size: 13px; font-weight: 700; }
.custom-label-panel textarea {
  width: 100%;
  resize: vertical;
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fbfcfe;
  font: inherit;
  line-height: 1.45;
}
.custom-label-actions { display: flex; gap: 8px; }
.custom-label-actions .button { flex: 1; padding: 9px 8px; font-size: 13px; }

.gesture-template-panel { margin: 14px 0; }
.gesture-template-panel > label { color: var(--muted); font-size: 13px; font-weight: 700; }
.gesture-template-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.gesture-template-list button { border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; background: #f8fafc; color: var(--ink); font: inherit; font-size: 12px; }
.gesture-template-list button.active { border-color: var(--primary); color: var(--primary); background: #eff5ff; }

.digit-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 9px;
  margin: 14px 0 22px;
  max-height: 340px;
  overflow-y: auto;
  padding-right: 3px;
}

.digit-card {
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px 4px;
  color: var(--ink);
  cursor: pointer;
}
.digit-card strong { display: block; overflow: hidden; text-overflow: ellipsis; font-size: 24px; white-space: nowrap; }
.digit-card.long strong { font-size: 15px; }
.digit-card span { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.digit-card.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); background: #eff5ff; }
.digit-card.complete { background: #eaf8f2; border-color: #91d5bd; }

.quality-panel, .tips { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 18px; }
h2 { font-size: 16px; margin: 0 0 13px; }
dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
dl div { background: #f7f9fc; border-radius: 11px; padding: 10px; }
dt { color: var(--muted); font-size: 12px; }
dd { margin: 5px 0 0; font-weight: 750; }
.tips ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13px; line-height: 1.65; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: #15243a;
  color: #fff;
  padding: 11px 17px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.asset-view {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
}
.asset-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.asset-heading h2 { margin: 5px 0 0; font-size: 24px; }
.asset-heading-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-teacher-panel { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-top: 20px; padding: 14px; border-radius: 14px; background: #eef4ff; }
.admin-teacher-panel label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
.admin-teacher-panel select, .admin-teacher-panel input { min-width: 220px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: #fff; color: var(--ink); font: inherit; }
.course-planner { display: grid; grid-template-columns: 220px 1fr; gap: 14px; margin: 22px 0; padding: 18px; border-radius: 16px; background: #f7f9fc; }
.course-planner label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
.course-planner input, .course-planner textarea { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 10px 11px; color: var(--ink); background: #fff; font: inherit; }
.course-text-field { min-width: 0; }
.planner-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.coverage-result { min-height: 44px; padding: 11px 13px; border-radius: 11px; background: #fff; color: var(--muted); line-height: 1.55; }
.coverage-result strong { color: var(--ink); }
.asset-summary { margin: 16px 0; color: var(--muted); }
.glyph-asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); gap: 14px; }
.glyph-asset-card { padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.glyph-asset-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.glyph-asset-title strong { font-size: 38px; color: var(--primary); }
.glyph-asset-title span { color: var(--muted); font-size: 12px; text-align: right; white-space: pre-line; }
.sample-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.sample-chip { border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; background: #f8fafc; color: var(--ink); font: inherit; font-size: 12px; }
.sample-chip.approved { border-color: #8fd4ba; background: #eaf8f2; }
.sample-chip.disabled { color: #8993a3; text-decoration: line-through; }
.sample-modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: rgba(16, 32, 54, .48); }
.sample-modal[hidden] { display: none; }
.sample-dialog { width: min(92vw, 540px); max-height: 94vh; overflow: auto; padding: 20px; }
#replayCanvas { display: block; width: min(100%, 430px); aspect-ratio: 1; margin: 16px auto; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.sample-metadata { margin: 10px 0 16px; color: var(--muted); font-size: 13px; text-align: center; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { order: 2; }
  .canvas-shell { width: min(100%, 72vh); }
}

@media (max-width: 600px) {
  body { padding-left: 10px; padding-right: 10px; }
  .topbar { align-items: flex-start; }
  .topbar p { display: none; }
  .session-actions { flex-direction: column; }
  .header-controls { justify-items: end; }
  .account-line { flex-wrap: wrap; justify-content: flex-end; }
  .workspace, .sidebar { padding: 15px; border-radius: 15px; }
  .prompt-digit { font-size: 58px; }
  .prompt-meta strong { font-size: 15px; }
  .button { padding: 10px 13px; }
  .course-planner { grid-template-columns: 1fr; }
  .asset-view { padding: 15px; }
  .asset-heading { align-items: flex-start; flex-direction: column; }
  .admin-teacher-panel > div { width: 100%; }
  .admin-teacher-panel select, .admin-teacher-panel input { min-width: 0; width: 100%; }
}
