:root {
  --paper: #f3eee4;
  --card: #fffdf8;
  --ink: #241910;
  --soft: #6a5d51;
  --line: #e4d8c6;
  --cinnabar: #a33b2b;
  --cinnabar-deep: #7d2a1e;
  --moss: #24664a;
  --amber: #8a5a12;
  --shadow: 0 12px 32px rgba(70, 42, 22, 0.08);
  --safe-b: env(safe-area-inset-bottom);
  --tab: calc(64px + var(--safe-b));
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #d7cec0;
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

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

button { cursor: pointer; }

.app {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  background:
    linear-gradient(90deg, transparent 18px, rgba(163, 59, 43, 0.28) 18px, rgba(163, 59, 43, 0.28) 19px, transparent 19px),
    var(--paper);
  display: flex;
  flex-direction: column;
  position: relative;
}

main {
  flex: 1;
  padding: 20px 20px var(--tab);
}

.view { display: none; }
.view.is-on { display: block; }

.mast { padding: 8px 8px 0 12px; }
.mast.compact { padding-bottom: 8px; }

.eyebrow {
  margin: 0 0 6px;
  color: var(--cinnabar);
  font-size: 13px;
  letter-spacing: 0.08em;
}

h1, h2, h3 { font-family: "Iowan Old Style", "Palatino Linotype", "Songti SC", "Noto Serif SC", "STSong", serif; font-weight: 650; }

h1 { margin: 0; font-size: 34px; letter-spacing: -0.03em; }
h2 { margin: 0; font-size: 22px; }
h3 { margin: 0 0 6px; font-size: 20px; }

.lede, .fine, .bank-line, .ocr-line { color: var(--soft); }
.lede { margin: 8px 0 0; font-size: 15px; }
.fine { margin: 14px 8px 0 12px; font-size: 12px; line-height: 1.6; }
.bank-line, .ocr-line { margin: 16px 8px 0 12px; font-size: 13px; }
.ocr-line.warn { color: var(--amber); }

.finder { margin: 22px 8px 0 12px; }
.finder-frame {
  position: relative;
  min-height: 168px;
  border-radius: 18px;
  background: rgba(255, 253, 248, 0.55);
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
  color: var(--soft);
}
.finder-frame span {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid var(--cinnabar);
}
.finder-frame span:nth-child(1) { top: 10px; left: 10px; border-right: 0; border-bottom: 0; }
.finder-frame span:nth-child(2) { top: 10px; right: 10px; border-left: 0; border-bottom: 0; }
.finder-frame span:nth-child(3) { bottom: 10px; left: 10px; border-right: 0; border-top: 0; }
.finder-frame span:nth-child(4) { bottom: 10px; right: 10px; border-left: 0; border-top: 0; }
.finder-frame p { margin: 0; max-width: 14em; }

.actions { display: flex; flex-direction: column; gap: 10px; margin: 18px 8px 0 12px; }

.primary, .ghost, .quiet, .back, .chip, .texty {
  border: 0;
  background: transparent;
}

.primary, .ghost {
  min-height: 52px;
  border-radius: 999px;
  padding: 0 18px;
}

.primary {
  background: var(--cinnabar-deep);
  color: #fffdf8;
  font-size: 17px;
  font-weight: 650;
  box-shadow: 0 8px 18px rgba(125, 42, 30, 0.22);
}

.primary:active { transform: translateY(1px); }

.ghost {
  background: transparent;
  color: var(--cinnabar-deep);
  border: 1px solid rgba(125, 42, 30, 0.35);
}

.quiet {
  color: var(--soft);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 6px;
}

.subhead {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px 4px;
}

.back {
  color: var(--cinnabar-deep);
  padding: 6px 2px;
  font-size: 14px;
}

.shot {
  margin: 0 4px 0 8px;
  background: var(--card);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.shot img { display: block; width: 100%; max-height: 52dvh; object-fit: contain; background: #1c1612; }

.field-label { display: block; margin: 12px 8px 8px 12px; font-size: 13px; color: var(--soft); }

textarea {
  display: block;
  width: calc(100% - 20px);
  margin-left: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  padding: 12px 14px;
  resize: vertical;
  min-height: 150px;
  line-height: 1.55;
}

textarea:focus { outline: 2px solid rgba(163, 59, 43, 0.35); border-color: transparent; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 12px 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  min-width: 42px;
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.chip.on {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.banner {
  margin: 0 8px 12px 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f4e4c8;
  color: #6a4310;
  font-size: 14px;
}

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 14px 14px 12px;
  margin: 0 4px 12px 8px;
  box-shadow: var(--shadow);
}

.kicker {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--soft);
  letter-spacing: 0.04em;
}

.level {
  display: inline-block;
  margin: 8px 0 0;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #efe4d4;
}

.level.high { background: #dcecde; color: var(--moss); }
.level.mid { background: #f4e4c8; color: var(--amber); }
.level.low { background: #f6d9d4; color: var(--cinnabar-deep); }

.reasons { margin: 8px 0 0; padding: 0; list-style: none; color: var(--soft); font-size: 14px; }
.reasons li { margin: 2px 0; }

.candidates { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.candidate {
  text-align: left;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 12px;
  padding: 10px 12px;
}
.candidate.on { border-color: var(--cinnabar); background: #fbf4ee; }
.candidate small { display: block; color: var(--soft); }

.prereq { padding: 8px 0; border-top: 1px solid var(--line); }
.prereq:first-of-type { border-top: 0; }
.prereq strong { font-weight: 650; }
.tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #f6d9d4;
  color: var(--cinnabar-deep);
}
.tag.soft { background: #efe4d4; color: var(--soft); }

.q-head { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.pill {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #efe7da;
}
.prompt { margin: 0 0 8px; white-space: pre-wrap; }
.choices { margin: 0 0 8px; padding-left: 1.1em; }
.reveal {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}
.reveal p { margin: 4px 0; }

.search-row { display: flex; gap: 8px; }
.search-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  padding: 10px 12px;
}
.texty {
  color: var(--cinnabar-deep);
  padding: 8px 4px;
  font-size: 14px;
}

.book-card, .domain-row { width: calc(100% - 12px); }

.book-card {
  display: block;
  text-align: left;
  margin: 0 4px 10px 8px;
  padding: 12px 14px;
  border: 0;
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.book-card p { margin: 4px 0 0; color: var(--soft); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.filters { margin-bottom: 12px; }

.numbers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 4px 14px 8px; }
.numbers div {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
  box-shadow: var(--shadow);
}
.numbers strong { display: block; font-size: 26px; font-family: "Iowan Old Style", "Songti SC", serif; }
.numbers span { color: var(--soft); font-size: 12px; }

.bar-row { display: grid; grid-template-columns: minmax(0, 9em) 1fr 2em; gap: 8px; align-items: center; margin: 7px 8px 7px 12px; font-size: 13px; }
.bar-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 8px; background: #e7dccb; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--cinnabar); border-radius: 99px; }
.week { display: flex; align-items: flex-end; gap: 6px; height: 72px; margin: 8px 8px 0 12px; }
.week span { flex: 1; background: #e7b2a4; border-radius: 6px 6px 2px 2px; min-height: 4px; }
.week-labels { display: flex; gap: 6px; margin: 4px 8px 0 12px; }
.week-labels em { flex: 1; text-align: center; font-style: normal; font-size: 10px; color: var(--soft); }

.empty { margin: 12px 8px 0 12px; color: var(--soft); }

.detail-photo { width: calc(100% - 12px); margin: 0 4px 12px 8px; border-radius: 16px; display: block; }

.tabs {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(243, 238, 228, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  z-index: 5;
}
.tabs button {
  border: 0;
  background: transparent;
  padding: 8px 0 10px;
  color: var(--soft);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
}
.tabs button.on { color: var(--cinnabar-deep); font-weight: 650; }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs em {
  position: absolute;
  top: 4px;
  margin-left: 28px;
  background: var(--cinnabar);
  color: white;
  border-radius: 99px;
  font-style: normal;
  font-size: 10px;
  min-width: 16px;
  padding: 0 4px;
  line-height: 16px;
}

#busy[hidden], #toast:empty { display: none; }
#busy {
  position: absolute;
  inset: 0;
  background: rgba(36, 25, 16, 0.28);
  display: grid;
  place-items: center;
  z-index: 8;
}
.busy-card {
  background: var(--card);
  border-radius: 16px;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}
.busy-card p { margin: 0; }
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--cinnabar);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--tab) + 8px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 9;
  max-width: 80%;
  text-align: center;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.source { font-size: 12px; color: var(--soft); }
.source a { color: var(--cinnabar-deep); }
