:root {
  --bg: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --card: #f8fafc;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --code-bg: #0f172a;
  --code-fg: #e2e8f0;

  /* Risk levels */
  --risk-critical: #dc2626;
  --risk-high: #ea580c;
  --risk-moderate: #ca8a04;
  --risk-low: #16a34a;
  --risk-restrictive: #2563eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --fg: #f1f5f9;
    --muted: #94a3b8;
    --border: #1e293b;
    --card: #131b2e;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --code-bg: #030712;
    --code-fg: #f1f5f9;
  }
}

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

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Container */
.container {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.logo {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--fg);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.nav-desktop {
  display: flex;
  gap: 20px;
  align-items: center;
}

.nav-desktop a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: color 0.15s ease;
}

.nav-desktop a:hover,
.nav-desktop a[aria-current="page"] {
  color: var(--accent);
}

.nav-mobile {
  display: none;
  position: relative;
}

.nav-mobile summary {
  list-style: none;
  cursor: pointer;
  padding: 8px;
  font-size: 1.25rem;
  color: var(--fg);
  user-select: none;
}

.nav-mobile summary::-webkit-details-marker {
  display: none;
}

.nav-mobile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  min-width: 180px;
  padding: 8px 0;
  z-index: 100;
}

.nav-mobile-menu a {
  padding: 10px 16px;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.95rem;
}

.nav-mobile-menu a[aria-current="page"] {
  color: var(--accent);
  font-weight: 600;
}

@media (max-width: 680px) {
  .nav-desktop { display: none; }
  .nav-mobile { display: block; }
}

/* Breadcrumbs */
.breadcrumb-nav {
  padding: 16px 0 0 0;
  font-size: 0.85rem;
}

.breadcrumb-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
  color: var(--muted);
  gap: 6px;
}

.breadcrumb-list li + li::before {
  content: "›";
  margin-right: 6px;
  color: var(--muted);
}

.breadcrumb-list a {
  color: var(--muted);
  text-decoration: none;
}

.breadcrumb-list a:hover {
  text-decoration: underline;
}

.breadcrumb-list [aria-current="page"] {
  color: var(--fg);
  font-weight: 600;
}

/* Main Typography */
main {
  padding: 24px 0 60px 0;
}

h1 {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1.25;
  margin: 12px 0 8px 0;
  color: var(--fg);
}

.lead {
  font-size: 1.15rem;
  color: var(--muted);
  margin: 0 0 24px 0;
  line-height: 1.5;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 40px 0 16px 0;
  color: var(--fg);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 24px 0 12px 0;
  color: var(--fg);
}

p, ul, ol {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--fg);
  margin: 0 0 16px 0;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--accent-hover);
}

/* Notice box for non-sane modes */
.alert-notice {
  background: #fef3c7;
  border-left: 4px solid #f59e0b;
  color: #92400e;
  padding: 12px 16px;
  border-radius: 0 6px 6px 0;
  margin: 16px 0 24px 0;
  font-size: 0.95rem;
}

@media (prefers-color-scheme: dark) {
  .alert-notice {
    background: #451a03;
    color: #fde68a;
    border-left-color: #f59e0b;
  }
}

/* Summary Grid (At-a-glance card) */
.at-a-glance {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin: 20px 0;
}

.glance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 16px;
  text-align: center;
}

.glance-item {
  padding: 10px;
}

.glance-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.glance-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--fg);
}

.glance-summary {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 1rem;
  color: var(--fg);
}

/* Calculator Component */
.calc {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  margin: 24px 0 32px 0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.03);
}

.calc-matrix-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}

.calc-matrix-table th,
.calc-matrix-table td {
  padding: 12px 8px;
  text-align: center;
}

