@import url('https://fonts.googleapis.com/css2?family=B612:wght@400;700&family=B612+Mono&display=swap');

:root {
  --cream: #FDF6E3;
  --cream-dark: #F5EBCF;
  --red: #C0392B;
  --red-dark: #A93226;
  --red-light: #F2D4D0;
  --text: #2C1810;
  --text-sec: #6B5B4F;
  --text-lt: #9B8A7E;
  --border: #E8DCC8;
  --white: #FFF;
  --shadow: 0 1px 3px rgba(44, 24, 16, .08);
  --shadow-lg: 0 4px 12px rgba(44, 24, 16, .12);
  --r: 10px;
  --mw: 720px;
  --nh: 54px;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  overflow-x: hidden;
}

body {
  font-family: 'B612', monospace, sans-serif;
  background: var(--cream);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow: hidden;
  overflow-x: hidden;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Navigation ── */

.nav-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--red);
  color: var(--white);
  padding-top: var(--st);
  box-shadow: 0 2px 8px rgba(44, 24, 16, .2);
  flex-shrink: 0;
}

.nav-inner {
  display: flex;
  align-items: center;
  height: var(--nh);
  max-width: var(--mw);
  margin: 0 auto;
  padding: 0 12px;
  gap: 8px;
  position: relative;
}

.nav-version {
  font-size: 10px;
  font-family: 'B612 Mono', monospace;
  color: rgba(255, 255, 255, 0.55);
  min-width: 44px;
  text-align: right;
  flex-shrink: 0;
  pointer-events: none;
}

.nav-back {
  display: flex;
  align-items: center;
  gap: 2px;
  background: 0;
  border: 0;
  color: var(--white);
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  padding: 8px 4px;
  min-width: 44px;
  min-height: 44px;
  opacity: .9;
  transition: opacity .15s;
}
.nav-back:active { opacity: .6; }
.nav-back.hidden { visibility: hidden; pointer-events: none; }

.nav-title {
  flex: 1;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.nav-action {
  position: absolute;
  right: 12px;
  background: 0;
  border: 0;
  color: var(--white);
  cursor: pointer;
  padding: 8px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: .9;
  transition: opacity .15s;
}
.nav-action:active { opacity: .6; }
.nav-action.hidden { display: none; }

/* ── Content ── */

.content {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.content-inner {
  max-width: var(--mw);
  margin: 0 auto;
  padding: 0 0 calc(20px + var(--sb));
  overflow-x: hidden;
}

/* ── Loading ── */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 12px;
  color: var(--text-sec);
  text-align: center;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-status {
  font-size: 13px;
  color: var(--text-lt);
}

/* ── Info Banner ── */

.info-banner {
  margin: 12px 12px 4px;
  padding: 12px 14px;
  background: var(--white);
  border-left: 3px solid var(--red);
  border-radius: var(--r);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-sec);
}
.info-banner strong { color: var(--text); }

/* ── Part List ── */

.part-list {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.part-group-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-lt);
  text-transform: uppercase;
  letter-spacing: .6px;
  padding: 12px 4px 4px;
}

.part-card {
  background: var(--white);
  border-radius: var(--r);
  padding: 12px 14px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform .1s, box-shadow .15s;
  display: flex;
  align-items: center;
  gap: 10px;
}
.part-card:active { transform: scale(.985); box-shadow: var(--shadow); }
.part-card.key-part { border-left: 3px solid var(--red); }

.part-number {
  background: var(--red);
  color: var(--white);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 5px;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 36px;
  text-align: center;
}
.part-card:not(.key-part) .part-number { background: var(--text-lt); }

.part-name { font-size: 13px; line-height: 1.35; flex: 1; min-width: 0; color: var(--text); }
.part-meta { font-size: 11px; color: var(--text-lt); white-space: nowrap; flex-shrink: 0; }
.part-chevron { flex-shrink: 0; color: var(--text-lt); }

/* ── Section / Appendix Rows ── */

.subpart-header {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 14px 16px 6px;
  position: sticky;
  top: 0;
  background: var(--cream);
  z-index: 5;
}

.section-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.section-row:active { background: var(--cream-dark); }

