/* ============================================================
   app.css — 设计令牌 / 基础排版 / 通用组件
   视觉来源：韩国学生用的 원고지(原稿纸) 격자 노트。
   纸是微冷的练习册白，墨是中性近黑，批改红笔与형광펜黄只用在
   「该被注意的那一处」：评分按钮、语法形式、重点词。
   ============================================================ */

:root {
  /* 纸与墨 */
  --paper: #f6f7f4;
  --paper-2: #ffffff;
  --paper-3: #eef0ea;
  --ink: #191e28;
  --ink-2: #4b5563;
  --ink-3: #8a929e;
  --rule: #e1e5de;
  --rule-2: #c9d0c7;

  /* 两种笔 */
  --pen: #c8402f;
  --pen-soft: #fbebe8;
  --hl: #ffe066;
  --hl-soft: #fff8dc;
  --good: #2e6b57;
  --good-soft: #e6f1eb;

  /* 字 */
  --font-ko: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Nanum Gothic", sans-serif;
  --font-ui: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", -apple-system, "Segoe UI", sans-serif;
  --font-data: ui-monospace, "SF Mono", "Cascadia Mono", "Consolas", monospace;

  --fs-xs: 12px;
  --fs-s: 13px;
  --fs-m: 15px;
  --fs-l: 17px;
  --fs-xl: 21px;
  --fs-2xl: 28px;
  --fs-3xl: 42px;

  /* 尺寸 */
  --gap: 12px;
  --pad: 16px;
  --r-s: 6px;
  --r-m: 10px;
  --r-l: 16px;
  --topbar-h: 52px;
  --tabbar-h: 58px;

  --shadow-1: 0 1px 2px rgba(25, 30, 40, 0.06);
  --shadow-2: 0 6px 24px -12px rgba(25, 30, 40, 0.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background-color: var(--paper);
  /* 原稿纸细则：28px 见方，1px 淡线 */
  background-image:
    linear-gradient(to right, rgba(201, 208, 199, 0.34) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(201, 208, 199, 0.34) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: -1px -1px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-m);
  line-height: 1.62;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body.is-immersive {
  background-image: none;
  background-color: var(--paper-2);
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 680px;
  margin: 0 auto;
  background: var(--paper);
  position: relative;
}

body.is-immersive #app { background: var(--paper-2); }

@media (min-width: 720px) {
  body { background-attachment: fixed; }
  #app {
    border-left: 1px solid var(--rule);
    border-right: 1px solid var(--rule);
    min-height: 100dvh;
  }
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--topbar-h);
  padding: 0 10px;
  background: rgba(246, 247, 244, 0.86);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar[hidden] { display: none; }

.topbar__title {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-m);
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__title .ko { font-family: var(--font-ko); }

.topbar__sub {
  font-family: var(--font-data);
  font-size: var(--fs-xs);
  color: var(--ink-3);
  font-weight: 400;
  margin-left: 6px;
}

.iconbtn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--r-m);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.iconbtn:hover { background: var(--paper-3); color: var(--ink); }
.iconbtn svg { width: 20px; height: 20px; }
.iconbtn--text {
  width: auto;
  padding: 0 8px;
  font-size: var(--fs-s);
  font-family: var(--font-ui);
  color: var(--ink-2);
}

/* ---------- 主区域 ---------- */

.view {
  flex: 1;
  padding: var(--pad);
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 24px);
}
body.is-immersive .view { padding-bottom: calc(var(--safe-b) + 24px); }

.view--notab { padding-bottom: calc(var(--safe-b) + 24px); }

/* ---------- 底部导航 ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: none;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(246, 247, 244, 0.94);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--rule);
}
.tabbar[data-show="1"] { display: flex; }

@media (min-width: 720px) {
  .tabbar {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 100%;
    max-width: 680px;
    border-left: 1px solid var(--rule);
    border-right: 1px solid var(--rule);
  }
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font-size: 10.5px;
  font-family: var(--font-ui);
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 22px; height: 22px; stroke-width: 1.7; }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"] svg { stroke-width: 2.1; }
.tab__dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--pen);
  margin-top: 1px;
  opacity: 0;
}
.tab[aria-current="page"] .tab__dot { opacity: 1; }

/* ---------- 卡片 ---------- */

