:root {
  --paper: #f3efe6;
  --paper-2: #fffdf8;
  --ink: #1e1a16;
  --ink-soft: #5e564c;
  --line: #e4d8c8;
  --red: #b4332a;
  --red-soft: #f6ddd8;
  --green: #1d6a45;
  --green-soft: #d7eddf;
  --shadow: 0 16px 40px rgba(60, 40, 20, 0.06);
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", "Songti SC", "Noto Serif SC", "Source Han Serif SC", serif;
  --sans: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(rgba(80, 50, 30, 0.045) 0.7px, transparent 0.7px);
  background-size: 8px 8px;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

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

button { cursor: pointer; }

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.top, #notice, main {
  width: min(40rem, calc(100% - 2rem));
  margin-left: auto;
  margin-right: auto;
}

.top { padding-top: 1.4rem; }

.brand-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-decoration: none;
}

.brand::before {
  content: "";
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-right: 0.45rem;
  border: 2px solid var(--red);
  border-radius: 50%;
  transform: translateY(-0.12rem);
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--ink-soft);
  font-family: var(--serif);
}

#logout {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  padding: 0.2rem;
}

.notice {
  margin-top: 1rem;
  padding: 0.75rem 0.9rem;
  background: var(--paper-2);
  border-left: 3px solid var(--red);
  color: var(--ink-soft);
  font-size: 0.92rem;
}

main { padding-top: 1.25rem; padding-bottom: 2rem; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 0.35rem 0.6rem calc(0.45rem + env(safe-area-inset-bottom));
  background: rgba(243, 239, 230, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.tabbar a {
  text-align: center;
  text-decoration: none;
  padding: 0.7rem 0.2rem;
  color: var(--ink-soft);
  letter-spacing: 0.12em;
}

.tabbar a[aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
}

h1, h2, p { margin-top: 0; }

h1 {
  font-family: var(--serif);
  font-size: 1.8rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.02em;
}

h2 {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
}

.kicker, .meta, .hint {
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
  color: var(--ink-soft);
}

.review-note {
  margin-bottom: 1rem;
  padding: 0.8rem 0.9rem;
  background: var(--green-soft);
}

.review-note a { font-weight: 600; }

.weak-panel { margin-bottom: 1rem; }

.weak-panel h2 { margin-bottom: 0.35rem; }

.weak-list { margin-top: 0.85rem; }

.weak-point {
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.weak-point:first-child { border-top: 0; padding-top: 0; }

.weak-point p { margin: 0.2rem 0 0; }

.weak-point a { font-weight: 600; text-decoration: none; }

.filters {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.filters button, .text-button, .ghost, .button, .danger {
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: transparent;
  padding: 0.55rem 0.95rem;
  line-height: 1.2;
}

.filters button[aria-selected="true"] {
  background: var(--ink);
  color: var(--paper);
}

.card-list { display: grid; gap: 0.8rem; }

.card, .panel, .result, .empty {
  background: var(--paper-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.card {
  display: block;
  padding: 0.95rem 1rem 1rem;
  text-decoration: none;
}

.card-top, .row, .actions, .result-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.7rem;
}

.card-top, .spread { justify-content: space-between; }

.topic {
  font-family: var(--serif);
  font-size: 1.15rem;
}

.preview {
  margin: 0.45rem 0 0;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.stamp {
  display: inline-block;
  border: 1.5px solid currentColor;
  padding: 0.05rem 0.4rem 0.08rem;
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  color: var(--red);
  transform: rotate(-8deg);
}

.stamp.mastered { color: var(--green); transform: rotate(-4deg); }

.dots { display: inline-flex; gap: 0.28rem; }

.dots i {
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 50%;
  border: 1.5px solid var(--red);
  display: block;
}

.dots i.on { background: var(--red); }

.empty, .panel { padding: 1.15rem 1.1rem 1.25rem; }

.stem, .choices {
  display: grid;
  gap: 0.45rem;
  margin: 0 0 0.95rem;
}

.choice {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: #fff;
  line-height: 1.45;
}

.choice-letter {
  flex: none;
  width: 1.25rem;
  font-weight: 650;
  color: var(--red);
}

.choice[aria-pressed="true"] {
  border-color: var(--red);
  background: var(--red-soft);
}

.prompt {
  margin: 0.8rem 0;
  padding: 0.35rem 0.2rem 0.35rem 0.9rem;
  border-left: 2px solid var(--red);
  background-color: rgba(255, 253, 248, 0.7);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 1.85rem,
    rgba(180, 80, 60, 0.16) 1.9rem
  );
  font-family: var(--serif);
  font-size: 1.12rem;
  line-height: 1.9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.photo {
  display: block;
  width: 100%;
  max-height: 18rem;
  object-fit: contain;
  background: #efe8dc;
  margin-bottom: 0.9rem;
}

label { display: block; margin-bottom: 0.75rem; }

label span, .field-label {
  display: block;
  margin-bottom: 0.28rem;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: #fff;
  font-size: 16px;
}

textarea { min-height: 6.5rem; resize: vertical; line-height: 1.5; }

.actions, .result-actions { margin-top: 0.9rem; }

.button {
  display: inline-block;
  text-decoration: none;
  background: var(--red);
  border-color: var(--red);
  color: white;
}

.button:disabled, .ghost:disabled, .danger:disabled { opacity: 0.55; cursor: wait; }

.ghost { background: transparent; }

.danger { border-color: var(--red); color: var(--red); }

.capture-actions, .file-row { display: grid; gap: 0.7rem; }

.file-button {
  display: block;
  text-align: center;
  padding: 0.95rem 1rem;
  border-radius: 999px;
  text-decoration: none;
}

.file-button input { display: none; }

.file-button.primary {
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
}

.file-button.secondary {
  border: 1px solid var(--ink);
}

.error {
  padding: 0.75rem 0.85rem;
  background: var(--red-soft);
  color: #6d221c;
  margin-bottom: 0.9rem;
}

.busy { color: var(--ink-soft); }

.block { margin: 0.85rem 0; }

.block p { margin: 0.25rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.result.good { background: var(--green-soft); }
.result.bad { background: var(--red-soft); }

.mastered-line {
  font-family: var(--serif);
  font-size: 1.7rem;
  line-height: 1.3;
  margin-bottom: 0.4rem;
}

.variant {
  padding: 0.85rem 0;
  border-top: 1px solid var(--line);
}

.variant:first-of-type { border-top: 0; }

.pill {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background: #efe6d8;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.unlock {
  max-width: 22rem;
  margin-top: 2rem;
}

@media (min-width: 840px) {
  body { padding-bottom: 2rem; }

  .tabbar {
    position: static;
    width: min(40rem, calc(100% - 2rem));
    margin: 1rem auto 0;
    padding: 0.2rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 253, 248, 0.8);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