.section-id {
  font-size: 12px;
  font-weight: 700;
  color: var(--red);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 68px;
  font-family: 'B612 Mono', monospace;
}
.section-title { font-size: 13px; line-height: 1.35; flex: 1; min-width: 0; color: var(--text); }

.appendix-divider {
  font-size: 11px;
  font-weight: 700;
  color: var(--red-dark);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 16px 16px 6px;
  border-top: 2px solid var(--border);
  margin-top: 8px;
}

.appendix-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.appendix-row:active { background: var(--cream-dark); }
.appendix-title { font-size: 13px; line-height: 1.35; flex: 1; min-width: 0; color: var(--text); }

/* ── Detail View ── */

.detail-view { padding: 16px; }

.detail-header {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--red);
}

.detail-id {
  font-size: 20px;
  font-weight: 700;
  color: var(--red);
  margin-bottom: 4px;
  font-family: 'B612 Mono', monospace;
}
.detail-title { font-size: 15px; font-weight: 700; line-height: 1.35; }
.detail-part { font-size: 12px; color: var(--text-sec); margin-top: 6px; }

.reg-text { font-size: 14px; line-height: 1.7; }
.reg-text p { margin-bottom: 6px; }
.reg-text p:last-child { margin-bottom: 0; }
.reg-text .indent-1 { padding-left: 20px; }
.reg-text .indent-2 { padding-left: 40px; }
.reg-text .indent-3 { padding-left: 56px; }
.reg-text .indent-4 { padding-left: 72px; }

/* ── Search ── */

.search-container {
  padding: 12px 16px;
  position: sticky;
  top: 0;
  background: var(--cream);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: var(--r);
  padding: 0 12px;
  transition: border-color .15s;
}
.search-input-wrap:focus-within { border-color: var(--red); }
.search-input-wrap svg { flex-shrink: 0; color: var(--text-lt); }

.search-input {
  flex: 1;
  border: 0;
  background: 0;
  font-family: inherit;
  font-size: 15px;
  padding: 12px 10px;
  color: var(--text);
  outline: 0;
}
.search-input::placeholder { color: var(--text-lt); }

.search-clear {
  background: 0;
  border: 0;
  color: var(--text-lt);
  cursor: pointer;
  padding: 4px;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-scope {
  display: flex;
  gap: 6px;
  padding: 8px 0 0;
}

.scope-btn {
  flex: 1;
  padding: 7px 8px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  background: 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sec);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  min-height: 36px;
}
.scope-btn.active {
  background: var(--red);
  border-color: var(--red);
  color: var(--white);
}

.search-meta { font-size: 12px; color: var(--text-sec); padding: 8px 0 0; }

.search-result-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.search-result-item:active { background: var(--cream-dark); }

.search-result-id {
  font-size: 12px;
  font-weight: 700;
  color: var(--red);
  font-family: 'B612 Mono', monospace;
}
.search-result-title { font-size: 13px; font-weight: 700; margin-top: 2px; line-height: 1.3; }
.search-result-snippet { font-size: 12px; color: var(--text-sec); margin-top: 4px; line-height: 1.4; }
.search-result-snippet mark {
  background: var(--red-light);
  color: var(--text);
  padding: 1px 2px;
  border-radius: 2px;
}
.search-result-part { font-size: 11px; color: var(--text-lt); margin-top: 4px; }

/* ── Empty State ── */

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-sec); }
.empty-state svg { color: var(--text-lt); margin-bottom: 12px; }
.empty-state p { font-size: 14px; line-height: 1.5; }

/* ── Tab Bar ── */

.tab-bar {
  display: flex;
  background: var(--white);
  border-top: 1px solid var(--border);
  padding-bottom: var(--sb);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 0 6px;
  border: 0;
  background: 0;
  cursor: pointer;
  color: var(--text-lt);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  transition: color .15s;
  min-height: 50px;
}
.tab.active { color: var(--red); }
.tab:active { opacity: .7; }

/* ── Scroll-to-top ── */

.scroll-top {
  position: fixed;
  bottom: calc(70px + var(--sb));
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--red);
  color: var(--white);
  border: 0;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 50;
}
.scroll-top.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.scroll-top:active { transform: scale(.9); }

/* ── Utilities ── */

.hidden { display: none !important; }