.card {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--r-m);
  padding: var(--pad);
  box-shadow: var(--shadow-1);
}
.card + .card { margin-top: 10px; }
.card--plain { box-shadow: none; background: transparent; border-style: dashed; }
.card--tight { padding: 12px; }

.sectionhead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 22px 2px 10px;
}
.sectionhead:first-child { margin-top: 4px; }
.sectionhead h2 {
  margin: 0;
  font-size: var(--fs-s);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  text-transform: uppercase;
}
.sectionhead a, .sectionhead .lnk {
  font-size: var(--fs-s);
  color: var(--ink-2);
  text-decoration: none;
  border-bottom: 1px solid var(--rule-2);
}

/* ---------- 文字 ---------- */

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }

.ko { font-family: var(--font-ko); }
.mono { font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.dim { color: var(--ink-3); }
.small { font-size: var(--fs-s); }
.xsmall { font-size: var(--fs-xs); }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.strong { font-weight: 600; }
.pen { color: var(--pen); }
.good { color: var(--good); }

a { color: inherit; }

.hr {
  height: 1px;
  background: var(--rule);
  border: 0;
  margin: 14px 0;
}

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  white-space: nowrap;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-m);
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-m);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
}
.btn:hover { background: var(--paper-3); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.btn--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.btn--primary:hover { background: #2b3441; border-color: #2b3441; }

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-2);
}
.btn--ghost:hover { background: var(--paper-3); color: var(--ink); }

.btn--danger { color: var(--pen); border-color: #e7cfca; }
.btn--danger:hover { background: var(--pen-soft); }

.btn--sm { min-height: 32px; padding: 0 10px; font-size: var(--fs-s); border-radius: var(--r-s); }
.btn--block { display: flex; width: 100%; }
.btn svg { width: 16px; height: 16px; }

.btnrow {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.btnrow > .btn { flex: 1 1 auto; }

/* ---------- 表单 ---------- */

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.label .hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--ink-3);
  font-size: var(--fs-xs);
}

.input, .textarea, .select {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-m);
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-m);
  line-height: 1.55;
  -webkit-appearance: none;
  appearance: none;
}
.input.ko, .textarea.ko { font-family: var(--font-ko); font-size: var(--fs-l); }
.textarea { min-height: 120px; resize: vertical; }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--ink-2);
  box-shadow: 0 0 0 3px rgba(25, 30, 40, 0.07);
}
.input::placeholder, .textarea::placeholder { color: #b3b9c0; }

.select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%238a929e' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.fieldrow { display: flex; gap: 10px; }
.fieldrow > * { flex: 1; min-width: 0; }

.help { font-size: var(--fs-xs); color: var(--ink-3); margin-top: 6px; line-height: 1.5; }

/* 分段控件 */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--paper-3);
  border-radius: var(--r-m);
}
.seg button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 7px;
  font-family: var(--font-ui);
  font-size: var(--fs-s);
  color: var(--ink-2);
  cursor: pointer;
}
.seg button[aria-pressed="true"] {
  background: var(--paper-2);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-1);
}

/* ---------- 标签 / 徽标 ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--rule-2);
  background: var(--paper-2);
  font-size: var(--fs-xs);
  color: var(--ink-2);
  line-height: 1.7;
}
.chip--hl { background: var(--hl-soft); border-color: #ecd98b; color: #6b5610; }
.chip--pen { background: var(--pen-soft); border-color: #e7cfca; color: var(--pen); }
.chip--good { background: var(--good-soft); border-color: #c3dbd0; color: var(--good); }

/* 课次：原稿纸里的一格 */
.unitcell {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  font-family: var(--font-data);
  font-size: var(--fs-xs);
  color: var(--ink-2);
  border: 1px solid var(--rule-2);
  border-radius: 3px;
  padding: 0 5px;
  line-height: 1.6;
  background: var(--paper-2);
}
.unitcell b { font-weight: 700; color: var(--ink); }

