:root {
  color-scheme: light;
  --bg: #f7f4ec;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --text: #18312a;
  --muted: #65716b;
  --line: #dce3da;
  --green: #165640;
  --green-strong: #0d4633;
  --green-soft: #e8f1eb;
  --amber: #9a5a08;
  --amber-soft: #fff2d8;
  --blue-soft: #eaf2f7;
  --shadow: 0 16px 40px rgba(27, 54, 44, 0.08);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 11px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #17201d;
  --surface: #202b27;
  --surface-strong: #26332e;
  --text: #eff7f2;
  --muted: #aebcb5;
  --line: #3b4b44;
  --green: #86cbb0;
  --green-strong: #b2e2cf;
  --green-soft: #293e35;
  --amber: #f0bd69;
  --amber-soft: #493a23;
  --blue-soft: #293a43;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.58;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

.shell {
  width: min(100% - 32px, 980px);
  margin-inline: auto;
}

.topbar {
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}

.topbar-inner {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
}

.brand img {
  border-radius: 10px;
}

.brand span {
  display: grid;
  line-height: 1.2;
}

.brand strong {
  font-size: 20px;
  letter-spacing: -0.02em;
}

.brand small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  font-size: 22px;
}

.search-panel {
  position: sticky;
  z-index: 20;
  top: 0;
  padding: 16px 0 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(16px);
}

.search-box {
  height: 54px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 0 10px 0 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  box-shadow: 0 8px 24px rgba(34, 63, 53, 0.05);
}

.search-box:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 18%, transparent);
}

.search-box > span {
  color: var(--green);
  font-size: 28px;
  line-height: 1;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 17px;
}

.search-box input::placeholder {
  color: var(--muted);
}

.search-box button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green-strong);
  cursor: pointer;
  font-size: 24px;
}

.quick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.jump-tools {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-jump,
.question-jump {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-jump label,
.question-jump label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.page-jump input,
.question-jump select {
  width: 70px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
  color: var(--text);
  text-align: center;
}

.question-jump select {
  width: min(250px, 31vw);
  min-width: 150px;
  padding: 0 34px 0 11px;
  color: var(--text);
  text-align: left;
}

.page-jump button,
.question-jump button,
.surprise-button,
.empty-state button,
.load-more {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--green);
  color: #fff;
  padding: 0 16px;
  font-weight: 750;
  cursor: pointer;
}

.page-jump button:disabled,
.question-jump button:disabled,
.question-jump select:disabled {
  cursor: default;
  opacity: 0.55;
}

.surprise-button {
  background: var(--surface);
  color: var(--green-strong);
  border: 1px solid var(--line);
}

.filters {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar {
  display: none;
}

.filter {
  min-height: 40px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 0 15px;
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
}

.filter.is-active {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.filter-warning.is-active {
  border-color: var(--amber);
  background: var(--amber);
}

.main-content {
  padding-top: 22px;
  padding-bottom: calc(112px + var(--safe-bottom));
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--amber) 30%, var(--line));
  border-radius: var(--radius-md);
  background: var(--amber-soft);
  color: var(--text);
  font-size: 14px;
}

.notice > span {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--amber);
  color: #fff;
  font-weight: 800;
}

.notice p {
  margin: 0;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin: 28px 0 18px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 38px);
  line-height: 1.15;
  letter-spacing: -0.035em;
}

.page-heading p:last-child {
  max-width: 680px;
  margin: 8px 0 0;
  color: var(--muted);
}

.result-count {
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-strong);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 800;
}

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

.answer-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  scroll-margin-top: 220px;
}

.answer-card.is-target {
  border-color: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 17%, transparent), var(--shadow);
}

.card-meta,
.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card-meta p {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.status-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-strong);
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 850;
}

.status-pill.provisional {
  background: var(--amber-soft);
  color: var(--amber);
}

.answer-block {
  margin-top: 15px;
}

.question-block {
  margin-top: 15px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface) 84%, var(--blue-soft));
}

