:root {
  --paper: #f3efe4;
  --ink: #1a1814;
  --muted: #6d675c;
  --line: #e2d9c8;
  --card: #fffdf8;
  --accent: #1f4d3a;
  --accent-soft: #e7f2ec;
  --mark: #8c3a2f;
  --mark-soft: #f8ebe7;
  --shadow: 0 10px 30px rgba(40, 32, 20, 0.06);
  color-scheme: light;
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Songti SC", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.45;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

#app {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.brand {
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
}
.brand strong {
  display: block;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}
.brand span { color: var(--muted); font-size: 0.82rem; }

.langs {
  display: flex;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.langs button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
}
.langs button.is-on {
  background: var(--accent);
  color: #fff;
}

h1 {
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  margin: 0 0 6px;
}
.lead { margin: 0 0 16px; color: var(--muted); }

.card, .group, .composer, .q-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 16px;
  margin-bottom: 10px;
}
.card b { display: block; font-size: 1.05rem; }
.card small { color: var(--muted); }

.composer, .group { padding: 14px; margin-bottom: 14px; }
.row { display: flex; gap: 8px; }
.row input, .rename input {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  min-width: 0;
}
.btn {
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  white-space: nowrap;
}
.btn--ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn--mark { background: var(--mark); }
.btn--block { width: 100%; margin-top: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.group h2 { margin: 0; font-size: 1.05rem; }
.group-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.hint { color: var(--muted); font-size: 0.86rem; margin: 8px 0; }

.photos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.photo {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  border: 0;
  padding: 0;
  background: #ece6da;
}
.photo > .photo {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border-radius: 0;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .x {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 16, 12, 0.72);
  color: #fff;
}
.file {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--accent);
  color: var(--accent);
  border-radius: 12px;
  padding: 12px;
  width: 100%;
  background: var(--accent-soft);
}
.file input { display: none; }

.lesson-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Iowan Old Style", Palatino, "Songti SC", "PingFang SC", serif;
  font-size: 1.02rem;
  line-height: 1.65;
  background: #faf7f1;
  border-radius: 12px;
  padding: 14px;
}
.empty-text {
  margin: 0;
  color: var(--muted);
  background: #faf7f1;
  border-radius: 12px;
  padding: 14px;
}

.q-card { padding: 18px; }
.progress { color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; }
.q-card h2 { margin: 0 0 14px; font-size: 1.25rem; line-height: 1.4; }
.choice {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}
.choice.is-right { background: var(--accent-soft); border-color: var(--accent); }
.choice.is-wrong { background: var(--mark-soft); border-color: var(--mark); }
.choice:disabled { cursor: default; }
.explain {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: #faf7f1;
}
.score { font-size: 2rem; letter-spacing: -0.04em; margin: 8px 0; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(12, 10, 8, 0.92);
  display: grid;
  place-items: center;
  padding: 16px;
}
.lightbox img { max-width: 100%; max-height: 92vh; object-fit: contain; }
.lightbox button {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  border: 0;
  background: #fff;
  border-radius: 999px;
  padding: 8px 12px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  z-index: 40;
}
#toast[hidden] { display: none; }

.rename { margin-bottom: 12px; }
.linkish {
  border: 0;
  background: none;
  color: var(--muted);
  padding: 8px 0;
}