/* ---------- 原稿纸面板（签名元素） ---------- */

.hanji {
  position: relative;
  background-color: var(--paper-2);
  background-image:
    linear-gradient(to right, rgba(201, 208, 199, 0.5) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(201, 208, 199, 0.5) 1px, transparent 1px);
  background-size: 32px 32px;
  border: 1px solid var(--rule);
  border-radius: var(--r-m);
  padding: 20px 18px;
}

/* 형광펜：做在字下而不遮盖字的荧光笔痕 */
.mark {
  background-image: linear-gradient(transparent 58%, var(--hl) 58%, var(--hl) 94%, transparent 94%);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  padding: 0 1px;
}

/* ---------- 列表 ---------- */

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--rule); }
.list > li:last-child { border-bottom: 0; }

.rowlink {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 2px;
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.rowlink:hover { background: rgba(238, 240, 234, 0.6); }
.rowlink__main { flex: 1; min-width: 0; }
.rowlink__title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: var(--fs-l);
  font-family: var(--font-ko);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rowlink__meta {
  font-size: var(--fs-s);
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rowlink__tail { flex: none; font-family: var(--font-data); font-size: var(--fs-xs); color: var(--ink-3); }

/* ---------- 空状态 ---------- */

.empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--ink-3);
  border: 1px dashed var(--rule-2);
  border-radius: var(--r-m);
  background: rgba(255, 255, 255, 0.5);
}
.empty__title { font-size: var(--fs-m); color: var(--ink-2); font-weight: 600; margin-bottom: 6px; }
.empty__body { font-size: var(--fs-s); line-height: 1.7; margin-bottom: 14px; }

/* ---------- 进度 / 统计 ---------- */

.bar {
  height: 4px;
  border-radius: 99px;
  background: var(--rule);
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: var(--ink);
  border-radius: 99px;
  transition: width 0.25s ease;
}