.calc-matrix-table th {
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.calc-matrix-table td:first-child {
  text-align: left;
  font-weight: 600;
  font-size: 0.95rem;
}

.calc-matrix-table .row-val {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  color: var(--accent);
  font-size: 1.1rem;
}

/* Big tap target checkbox */
.chk-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.chk-label:hover {
  background: rgba(37, 99, 235, 0.08);
}

.chk-label input[type="checkbox"] {
  width: 22px;
  height: 22px;
  cursor: pointer;
  accent-color: var(--accent);
}

/* Special bits row */
.special-bits-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px dashed var(--border);
  border-bottom: 1px dashed var(--border);
  margin-bottom: 20px;
}

.special-chk-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.special-chk-item input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* Inputs row */
.calc-inputs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.calc-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.calc-field input[type="text"],
.calc-field input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.calc-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.calc-field input[aria-invalid="true"] {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* Flags row */
.calc-flags-row {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}

/* Big Display outputs */
.calc-display-area {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  margin-bottom: 20px;
}

.display-numbers {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
}

.big-octal {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.big-symbolic {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--fg);
}

.display-meaning {
  margin-top: 10px;
  font-size: 0.95rem;
  color: var(--muted);
}

/* Command Output with copy button */
.command-box {
  display: flex;
  align-items: center;
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 8px;
  padding: 6px 6px 6px 16px;
  margin-bottom: 16px;
}

.command-box code {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.05rem;
  overflow-x: auto;
  white-space: nowrap;
}

.btn-copy {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
  white-space: nowrap;
}

.btn-copy:hover {
  background: rgba(255, 255, 255, 0.25);
}

.btn-copy.copied {
  background: #16a34a;
}

/* Risk badge in calculator */
.calc-risk-line {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.calc-guide-link {
  display: inline-block;
  margin-top: 12px;
  font-size: 0.95rem;
  font-weight: 600;
}

.calc-guide-link.highlight {
  background: #fef08a;
  color: #854d0e;
  padding: 4px 8px;
  border-radius: 4px;
}

@media (prefers-color-scheme: dark) {
  .calc-guide-link.highlight {
    background: #854d0e;
    color: #fef08a;
  }
}

/* Risk Badges */
.badge-risk {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
}

.badge-risk.critical { background-color: var(--risk-critical); }
.badge-risk.high { background-color: var(--risk-high); }
.badge-risk.moderate { background-color: var(--risk-moderate); }
.badge-risk.low { background-color: var(--risk-low); }
.badge-risk.restrictive { background-color: var(--risk-restrictive); }

/* Card Grids */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin: 20px 0;
}

.mode-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
}

.mode-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.mode-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.mode-card-octal {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.mode-card-sym {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  color: var(--muted);
}

.mode-card-use {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
  margin-top: auto;
  padding-top: 8px;
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.95rem;
}

th, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--card);
  font-weight: 600;
  color: var(--fg);
}

tr:last-child td {
  border-bottom: none;
}

/* Code blocks */
pre {
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 16px 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

p code, li code, td code {
  background: rgba(125, 125, 125, 0.12);
  padding: 2px 5px;
  border-radius: 4px;
}

/* FAQ Accordion / Details */
.faq-list {
  margin: 24px 0;
}

.faq-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}

.faq-item summary {
  padding: 14px 16px;
  font-weight: 600;
  font-size: 1.05rem;
  cursor: pointer;
  background: var(--card);
  user-select: none;
}

.faq-item summary:hover {
  color: var(--accent);
}

.faq-answer {
  padding: 14px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.faq-answer p:last-child {
  margin-bottom: 0;
}

/* Ad Slots */
.ad-slot {
  margin: 32px 0;
  min-height: 100px;
  text-align: center;
}

.ad-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--card);
  padding: 48px 0 24px 0;
  margin-top: 60px;
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 32px;
  margin-bottom: 36px;
}

.footer-col h4 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 12px 0;
}

.footer-col ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.footer-col li {
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.footer-col a {
  color: var(--fg);
  text-decoration: none;
}

.footer-col a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.footer-bottom {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}