.question-label {
  display: block;
  margin-bottom: 5px;
  color: var(--green-strong);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.question-text,
.question-translation {
  margin: 0;
  overflow-wrap: anywhere;
}

.question-translation {
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
}

.question-source {
  display: inline-block;
  margin-top: 9px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 750;
}

.question-source.reviewed-source,
.question-source.image-compared {
  color: var(--green-strong);
}

.options {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.option {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.option.is-answer {
  color: var(--green-strong);
  font-weight: 750;
}

.option-key {
  display: inline-block;
  min-width: 22px;
}

.option-translation {
  color: var(--muted);
  font-weight: 400;
}

.question-unavailable {
  margin-top: 15px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--blue-soft);
  color: var(--muted);
  font-size: 14px;
}

.answer-block small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.answer-text {
  margin: 4px 0 0;
  color: var(--green-strong);
  font-size: clamp(22px, 4vw, 29px);
  font-weight: 850;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.answer-block .answer-translation-label {
  margin-top: 12px;
}

.answer-translation {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.context-details {
  margin-top: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.context-details summary {
  min-height: 46px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: var(--green-strong);
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}

.context-text {
  max-height: 56vh;
  margin: 0;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
}

.reason {
  margin: 16px 0 0;
  padding: 14px 15px;
  border-radius: var(--radius-md);
  background: var(--green-soft);
}

.reason-label {
  display: block;
  margin-bottom: 5px;
  color: var(--green-strong);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.reason p {
  margin: 0;
}

.solution-steps {
  margin: 6px 0 0;
  padding-left: 22px;
  color: var(--text);
  font-size: 15px;
}

.solution-steps li + li {
  margin-top: 3px;
}

.missing-reason {
  background: var(--blue-soft);
  color: var(--muted);
}

.source-details {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.source-details summary {
  min-height: 40px;
  display: flex;
  align-items: center;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
}

.source-details p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.card-actions {
  margin-top: auto;
  padding-top: 14px;
}

.card-actions button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--green-strong);
  padding: 0 13px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
}

.card-id {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.load-more {
  display: block;
  margin: 22px auto 0;
}

.empty-state {
  padding: 54px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
  text-align: center;
  color: var(--muted);
}

.empty-state > span {
  font-size: 42px;
}

.empty-state h2 {
  margin: 8px 0 4px;
  color: var(--text);
}

.empty-state p {
  margin: 0 0 18px;
}

.ocr-preview {
  margin: 24px auto 20px;
  max-width: 860px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  text-align: left;
}

.ocr-preview h3 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
}

.ocr-warning {
  margin: 7px 0 13px !important;
  color: var(--amber);
  font-size: 13px;
}

.ocr-preview pre {
  max-height: 68vh;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 14px/1.58 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
}

.book-nav {
  position: fixed;
  z-index: 25;
  right: 0;
  bottom: 0;
  left: 0;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(16px);
  padding-bottom: var(--safe-bottom);
}

.book-nav-inner {
  min-height: 70px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.book-nav button {
  min-height: 46px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--green-strong);
  cursor: pointer;
  font-weight: 800;
}

.book-nav button:first-child {
  text-align: left;
}

.book-nav button:last-child {
  text-align: right;
}

.book-nav button:disabled {
  color: var(--muted);
  opacity: 0.45;
}

.book-nav strong {
  white-space: nowrap;
  font-size: 14px;
}

.toast {
  position: fixed;
  z-index: 40;
  right: 20px;
  bottom: calc(88px + var(--safe-bottom));
  max-width: min(360px, calc(100% - 40px));
  border-radius: var(--radius-md);
  background: var(--text);
  color: var(--bg);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 700;
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 24px, 980px);
  }

  .topbar-inner {
    min-height: 68px;
  }

  .brand strong {
    font-size: 18px;
  }

  .search-panel {
    padding-top: 10px;
  }

  .answer-list {
    grid-template-columns: 1fr;
  }

  .answer-card {
    padding: 17px;
    border-radius: 20px;
    scroll-margin-top: 250px;
  }

  .page-heading {
    align-items: flex-start;
    margin-top: 22px;
  }

  .page-heading p:last-child {
    font-size: 15px;
  }

  .result-count {
    margin-top: 4px;
  }
}

@media (max-width: 430px) {
  .quick-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .jump-tools {
    display: contents;
  }

  .page-jump {
    grid-column: 1;
    grid-row: 1;
  }

  .question-jump {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .page-jump input {
    width: 58px;
  }

  .page-jump button,
  .question-jump button,
  .surprise-button {
    padding-inline: 12px;
  }

  .question-jump select {
    width: 100%;
    min-width: 0;
  }

  .surprise-button {
    grid-column: 2;
    grid-row: 1;
  }

  .book-nav-inner {
    gap: 4px;
  }

  .book-nav button {
    font-size: 14px;
  }
}

@media (max-width: 370px) {
  .page-jump input {
    width: 50px;
  }
}
