:root {
  --paper: #faf6ec;
  --paper-deep: #f1eadc;
  --blue: #d4ecfb;
  --blue-dark: #5ba4cf;
  --pink: #ffe4ec;
  --pink-dark: #d985a2;
  --ink: #40596b;
  --muted: #777875;
  --border: #cdc6b8;
  --shadow: 3px 4px 0 #cbdde7;
  --radius-lg: 15px;
  --radius-md: 12px;
  --radius-sm: 8px;
  font-family: "Iowan Old Style", "Baskerville", "Songti SC", "Noto Serif CJK SC", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #e9e4d8;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  overflow-x: hidden;
  background-color: #e9e4d8;
  background-image: url("assets/paper-grain.svg");
  background-repeat: repeat;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

@media (hover: hover) and (pointer: fine) {
  body,
  button,
  select,
  .file-drop,
  .book-item {
    cursor: url("assets/cat-paw-cursor.svg") 9 5, pointer;
  }

  input,
  textarea {
    cursor: text;
  }
}

.floating-decor {
  position: fixed;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

.deco {
  position: absolute;
  display: block;
  line-height: 1;
  opacity: 0.6;
  animation: deco-float 5s ease-in-out infinite;
  user-select: none;
}

.deco-star {
  top: 9%;
  right: 2%;
  color: #f3c86b;
  font-size: 42px;
}

.deco-heart {
  top: 44%;
  left: 1%;
  color: #e7a1b7;
  font-size: 30px;
  animation-delay: -1.5s;
}

.deco-paw {
  right: 1%;
  bottom: 25%;
  width: 38px;
  height: 38px;
  animation-delay: -2.5s;
}

.deco-star-small {
  bottom: 8%;
  left: 2%;
  color: #83c3e3;
  font-size: 38px;
  animation-delay: -3.2s;
}

@keyframes deco-float {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-16px) rotate(7deg); }
}

.cat-sticker {
  position: fixed;
  right: 28px;
  bottom: 24px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 1px dashed var(--pink-dark);
  border-radius: 50%;
  background: var(--pink);
  box-shadow: var(--shadow);
  font-size: 29px;
  user-select: none;
  animation: sticker-bob 3.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes sticker-bob {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-8px) rotate(5deg); }
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(250px, 292px) minmax(420px, 1fr) minmax(280px, 360px);
  gap: 22px;
  width: min(1660px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  align-items: start;
}

.paper-panel {
  border: 1px solid var(--border);
  background-color: var(--paper);
  background-image: url("assets/paper-grain.svg");
  background-repeat: repeat;
  box-shadow: var(--shadow);
}

.sidebar,
.rightbar {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  scrollbar-width: thin;
}

.sidebar {
  padding: 22px;
  border-radius: var(--radius-lg);
}

.rightbar {
  display: grid;
  gap: 18px;
}

.main-area {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid var(--blue-dark);
  border-radius: 10px;
  background: var(--blue);
  color: #4a7ba0;
  font-weight: 900;
  font-size: 25px;
  box-shadow: 2px 2px 0 #b9d9e9;
}

.brand-mark:hover {
  animation: sticker-bob 900ms ease-in-out;
}

.brand h1,
.side-section h2,
.panel-title h2,
.card-head h2,
.eyebrow {
  margin: 0;
}

.brand h1 {
  font-size: 25px;
  line-height: 1.1;
}

.side-section {
  padding: 18px 0;
  border-top: 1px dashed var(--border);
}

