/* State of San Andreas Penal Code */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f6f6;
  --ink: #111111;
  --ink-2: #404040;
  --ink-3: #737373;
  --rule: #e5e5e5;
  --rule-strong: #c8c8c8;
  --mark-bg: #e5e5e5;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", Times, serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --topbar-h: 54px;
  --sidebar-w: 248px;
}

[data-theme="dark"] {
  --bg: #111111;
  --bg-soft: #1a1a1a;
  --ink: #ededed;
  --ink-2: #b8b8b8;
  --ink-3: #808080;
  --rule: #262626;
  --rule-strong: #3d3d3d;
  --mark-bg: #333333;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 20px);
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}

.topbar-inner {
  max-width: 1180px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

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

.brand-seal {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.brand-name {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 400px;
  margin-left: auto;
}

.search-input {
  width: 100%;
  height: 34px;
  padding: 0 28px 0 10px;
  border: none;
  border-bottom: 1px solid var(--rule-strong);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
}

.search-input::placeholder {
  color: var(--ink-3);
}

.search-input:focus {
  border-bottom-color: var(--ink);
}

.search-input::-webkit-search-cancel-button {
  display: none;
}

.search-clear {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--ink-3);
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
}

.search-clear:hover {
  color: var(--ink);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.text-btn {
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  padding: 4px 0;
  cursor: pointer;
}

.text-btn:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.calc-count {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink);
}

.mobile-menu-btn,
.sidebar-close-btn {
  display: none;
}

/* Page Shell */
.page-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 36px 24px 80px;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 56px;
  align-items: start;
}

/* Sidebar TOC */
.sidebar {
  position: sticky;
  top: calc(var(--topbar-h) + 28px);
  max-height: calc(100vh - var(--topbar-h) - 48px);
  overflow-y: auto;
  padding-right: 12px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

.toc-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toc-link {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  text-decoration: none;
  color: var(--ink-3);
  font-size: 13.5px;
  line-height: 1.4;
}

.toc-link:hover {
  color: var(--ink);
}

.toc-link.active {
  color: var(--ink);
  font-weight: 600;
}

.toc-link.dimmed {
  opacity: 0.35;
}

.toc-roman {
  font-family: var(--font-mono);
  font-size: 11px;
  margin-right: 6px;
  color: var(--ink-3);
}

.toc-link.active .toc-roman {
  color: var(--ink);
}

.toc-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-3);
  flex-shrink: 0;
}

/* Main Content */
.content-area {
  min-width: 0;
  max-width: 74ch;
}

/* Document Header */
.doc-header {
  padding-bottom: 24px;
  margin-bottom: 40px;
  border-bottom: 1px solid var(--rule);
}

.doc-header-row {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}

.doc-seal {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}

.doc-title {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.02em;
}

.doc-meta {
  margin: 0;
  font-size: 13.5px;
  color: var(--ink-3);
}

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.tab {
  border: none;
  background: transparent;
  padding: 4px 0;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink-3);
  cursor: pointer;
  border-bottom: 1.5px solid transparent;
}

.tab:hover {
  color: var(--ink);
}

.tab.active {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--ink);
}

.results-summary {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-3);
}

/* Titles & Chapters */
.code-container {
  display: flex;
  flex-direction: column;
  gap: 56px;
}

.title-block {
  scroll-margin-top: calc(var(--topbar-h) + 20px);
}

.title-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--ink);
}

.title-roman {
  display: block;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 2px;
}

.title-heading {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(21px, 2.3vw, 26px);
  font-weight: 700;
  line-height: 1.2;
}

.chapter-block {
  margin-top: 32px;
}

.chapter-block:first-of-type {
  margin-top: 0;
}

