:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #183230;
  background: #f6f7f2;
  font-synthesis: none;
  --ink: #183230;
  --muted: #647674;
  --line: #dce3df;
  --paper: #ffffff;
  --teal: #16756f;
  --teal-dark: #0e5b56;
  --yellow: #f6c453;
  --coral: #ec765f;
  --blue: #4e79b8;
  --soft-teal: #e4f1ee;
  --soft-yellow: #fff3cf;
  --soft-coral: #fce9e4;
  --shadow: 0 10px 30px rgba(34, 70, 65, 0.09);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #f6f7f2; }
body { min-height: 100dvh; letter-spacing: 0; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(22, 117, 111, 0.25);
  outline-offset: 2px;
}
.hidden { display: none !important; }
.icon { width: 20px; height: 20px; stroke-width: 2; flex: 0 0 auto; }
.icon-lg { width: 30px; height: 30px; }

.shell { min-height: 100dvh; padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 10px max(20px, calc((100vw - 920px) / 2));
  background: rgba(246, 247, 242, 0.94);
  border-bottom: 1px solid rgba(220, 227, 223, 0.75);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: white;
  background: var(--teal);
  border-radius: 8px;
}
.top-actions { display: flex; align-items: center; gap: 8px; }
.role-pill { color: var(--muted); font-size: 13px; font-weight: 700; }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.content { width: min(100% - 32px, 880px); margin: 0 auto; padding: 26px 0 34px; }
.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 0 0 7px; font-size: clamp(26px, 4vw, 36px); line-height: 1.2; }
.page-head p { margin: 0; color: var(--muted); font-size: 15px; }