.side-section:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.side-section h2 {
  margin-bottom: 12px;
  color: #5a8db5;
  font-size: 14px;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mode-btn,
.soft-btn,
.primary-btn,
.pink-btn,
.danger-btn,
.filter-btn,
.audio-btn {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  transition: transform 160ms ease, background-color 160ms ease;
}

.mode-btn,
.soft-btn,
.filter-btn,
.audio-btn {
  background: #f9f5eb;
}

.mode-btn:hover,
.soft-btn:hover,
.primary-btn:hover,
.pink-btn:hover,
.danger-btn:hover,
.filter-btn:hover,
.audio-btn:hover {
  transform: translateY(-1px);
}

.mode-btn.active,
.filter-btn.active {
  border-color: var(--blue-dark);
  color: #376785;
  background: var(--blue);
  box-shadow: 2px 2px 0 #b9d9e9;
}

.primary-btn {
  border-color: var(--blue-dark);
  color: #376785;
  background: var(--blue);
  box-shadow: 2px 2px 0 #b9d9e9;
  font-weight: 800;
}

.pink-btn {
  border-color: var(--pink-dark);
  color: #75515e;
  background: var(--pink);
  box-shadow: 2px 2px 0 #ead1d9;
  font-weight: 800;
}

.danger-btn {
  color: #8d4959;
  background: #f6e5e4;
}

.full {
  width: 100%;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.range-row label,
.slider-row,
.select-row {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.range-row input,
.select-row select,
.paste-box,
.answer-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: #fffdf6;
  outline: none;
}

.range-row input,
.select-row select {
  height: 40px;
  padding: 0 12px;
}

.range-row input:focus,
.select-row select:focus,
.paste-box:focus,
.answer-input:focus {
  border-color: var(--blue-dark);
  box-shadow: 0 0 0 3px #d4ecfb;
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.file-drop {
  display: grid;
  gap: 6px;
  padding: 16px;
  border: 1px dashed var(--blue-dark);
  border-radius: var(--radius-sm);
  background: #f3f2e9;
  text-align: center;
}

.file-drop span {
  font-weight: 800;
}

.file-drop small {
  color: var(--muted);
  line-height: 1.45;
}

.sr-only {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  clip: rect(0, 0, 0, 0);
}

.check-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
  color: var(--muted);
  font-size: 13px;
}

.paste-box {
  min-height: 112px;
  margin-bottom: 10px;
  padding: 12px;
  resize: vertical;
  line-height: 1.55;
}

.slider-row input {
  width: 100%;
  accent-color: var(--blue-dark);
}

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

.stat-card {
  min-height: 108px;
  padding: 18px;
  border-radius: var(--radius-md);
}

.stat-card:nth-child(even) {
  background-color: #f8f0ee;
}

.stat-card:nth-child(odd) {
  background-color: #f1f8fd;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  display: block;
  margin-top: 12px;
  color: #4a7ba0;
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1;
}

.practice-card {
  min-height: 680px;
  padding: clamp(20px, 3vw, 34px);
  border-radius: var(--radius-lg);
}

.card-head,
.panel-title,
.input-head,
.score-row,
.control-row,
.learn-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  color: #8f6977;
  font-size: 13px;
  font-weight: 800;
}

.card-head h2 {
  margin-top: 6px;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.16;
}

.progress-pill {
  flex: 0 0 auto;
  min-width: 84px;
  padding: 9px 14px;
  border: 1px solid #c9b1b8;
  border-radius: var(--radius-sm);
  color: #75515e;
  background: var(--pink);
  text-align: center;
  font-weight: 800;
}

.learn-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 24px 0 18px;
}

.filter-btn {
  min-height: 36px;
  padding: 0 14px;
  font-size: 13px;
}

.empty-state {
  display: none;
  place-items: center;
  min-height: 410px;
  padding: 34px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: #f5f1e8;
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 8px;
  font-size: 22px;
}

.empty-state span {
  max-width: 420px;
  color: var(--muted);
  line-height: 1.7;
}

.study-surface {
  display: grid;
  gap: 18px;
}

.prompt-block,
.answer-block,
.result-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fdfaf2;
}

.prompt-block {
  background: #e8f4fd;
  border-color: #a8d4e8;
}

.answer-block {
  background: #f9f1ef;
  border-color: #ddc7ca;
}

.prompt-block,
.answer-block {
  padding: clamp(18px, 2.3vw, 26px);
}

.block-label {
  display: inline-block;
  margin-bottom: 9px;
  color: #7c7771;
  font-size: 12px;
  font-weight: 900;
}

.cn-prompt {
  min-height: 116px;
  color: #4a6b8a;
  font-size: clamp(22px, 3vw, 36px);
  font-weight: 800;
  line-height: 1.42;
  white-space: pre-wrap;
}

.en-reference {
  color: #595561;
  font-size: clamp(18px, 2vw, 25px);
  line-height: 1.58;
  white-space: pre-wrap;
}

.answer-input {
  display: block;
  min-height: 190px;
  padding: 18px;
  resize: vertical;
  font-size: 18px;
  line-height: 1.6;
}

.audio-btn {
  min-height: 36px;
  padding: 0 14px;
  color: #4a7ba0;
  font-weight: 800;
}

.result-panel {
  display: none;
  padding: 18px;
}

.score-row {
  align-items: baseline;
  justify-content: flex-start;
}

.score-row strong {
  color: #5ba4cf;
  font-size: 38px;
}