.stats { display: flex; gap: 0; }
.stat {
  flex: 1;
  padding: 2px 10px;
  border-left: 1px solid var(--rule);
}
.stat:first-child { border-left: 0; padding-left: 0; }
.stat__n {
  font-family: var(--font-data);
  font-size: var(--fs-xl);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.stat__k { font-size: var(--fs-xs); color: var(--ink-3); letter-spacing: 0.04em; }

/* ---------- 评分按钮（红笔 / 绿笔） ---------- */

.grades {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.grade {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 8px 4px 9px;
  border: 1px solid var(--rule-2);
  border-radius: var(--r-m);
  background: var(--paper-2);
  font-family: var(--font-ui);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.grade__k { font-size: var(--fs-s); font-weight: 600; }
.grade__v { font-family: var(--font-data); font-size: 10.5px; color: var(--ink-3); letter-spacing: -0.02em; }
.grade b { font-weight: inherit; }
.grade[data-r="again"] .grade__k { color: var(--pen); }
.grade[data-r="good"] .grade__k, .grade[data-r="easy"] .grade__k { color: var(--good); }
.grade:hover { border-color: var(--ink-3); }
.grade:active { background: var(--paper-3); }

@media (min-width: 480px) {
  .grade { padding: 10px 6px; }
  .grade__v { font-size: 11px; }
}

/* ---------- 提示条 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  transform: translate(-50%, 12px);
  z-index: 90;
  max-width: min(90vw, 420px);
  padding: 10px 16px;
  border-radius: var(--r-m);
  background: rgba(25, 30, 40, 0.94);
  color: #fff;
  font-size: var(--fs-s);
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  text-align: center;
}
.toast[data-show="1"] { opacity: 1; transform: translate(-50%, 0); }

.notice {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-m);
  font-size: var(--fs-s);
  line-height: 1.6;
  background: var(--hl-soft);
  border: 1px solid #ecd98b;
  color: #5c4a0d;
}
.notice--pen { background: var(--pen-soft); border-color: #e7cfca; color: #8c2b1e; }
.notice--good { background: var(--good-soft); border-color: #c3dbd0; color: #235446; }
.notice--plain { background: var(--paper-3); border-color: var(--rule-2); color: var(--ink-2); }
.notice svg { width: 16px; height: 16px; flex: none; margin-top: 3px; }

/* ---------- Markdown ---------- */

.md { line-height: 1.75; }
.md > *:first-child { margin-top: 0; }
.md h3 {
  font-size: var(--fs-m);
  margin: 18px 0 6px;
  padding-left: 9px;
  border-left: 3px solid var(--ink);
}
.md h4 { font-size: var(--fs-m); margin: 14px 0 4px; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 20px; }
.md li { margin-bottom: 3px; }
.md strong { font-weight: 600; }
.md em { font-style: normal; background: var(--hl-soft); padding: 0 2px; }
.md code {
  font-family: var(--font-data);
  font-size: 0.9em;
  background: var(--paper-3);
  padding: 1px 5px;
  border-radius: 4px;
}
.md blockquote {
  margin: 0 0 10px;
  padding: 8px 12px;
  border-left: 3px solid var(--rule-2);
  background: var(--paper-3);
  color: var(--ink-2);
  border-radius: 0 var(--r-s) var(--r-s) 0;
}
.md table { border-collapse: collapse; width: 100%; margin: 0 0 10px; font-size: var(--fs-s); }
.md th, .md td { border: 1px solid var(--rule); padding: 5px 8px; text-align: left; }
.md th { background: var(--paper-3); }
.md hr { border: 0; border-top: 1px solid var(--rule); margin: 16px 0; }

/* ---------- 底部弹层 ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(25, 30, 40, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.sheet[data-show="1"] { opacity: 1; pointer-events: auto; }
.sheet__panel {
  background: var(--paper-2);
  border-radius: var(--r-l) var(--r-l) 0 0;
  max-height: 92dvh;
  overflow: auto;
  padding: 8px 16px calc(16px + var(--safe-b));
  transform: translateY(16px);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.sheet[data-show="1"] .sheet__panel { transform: translateY(0); }
.sheet__grip {
  width: 36px;
  height: 4px;
  border-radius: 99px;
  background: var(--rule-2);
  margin: 6px auto 12px;
}

/* ---------- 工具类 ---------- */

.stack > * + * { margin-top: 10px; }
.stack-s > * + * { margin-top: 6px; }
.stack-l > * + * { margin-top: 18px; }
.flex { display: flex; align-items: center; gap: 8px; }
.flex--between { justify-content: space-between; }
.flex--wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.mt-0 { margin-top: 0; }
.mt-s { margin-top: 8px; }
.mt-m { margin-top: 14px; }
.mt-l { margin-top: 22px; }
.mb-s { margin-bottom: 8px; }
.mb-m { margin-bottom: 14px; }
.hidden { display: none !important; }

/* 焦点可见（键盘） */
:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus:not(:focus-visible) { outline: none; }

/* 尊重减少动效 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* 旋转 */
.spin {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
.spin--ink { border-color: rgba(25, 30, 40, 0.2); border-top-color: var(--ink); }

/* 图标兜底尺寸：没有 width/height 的 <svg> 浏览器按 300×150 算，会把布局撑破。
   用 :where() 让优先级归零，具体场景写了自己的尺寸就盖掉这条。 */
:where(#view, #topbar, #tabbar, .sheet, .md) svg {
  width: 18px;
  height: 18px;
  flex: none;
}@keyframes spin { to { transform: rotate(360deg); } }
