:root {
  color-scheme: light;
  --ink: #172230;
  --muted: #5d6a78;
  --brand: #123b67;
  --brand-dark: #0a2746;
  --accent: #d9ab16;
  --surface: #ffffff;
  --surface-alt: #f4f7fa;
  --line: #d8e0e8;
  --evidence: #d8f1d4;
  --shadow: 0 16px 42px rgba(21, 41, 61, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #edf2f6;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: linear-gradient(180deg, #f7fafc 0, #edf2f6 420px); }
button, input, select { font: inherit; }
button, select, input { min-height: 42px; }
button {
  border: 1px solid #b8c4cf;
  border-radius: 9px;
  padding: .58rem .82rem;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: border-color .16s, background .16s, color .16s, transform .16s;
}
button:hover { border-color: var(--brand); background: #eef5fc; }
button:active { transform: translateY(1px); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(18, 59, 103, .3); outline-offset: 2px; }
button.toggle_on, button[aria-pressed="true"] { border-color: var(--brand); background: var(--brand); color: #fff; }
.button--primary { border-color: var(--brand); background: var(--brand); color: #fff; }
.button--primary:hover { background: var(--brand-dark); color: #fff; }

.skip-link { position: fixed; z-index: 1000; top: 8px; left: 8px; padding: .6rem 1rem; background: #fff; transform: translateY(-140%); }
.skip-link:focus { transform: none; }
.site-header { border-bottom: 1px solid rgba(18, 59, 103, .15); background: rgba(255, 255, 255, .92); backdrop-filter: blur(12px); }
.site-header__inner { display: flex; align-items: center; gap: 1.4rem; width: min(1180px, calc(100% - 32px)); margin: auto; padding: 1.05rem 0; }
.site-header img { width: 146px; height: 50px; object-fit: contain; }
.site-header h1 { margin: .1rem 0 0; color: var(--brand-dark); font-size: clamp(1.45rem, 3vw, 2rem); line-height: 1.1; }
.eyebrow { margin: 0; color: var(--muted); font-size: .75rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.content { width: min(1180px, calc(100% - 32px)); margin: 1.5rem auto 3rem; }

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.toolbar__group { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.toolbar__label { flex-basis: 100%; color: var(--muted); font-size: .72rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.toolbar__group--settings { margin-left: auto; }
#settings_button { display: inline-flex; align-items: center; gap: .45rem; }
#settings_button img { filter: brightness(0) invert(1); }

.status { margin: 1rem 0; padding: .8rem 1rem; border: 1px solid #e5c45c; border-radius: 9px; background: #fff8dc; }
.status.status--error { border-color: #dc8f8f; background: #fff0f0; color: #842525; }
.step-navigation { margin: 1.4rem 0; padding: 1rem .75rem .3rem; overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.step-navigation .progress-tracker { min-width: 720px; }
.progress-step a { color: inherit; text-decoration: none; }
.progress-title { font-size: .78rem; line-height: 1.35; }

.visualization-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.visual-card { display: none; min-width: 0; padding: 1rem; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.visual-card--wide { grid-column: 1 / -1; }
.visual-card__heading { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.visual-card h2 { margin: 0; color: var(--brand-dark); font-size: 1.05rem; }
.info-button { width: 26px; min-height: 26px; height: 26px; padding: 0; border-radius: 50%; font-family: Georgia, serif; font-weight: 700; }
.canvas-scroll, .table-scroll { width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
#tree_diagram { display: block; width: 860px; max-width: none; margin: auto; }
#grid_div .canvas-scroll { min-height: 410px; }
.canwrap { position: relative; width: 410px; height: 390px; margin: 0 auto; }
#grid_div canvas { position: absolute; inset: 0 auto auto 0; }

table { margin: .5rem auto; border-collapse: separate; border-spacing: 0; font-size: .78rem; }
td { min-width: 66px; padding: .45rem .35rem; text-align: center; border-bottom: 1px solid #b8c1cb; }
tr:first-child td { font-weight: 700; border-bottom: 2px solid var(--ink); }
.hyp { min-width: 118px; }
.joint_e0 { min-width: 90px; background: var(--evidence); }
.joint_e1 { min-width: 90px; background: #e9edf1; }
.sep { min-width: 28px; background: #f4f5f6; font-weight: 700; }
.highlight { background: #ffef76 !important; }
.dark { background: #536273 !important; color: #fff; }
.frac { display: inline-block; text-align: center; }
.frac > sup { display: block; border-bottom: 1px solid; }
.frac > span { display: none; }
.frac > sub { display: block; }

.hover-tip, .infotip { position: absolute; z-index: 40; max-width: min(720px, calc(100vw - 24px)); padding: .7rem .8rem; border-radius: 8px; background: #152536; color: #fff; box-shadow: var(--shadow); font-size: .78rem; pointer-events: none; }
#hover_tip_text { padding: .5rem; border-radius: 6px; background: #fff; color: var(--ink); }

.modal { display: none; position: fixed; z-index: 100; inset: 0; overflow-y: auto; padding: clamp(1rem, 6vh, 4rem) 1rem; background: rgba(9, 22, 35, .78); backdrop-filter: blur(5px); }
#exportModal { z-index: 101; }
#linkGenModal { z-index: 102; }
.modal-content { position: relative; width: min(900px, 100%); margin: auto; padding: clamp(1.2rem, 4vw, 2rem); border-radius: 16px; background: var(--surface); box-shadow: 0 24px 80px rgba(0, 0, 0, .35); }
.modal-content--small { width: min(620px, 100%); }
.modal-content h2 { margin-top: 0; color: var(--brand-dark); }
.close { position: absolute; top: .65rem; right: .65rem; width: 42px; padding: 0; border: 0; background: transparent; font-size: 1.8rem; }
.option-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem 1rem; }
.option-grid label, fieldset label { display: grid; gap: .3rem; color: var(--muted); font-size: .82rem; font-weight: 650; }
fieldset { display: grid; gap: .8rem; margin: 1rem 0; padding: 1rem; border: 1px solid var(--line); border-radius: 10px; }
legend { padding: 0 .4rem; color: var(--brand-dark); font-weight: 750; }
input, select { width: 100%; border: 1px solid #b8c4cf; border-radius: 8px; padding: .55rem .65rem; background: #fff; color: var(--ink); }
.editor-library { display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: .6rem; }
#hyp_editor > p { margin-bottom: .4rem; }
#hyp_editor ul { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem; margin: 0 0 1rem; padding: 0; list-style: none; }
#hyp_editor li { display: grid; gap: .3rem; color: var(--muted); font-size: .82rem; }
.modal-err { color: #a11d28; font-size: .75rem; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 1rem; }
.share-link { display: grid; grid-template-columns: 1fr auto; gap: .6rem; }
.share-link input { min-width: 0; }

footer { padding: 2rem 1rem; color: var(--muted); text-align: center; font-size: .78rem; }

@media (max-width: 760px) {
  .site-header__inner { gap: .8rem; width: min(100% - 24px, 1180px); }
  .site-header img { width: 108px; height: auto; }
  .eyebrow { display: none; }
  .content { width: min(100% - 20px, 1180px); margin-top: .75rem; }
  .toolbar { align-items: stretch; gap: .85rem; padding: .8rem; }
  .toolbar__group { flex: 1 1 100%; }
  .toolbar__group button { flex: 1 1 calc(50% - .5rem); }
  .toolbar__group--settings { margin-left: 0; }
  .visualization-grid { grid-template-columns: 1fr; }
  .visual-card--wide { grid-column: auto; }
  .visual-card { padding: .8rem; }
  .option-grid, #hyp_editor ul { grid-template-columns: 1fr; }
  .editor-library { grid-template-columns: 1fr; }
  .modal { padding: .5rem; }
  .modal-content { min-height: calc(100dvh - 1rem); border-radius: 12px; }
  .share-link { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