.score-row span {
  color: var(--muted);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.metric-grid span {
  min-height: 42px;
  padding: 9px;
  border: 1px solid #d8d8ce;
  border-radius: var(--radius-sm);
  background: #e8f4fd;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.metric-grid b {
  color: var(--ink);
}

.diff-output,
.standard-answer {
  margin-top: 14px;
}

#diffOutput,
#standardAnswer {
  min-height: 48px;
  padding: 14px;
  border: 1px solid #e0d7ca;
  border-radius: var(--radius-sm);
  background: #fffdf6;
  line-height: 1.8;
  white-space: pre-wrap;
}

.token {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin: 3px 4px 3px 0;
  padding: 3px 9px;
  border-radius: 6px;
  font-weight: 800;
}

.token.correct {
  color: #346988;
  background: #d4ecfb;
}

.token.approx {
  color: #684f12;
  background: #f5e9bd;
}

.token.wrong {
  color: #7b263e;
  background: #efd0d7;
}

.token.extra {
  color: #7a3153;
  background: #f2dce2;
}

.token.missing {
  color: #315d86;
  background: #d4ecfb;
  border: 1px dashed #7999a6;
}

.token .mini {
  margin-left: 6px;
  color: #687479;
  font-size: 11px;
  font-weight: 700;
}

.learn-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.soft-btn,
.primary-btn,
.pink-btn,
.danger-btn {
  padding: 0 18px;
}

.control-row {
  justify-content: center;
  margin-top: 4px;
}

.control-row button,
.learn-actions button {
  min-width: 122px;
}

.book-card {
  padding: 18px;
  border-radius: var(--radius-md);
}

.book-card:nth-child(2) {
  background-color: #fcf5f0;
}

.panel-title {
  margin-bottom: 12px;
}

.panel-title h2 {
  font-size: 18px;
}

.panel-title span {
  color: var(--muted);
  font-size: 12px;
}

.book-list {
  display: grid;
  gap: 10px;
  max-height: 268px;
  overflow: auto;
  padding-right: 2px;
}

.book-item {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fffdf6;
  color: var(--ink);
  text-align: left;
}

.book-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-item span {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-empty {
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: #f4f0e8;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

#historyChart {
  display: block;
  width: 100%;
  height: 180px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fbf8ef;
}

.toast-container {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 20;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--paper);
  box-shadow: var(--shadow);
  color: var(--ink);
  animation: toast-in 180ms ease both;
}

.celebration-layer {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  pointer-events: none;
}

.celebration-layer canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.celebration-message {
  position: absolute;
  top: 39%;
  left: 50%;
  width: min(460px, calc(100vw - 36px));
  padding: 18px 22px;
  border: 2px solid var(--blue-dark);
  border-radius: var(--radius-lg);
  background: var(--paper);
  box-shadow: 5px 6px 0 #b9d9e9;
  color: #4a7ba0;
  font-size: clamp(23px, 4vw, 38px);
  font-weight: 900;
  text-align: center;
  animation: celebration-pop 420ms ease-out both;
}

.celebration-message span {
  display: block;
  margin-top: 5px;
  color: var(--pink-dark);
  font-size: 15px;
  font-weight: 700;
}

@keyframes celebration-pop {
  from { opacity: 0; transform: translate(-50%, -35%) scale(0.8); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hidden {
  display: none !important;
}

button:focus-visible,
.file-drop:focus-within {
  outline: 2px solid var(--blue-dark);
  outline-offset: 3px;
}

button:hover,
.book-item:hover,
.file-drop:hover {
  background-color: #e8f4fd;
}

button:active {
  transform: translateY(2px) scale(0.98);
}

.pink-btn:hover,
.danger-btn:hover {
  background-color: #ead0d6;
}

::placeholder {
  color: #9b9891;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .rightbar {
    grid-column: 1 / -1;
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-height: none;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(100% - 18px, 720px);
    margin: 9px auto;
  }

  .sidebar,
  .rightbar {
    position: static;
    max-height: none;
  }

  .rightbar {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .card-head,
  .input-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }

  .control-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .control-row button,
  .learn-actions button {
    width: 100%;
  }

  .cat-sticker {
    right: 14px;
    bottom: 14px;
  }
}

@media (max-width: 520px) {
  .stats-grid,
  .mode-grid,
  .range-row {
    grid-template-columns: 1fr;
  }

  .practice-card,
  .sidebar,
  .book-card {
    border-radius: 22px;
  }

  .cn-prompt {
    font-size: 22px;
  }

  .deco-heart,
  .deco-star-small {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .deco,
  .cat-sticker,
  .brand-mark:hover,
  .celebration-message {
    animation: none;
  }
}