.welcome-band {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 24px;
  padding: 24px;
  color: white;
  background: #16756f;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.welcome-band h1 { margin: 0 0 8px; font-size: clamp(26px, 5vw, 40px); line-height: 1.15; }
.welcome-band p { margin: 0; color: #ddf1ee; line-height: 1.7; }
.progress-orbit {
  display: grid;
  place-items: center;
  width: 112px;
  aspect-ratio: 1;
  color: var(--ink);
  background: var(--yellow);
  border: 8px solid rgba(255,255,255,0.22);
  border-radius: 50%;
  text-align: center;
}
.progress-orbit strong { display: block; font-size: 32px; line-height: 1; }
.progress-orbit span { display: block; margin-top: 6px; font-size: 12px; font-weight: 800; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 18px 0; }
.stat {
  min-height: 112px;
  padding: 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.stat .icon { margin-bottom: 14px; color: var(--teal); }
.stat strong { display: block; font-size: 26px; line-height: 1; }
.stat span { display: block; margin-top: 7px; color: var(--muted); font-size: 13px; }

.action-list { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; }
.action-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 138px;
  padding: 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.action-panel.primary { background: var(--soft-yellow); border-color: #edcf7c; }
.action-panel h2 { margin: 0 0 6px; font-size: 20px; }
.action-panel p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  color: white;
  font-weight: 800;
  background: var(--teal);
  border: 1px solid var(--teal);
  border-radius: 8px;
  white-space: nowrap;
}
.button:hover { background: var(--teal-dark); }
.button.secondary { color: var(--ink); background: white; border-color: var(--line); }
.button.secondary:hover { background: #f2f5f3; }
.button.coral { background: var(--coral); border-color: var(--coral); }
.button.small { min-height: 38px; padding: 0 12px; font-size: 13px; }
.button.wide { width: 100%; }
.button:disabled { cursor: default; opacity: 0.5; }

.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(calc(100% - 24px), 520px);
  padding: 7px;
  padding-bottom: max(7px, env(safe-area-inset-bottom));
  background: rgba(255,255,255,0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 35px rgba(31, 56, 52, 0.16);
  backdrop-filter: blur(14px);
}
.nav-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 48px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 800;
}
.nav-button.active { color: var(--teal-dark); background: var(--soft-teal); }

.login-page {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  min-height: 100dvh;
  background: white;
}
.login-story {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 100%;
  padding: clamp(32px, 7vw, 80px);
  overflow: hidden;
  color: white;
  background: #16756f;
}
.login-story::before, .login-story::after {
  content: "";
  position: absolute;
  border: 16px solid rgba(255,255,255,0.16);
  border-radius: 50%;
}
.login-story::before { width: 220px; height: 220px; top: 9%; right: 11%; }
.login-story::after { width: 80px; height: 80px; top: 31%; right: 33%; background: var(--yellow); border-color: var(--yellow); }
.login-story-content { position: relative; z-index: 1; max-width: 580px; }
.login-story .brand { margin-bottom: 40px; }
.login-story h1 { margin: 0 0 16px; max-width: 520px; font-size: clamp(42px, 7vw, 72px); line-height: 1.05; }
.login-story p { margin: 0; max-width: 480px; color: #d8f0ed; font-size: 18px; line-height: 1.7; }
.login-panel { display: grid; place-items: center; padding: 30px; }
.login-form { width: min(100%, 380px); }
.login-form h2 { margin: 0 0 8px; font-size: 26px; }
.login-form > p { margin: 0 0 24px; color: var(--muted); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: #edf1ef; border-radius: 8px; }
.segment { min-height: 42px; color: var(--muted); font-weight: 800; background: transparent; border: 0; border-radius: 6px; }
.segment.active { color: var(--ink); background: white; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
.field { display: grid; gap: 7px; margin: 18px 0; }
.field label { color: #405451; font-size: 13px; font-weight: 800; }
.field input, .field textarea, .field select {
  width: 100%;
  min-height: 46px;
  padding: 11px 12px;
  color: var(--ink);
  background: white;
  border: 1px solid #cbd6d2;
  border-radius: 6px;
}
.field textarea { min-height: 92px; resize: vertical; line-height: 1.6; }
.error-text { min-height: 22px; margin: 10px 0; color: #b64635; font-size: 13px; }

.review-wrap { width: min(100%, 700px); margin: 0 auto; }
.review-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.review-toolbar-main { display: flex; align-items: center; gap: 10px; }
.review-count { color: var(--muted); font-size: 14px; font-weight: 800; }
.phase-pill { padding: 5px 9px; color: var(--teal-dark); background: var(--soft-teal); border-radius: 4px; font-size: 12px; font-weight: 800; }
.progress-track { height: 8px; margin-bottom: 20px; overflow: hidden; background: #e3e9e6; border-radius: 4px; }
.progress-track span { display: block; height: 100%; background: var(--teal); transition: width 220ms ease; }
.study-card {
  display: grid;
  align-content: center;
  min-height: 410px;
  padding: clamp(28px, 7vw, 60px);
  text-align: center;
  background: white;
  border: 1px solid var(--line);
  border-top: 8px solid var(--yellow);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.study-tag { margin-bottom: 20px; color: var(--teal-dark); font-size: 13px; font-weight: 900; }
.study-prompt { margin: 0; overflow-wrap: anywhere; font-size: clamp(34px, 8vw, 58px); line-height: 1.25; }
.study-card.sentence .study-prompt { font-size: clamp(28px, 6vw, 44px); }
.answer-area { min-height: 112px; margin-top: 26px; padding-top: 24px; border-top: 1px dashed var(--line); }
.answer-area strong { display: block; overflow-wrap: anywhere; font-size: clamp(25px, 5vw, 38px); line-height: 1.35; }
.answer-area p { margin: 12px 0 0; color: var(--muted); line-height: 1.6; }
.reveal-actions { display: flex; justify-content: center; gap: 10px; margin-top: 28px; }
.write-instruction { max-width: 430px; margin: 30px auto 0; color: var(--muted); font-size: 15px; line-height: 1.7; }
.write-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }
.marking-wrap { width: min(100%, 780px); margin: 0 auto; }
.marking-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.marking-head-actions { display: flex; align-items: center; gap: 8px; }
.marking-count { flex: 0 0 auto; padding: 7px 10px; color: var(--teal-dark); background: var(--soft-teal); border-radius: 4px; font-size: 13px; font-weight: 900; }
.marking-list { display: grid; gap: 12px; }
.marking-item { padding: 18px; background: white; border: 1px solid var(--line); border-radius: 8px; }
.marking-answer { display: grid; grid-template-columns: 34px minmax(0, 1fr) 42px; align-items: center; gap: 12px; }
.marking-number { display: grid; place-items: center; width: 32px; height: 32px; color: var(--teal-dark); background: var(--soft-teal); border-radius: 50%; font-size: 13px; font-weight: 900; }
.marking-answer span:not(.marking-number) { display: block; color: var(--muted); font-size: 14px; }
.marking-answer strong { display: block; margin-top: 4px; overflow-wrap: anywhere; font-size: 23px; line-height: 1.35; }
.marking-answer small { display: block; margin-top: 6px; color: var(--muted); line-height: 1.45; }
.rating-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 16px; }
.rating-grid.compact { margin: 16px 0 0 46px; }
.rating {
  min-height: 70px;
  padding: 8px;
  color: var(--ink);
  font-weight: 900;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.rating.again { background: var(--soft-coral); border-color: #efb1a4; }
.rating.hard { background: var(--soft-yellow); border-color: #efd88c; }
.rating.good { background: var(--soft-teal); border-color: #9bcfc7; }
.rating.easy { color: white; background: var(--blue); border-color: var(--blue); }
.rating small { display: block; margin-top: 4px; font-weight: 600; opacity: 0.72; }
.rating.selected { outline: 3px solid var(--ink); outline-offset: 2px; }
.marking-submit {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding: 14px 16px;
  background: rgba(255,255,255,0.97);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.marking-submit span { color: var(--muted); font-size: 13px; font-weight: 700; }

.empty-state { padding: 60px 24px; text-align: center; background: white; border: 1px solid var(--line); border-radius: 8px; }
.empty-state .empty-visual {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  margin: 0 auto 22px;
  color: var(--teal);
  background: var(--soft-teal);
  border-radius: 50%;
}
.empty-state h2 { margin: 0 0 8px; }
.empty-state p { margin: 0 0 22px; color: var(--muted); }

.admin-layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 22px; align-items: start; }
.form-panel, .list-panel { padding: 20px; background: white; border: 1px solid var(--line); border-radius: 8px; }
.form-panel { position: sticky; top: 84px; }
.form-panel h2, .list-panel h2 { margin: 0 0 4px; font-size: 20px; }
.panel-note { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions { display: flex; gap: 8px; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.search-input { width: min(100%, 230px); min-height: 40px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 6px; }
.item-list { display: grid; gap: 8px; }
.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.item-main { min-width: 0; }
.item-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-main span { display: block; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { display: flex; gap: 6px; margin-top: 9px; }
.badge { padding: 3px 7px; color: var(--teal-dark); background: var(--soft-teal); border-radius: 4px; font-size: 11px; font-weight: 800; }
.row-actions { display: flex; gap: 6px; }
.row-actions .icon-button { width: 38px; height: 38px; }
.danger { color: #b64635; }
.import-box { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.import-box summary { cursor: pointer; font-weight: 800; }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 92px;
  transform: translate(-50%, 16px);
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  color: white;
  background: #183230;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 760px) {
  .login-page { grid-template-columns: 1fr; }
  .login-story { min-height: 40vh; padding: 30px 24px; }
  .login-story::before { width: 130px; height: 130px; }
  .login-story::after { width: 44px; height: 44px; }
  .login-story h1 { font-size: 38px; }
  .login-story p { font-size: 15px; }
  .login-panel { padding: 30px 24px 50px; }
  .welcome-band { grid-template-columns: 1fr; }
  .progress-orbit { width: 94px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .action-list { grid-template-columns: 1fr; }
  .action-panel { min-height: 120px; }
  .admin-layout { grid-template-columns: 1fr; }
  .form-panel { position: static; }
  .rating-grid { grid-template-columns: 1fr 1fr; }
  .rating-grid.compact { margin-left: 0; }
  .study-card { min-height: 360px; }
  .role-pill { display: none; }
}

@media (max-width: 430px) {
  .content { width: min(100% - 24px, 880px); padding-top: 18px; }
  .topbar { padding-inline: 14px; }
  .stats-grid { gap: 8px; }
  .stat { min-height: 98px; padding: 14px; }
  .action-panel { align-items: flex-start; flex-direction: column; }
  .action-panel .button { width: 100%; }
  .study-card { padding: 28px 18px; }
  .write-nav { display: grid; grid-template-columns: 1fr; }
  .write-nav .button { width: 100%; }
  .marking-head { align-items: flex-start; flex-direction: column; gap: 12px; }
  .marking-answer { grid-template-columns: 32px minmax(0, 1fr) 42px; gap: 8px; }
  .marking-item { padding: 14px; }
  .marking-answer strong { font-size: 20px; }
  .marking-submit { align-items: stretch; flex-direction: column; }
  .marking-submit .button { width: 100%; }
  .inline-fields { grid-template-columns: 1fr; }
  .list-head { align-items: stretch; flex-direction: column; }
  .search-input { width: 100%; }
  .nav-button span { display: none; }
}