.chapter-heading {
  margin: 0 0 18px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

/* Simple Tables */
.ref-section {
  margin: 0 0 28px;
}

.ref-section-trailing {
  margin: 32px 0 0;
}

.ref-heading {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

.ref-subblock {
  margin-top: 16px;
}

.ref-subblock h4 {
  margin: 0 0 4px;
  font-size: 14.5px;
  font-weight: 600;
}

.ref-subblock p {
  margin: 0 0 8px;
  color: var(--ink-2);
  font-size: 14px;
}

.simple-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.simple-table tr {
  border-bottom: 1px solid var(--rule);
}

.simple-table td {
  padding: 7px 0;
  vertical-align: top;
}

.simple-table td:first-child {
  color: var(--ink-2);
  padding-right: 16px;
}

.simple-table td:last-child {
  font-family: var(--font-mono);
  font-size: 13.5px;
  text-align: right;
  color: var(--ink);
}

/* Preliminary Provisions */
.prelim-list {
  display: flex;
  flex-direction: column;
}

.prelim-item {
  padding: 18px 0;
  border-bottom: 1px solid var(--rule);
}

.prelim-item:first-child {
  padding-top: 0;
}

.prelim-item:last-child {
  border-bottom: none;
}

.prelim-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}

.sec-num {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
  text-decoration: none;
  flex-shrink: 0;
}

.sec-num:hover {
  color: var(--ink);
}

.prelim-title,
.statute-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

.prelim-item p,
.statute-desc {
  margin: 0 0 8px;
  color: var(--ink-2);
  font-size: 14.5px;
}

.prelim-item p:last-child,
.statute-desc:last-child {
  margin-bottom: 0;
}

.def-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--ink-2);
  font-size: 14.5px;
}

.def-list li {
  margin-bottom: 5px;
}

.def-term {
  font-weight: 600;
  color: var(--ink);
}

.prelim-group {
  margin-top: 12px;
  padding-left: 14px;
}

.prelim-group h4 {
  margin: 0 0 3px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.inline-items {
  margin: 4px 0 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-3);
  line-height: 1.6;
}

/* Statutes */
.statute-list {
  display: flex;
  flex-direction: column;
}

.statute-entry {
  padding: 20px 0;
  border-bottom: 1px solid var(--rule);
  scroll-margin-top: calc(var(--topbar-h) + 20px);
}

.statute-entry:first-child {
  padding-top: 0;
}

.statute-entry:last-child {
  border-bottom: none;
}

.statute-entry.targeted {
  background: var(--bg-soft);
  padding-left: 12px;
  padding-right: 12px;
  margin-left: -12px;
  margin-right: -12px;
}

.statute-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 6px;
}

.statute-head-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.statute-head-right {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-shrink: 0;
}

.class-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.copy-link-btn {
  border: none;
  background: transparent;
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 0 2px;
  cursor: pointer;
  opacity: 0.45;
}

.statute-entry:hover .copy-link-btn,
.copy-link-btn:focus {
  opacity: 1;
  color: var(--ink);
}

.statute-context {
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--ink-3);
}

.statute-bullets {
  margin: 8px 0 0;
  padding-left: 20px;
  color: var(--ink-2);
  font-size: 14px;
}

.statute-bullets li {
  margin-bottom: 3px;
}

.subsection-list {
  margin: 10px 0 0;
  padding-left: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.subsection-item {
  font-size: 14px;
  color: var(--ink-2);
}

.subsection-label {
  font-weight: 600;
  color: var(--ink);
  margin-right: 4px;
}

/* Details Disclosure */
.detail-disclosure {
  margin-top: 10px;
}

.detail-disclosure summary {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  padding: 4px 0;
}

.detail-disclosure-body {
  padding: 8px 0 4px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-group h4 {
  margin: 0 0 4px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.detail-group p {
  margin: 0 0 4px;
  font-size: 13.5px;
  color: var(--ink-3);
}

.detail-group ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13.5px;
  color: var(--ink-2);
}

.detail-group li {
  margin-bottom: 3px;
}

.statute-footnote {
  margin: 10px 0 0;
  font-size: 13.5px;
  color: var(--ink-3);
  font-style: italic;
}

.contributors-line {
  margin: 10px 0 0;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-2);
}

/* Penalty Lines */
.penalty-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.penalty-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  font-size: 13.5px;
  padding: 3px 0;
}

.penalty-text {
  color: var(--ink-2);
}

.penalty-tier {
  font-weight: 600;
  color: var(--ink);
}

.penalty-vals {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink);
}

.penalty-note {
  color: var(--ink-3);
}

.add-charge-btn {
  border: none;
  background: transparent;
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 0;
  cursor: pointer;
  flex-shrink: 0;
}

.add-charge-btn:hover,
.add-charge-btn.in-sheet {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Search Highlight */
mark.hl {
  background: var(--mark-bg);
  color: var(--ink);
  padding: 0 2px;
}

/* Empty State & Footer */
.empty-state {
  padding: 48px 0;
}

.empty-state h2 {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: 20px;
}

.empty-state p {
  margin: 0 0 16px;
  color: var(--ink-3);
}

.site-footer {
  margin-top: 64px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  font-size: 13px;
  color: var(--ink-3);
}

.site-footer p {
  margin: 0;
}

/* Plain Action Buttons */
.action-btn {
  border: 1px solid var(--rule-strong);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  padding: 8px 14px;
  cursor: pointer;
}

.action-btn:hover:not(:disabled) {
  border-color: var(--ink);
}

.action-btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Drawer */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.35);
}

.calc-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  width: min(390px, 100vw);
  background: var(--bg);
  border-left: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.calc-drawer.open {
  transform: translateX(0);
}

.calc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--rule);
}

.calc-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 19px;
}

.calc-totals {
  margin: 0;
  padding: 14px 22px;
  border-bottom: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
}

.total-row dt {
  color: var(--ink-3);
}

.total-row dd {
  margin: 0;
  font-family: var(--font-mono);
  font-weight: 600;
}

.calc-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 22px;
}

.calc-empty {
  margin: 24px 0;
  font-size: 13.5px;
  color: var(--ink-3);
}

.calc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.calc-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
}

.calc-item:first-child {
  padding-top: 0;
}

.calc-item-title {
  font-size: 13.5px;
  font-weight: 600;
}

.calc-item-tier {
  font-size: 12.5px;
  color: var(--ink-3);
}

.calc-item-bottom {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.calc-item-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-2);
}

.qty-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.qty-btn {
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 2px 6px;
  cursor: pointer;
}

.qty-val {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.calc-notes {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
}

.calc-notes h3 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

.calc-notes ul {
  margin: 0;
  padding-left: 16px;
  font-size: 12.5px;
  color: var(--ink-2);
}

.calc-footer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--rule);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  background: var(--ink);
  color: var(--bg);
  padding: 8px 16px;
  font-size: 13px;
}

/* Responsive */
@media (max-width: 900px) {
  .page-shell {
    grid-template-columns: 1fr;
    padding: 24px 18px 64px;
  }

  .mobile-menu-btn,
  .sidebar-close-btn {
    display: inline-block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    max-height: none;
    width: min(300px, 85vw);
    z-index: 90;
    background: var(--bg);
    padding: 18px 20px;
    border-right: 1px solid var(--rule);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }
}

@media (max-width: 640px) {
  .topbar-inner {
    padding: 0 14px;
    gap: 12px;
  }

  .brand-name {
    display: none;
  }

  .doc-header-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .doc-seal {
    width: 60px;
    height: 60px;
  }

  .statute-head {
    flex-direction: column;
    gap: 4px;
  }

  .penalty-row {
    flex-direction: column;
    gap: 4px;
  }
}

@media print {
  .topbar,
  .sidebar,
  .filter-bar,
  .add-charge-btn,
  .copy-link-btn,
  .calc-drawer,
  .backdrop {
    display: none !important;
  }

  .page-shell {
    display: block;
    padding: 0;
  }

  .content-area {
    max-width: none;
  }
}
