/* =================================================================
   MM250 DISCRETE MATH LAB — Stylesheet
   Palette: dark navy headers, light background, pale blue inputs,
   pale green results, pale yellow REMEMBER boxes. Subtle graph-paper
   texture. Mobile-first; sidebar nav becomes a drawer under ~880px.
   ================================================================= */

:root {
  --navy-900: #0b1c33;
  --navy-800: #12274a;
  --navy-700: #1a3a63;
  --ink: #1c2733;
  --ink-soft: #4a5a6b;
  --paper: #fbfbf8;
  --paper-line: rgba(18, 39, 74, 0.06);
  --line: #d8dde3;
  --line-strong: #b9c2cc;

  --blue-fill: #e8f1fb;
  --blue-border: #b7d3ec;
  --green-fill: #e9f7ee;
  --green-border: #b3ddc0;
  --yellow-fill: #fdf6df;
  --yellow-border: #e8d38f;
  --red-fill: #fdecec;
  --red-border: #e8b4b4;
  --neutral-fill: #f0f1f3;
  --neutral-border: #d6d9de;

  --true-color: #1d7a3e;
  --false-color: #a3341f;

  --radius: 10px;
  --radius-lg: 14px;
  --font-display: Iowan Old Style, 'Palatino Linotype', Palatino, Georgia, 'Cambria', 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  --shadow-card: 0 1px 2px rgba(11, 28, 51, 0.06), 0 1px 0 rgba(11, 28, 51, 0.04);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--paper-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-line) 1px, transparent 1px);
  background-size: 28px 28px;
  line-height: 1.5;
  min-height: 100vh;
  /* Safety net only — the real fix is .app-shell stacking vertically below
     880px (see the max-width: 879px block further down). This just stops
     any future stray element from creating visible page-level horizontal
     scroll; it does not make content fit by itself. */
  overflow-x: hidden;
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 200;
  background: var(--navy-900); color: #fff; padding: 10px 16px; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

h1, h2, h3, h4 { font-family: var(--font-display); color: var(--navy-900); margin: 0 0 0.4em; font-weight: 700; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.08rem; margin-bottom: 0.25em; }
h4 { font-size: 0.95rem; color: var(--navy-800); }
p { margin: 0 0 0.75em; }
.muted { color: var(--ink-soft); font-size: 0.92rem; }
a { color: var(--navy-700); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #7fb0e0; outline-offset: 2px;
}

/* ---------------- Banner ---------------- */
.app-banner {
  background: linear-gradient(180deg, var(--navy-900), var(--navy-800));
  color: #fff;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 8px rgba(11, 28, 51, 0.25);
}
.app-banner-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; }
.brand-mark {
  font-family: var(--font-display); font-size: 1.5rem; line-height: 1;
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.1); border-radius: 8px;
}
.brand-title { display: block; font-family: var(--font-display); font-weight: 700; font-size: 1rem; letter-spacing: 0.02em; }
.brand-sub { display: block; font-size: 0.72rem; color: #b9c9e0; letter-spacing: 0.03em; }

.nav-toggle {
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  width: 40px; height: 36px; background: transparent; border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px; cursor: pointer;
}
.nav-toggle span { display: block; width: 18px; height: 2px; background: #fff; margin: 0 auto; }

@media (min-width: 880px) {
  .nav-toggle { display: none; }
}

/* ---------------- Layout shell ---------------- */
.app-shell {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: flex-start;
}
.app-main { flex: 1 1 auto; min-width: 0; padding: 20px 16px 60px; }

.site-nav {
  flex: 0 0 auto; width: 100%;
  background: #fff; border-bottom: 1px solid var(--line);
  max-height: 0; overflow: hidden; transition: max-height 0.25s ease;
}
.site-nav.nav-open { max-height: 900px; }

@media (min-width: 880px) {
  .site-nav {
    width: 232px; max-height: none; overflow: visible; border-right: 1px solid var(--line); border-bottom: none;
    position: sticky; top: 61px; align-self: flex-start; height: calc(100vh - 61px); overflow-y: auto;
  }
}

/* Below the sidebar breakpoint, .app-shell must stack vertically. Without
   this, its default row direction puts .site-nav (width:100%) and
   .app-main side by side, forcing .app-main off-canvas to the right. */
@media (max-width: 879px) {
  .app-shell {
    flex-direction: column;
    width: 100%;
    min-width: 0;
  }

  .site-nav {
    width: 100%;
    flex: 0 0 auto;
    min-width: 0;
  }

  .app-main {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex: 1 1 auto;
  }
}

.nav-list { list-style: none; margin: 0; padding: 10px; }
.nav-list li { margin: 2px 0; }
.nav-list a {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 8px; text-decoration: none; color: var(--ink);
  font-size: 0.93rem;
}
.nav-list a:hover { background: var(--blue-fill); }
.nav-list a.active { background: var(--navy-900); color: #fff; }
.nav-icon { width: 1.1em; text-align: center; }
.nav-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 5px; background: var(--neutral-fill);
  font-size: 0.75rem; font-weight: 600; color: var(--navy-800); flex: none;
}
.nav-list a.active .nav-num { background: rgba(255,255,255,0.2); color: #fff; }
.nav-label { flex: 1; }
.nav-flag { color: #c79a2e; font-size: 1.2rem; line-height: 0; }
.nav-divider { border-top: 1px solid var(--line); margin: 8px 6px; }
.nav-chapter.nav-collapsed { display: none; }

/* ---------------- Hero / dashboard ---------------- */
.hero { padding: 8px 0 18px; }
.hero-sub { color: var(--ink-soft); max-width: 60ch; }

.dash-grid {
  display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 24px;
}
@media (min-width: 700px) {
  .dash-grid { grid-template-columns: 1fr 1fr; }
}
.dash-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 16px; box-shadow: var(--shadow-card);
}
.toggle-row { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; margin-top: 8px; }
.dash-card select {
  width: 100%; font-family: var(--font-body); font-size: 0.95rem;
  background: var(--blue-fill); border: 1.5px solid var(--blue-border); border-radius: 8px;
  padding: 9px 10px; min-height: 44px; margin: 6px 0; color: var(--ink);
}
.field-hint { font-size: 0.82rem; color: var(--ink-soft); margin: 2px 0 6px; }
.tool-list-empty-ok { list-style: none; margin: 0; padding: 0; }
.tool-list-empty-ok li { padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 0.92rem; }
.tool-list-empty-ok li:last-child { border-bottom: none; }
.status-summary { list-style: none; margin: 0; padding: 0; }
.status-summary li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 0; font-size: 0.88rem; border-bottom: 1px dashed var(--line); }
.status-summary li:last-child { border-bottom: none; }

.dash-quicklinks h2 { margin-bottom: 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 999px;
  padding: 7px 13px; font-size: 0.87rem; text-decoration: none; color: var(--navy-800);
}
.chip:hover { background: var(--blue-fill); }
button.chip { font-family: inherit; font-size: 0.87rem; cursor: pointer; }
.chip-flag, .chip-flag-inline { color: #c79a2e; }

/* ---------------- Page head / status badges ---------------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 6px; }
.page-head h1 { margin-bottom: 0; }
.status-badge {
  display: inline-block; font-family: var(--font-body); font-weight: 600;
  font-size: 0.68rem; letter-spacing: 0.02em; padding: 4px 9px; border-radius: 999px;
  white-space: nowrap;
}
.status-verified { background: var(--green-fill); color: var(--true-color); border: 1px solid var(--green-border); }
.status-partial { background: #eaf1fb; color: #1a4a7a; border: 1px solid #b7d3ec; }
.status-pending { background: var(--yellow-fill); color: #8a6d16; border: 1px solid var(--yellow-border); }

/* ---------------- Boxes ---------------- */
.box { border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; font-size: 0.9rem; }
.box-warning { background: var(--yellow-fill); border: 1px solid var(--yellow-border); color: #6b551a; }
.box-neutral { background: var(--neutral-fill); border: 1px solid var(--neutral-border); color: var(--ink-soft); }

/* ---------------- Tool grid / cards ---------------- */
.tool-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-top: 16px; }
@media (min-width: 760px) {
  .tool-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1140px) {
  .tool-grid { grid-template-columns: 1fr 1fr 1fr; }
}

.tool-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card); overflow: hidden; display: flex; flex-direction: column;
}
.tool-card-scaffold { opacity: 0.85; }
.tool-card-highlight { outline: 3px solid var(--navy-700); outline-offset: 3px; box-shadow: 0 0 0 6px rgba(26, 58, 99, 0.12); }
.tool-card-head { background: var(--navy-900); color: #fff; padding: 14px 16px 12px; position: relative; }
.tool-card-head h3 { color: #fff; }
.tool-card-head-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.tool-type-tag {
  font-size: 0.66rem; letter-spacing: 0.06em; font-weight: 700; color: #cfe0f5;
  border: 1px solid rgba(255,255,255,0.3); border-radius: 5px; padding: 2px 7px;
}
.tool-card-head .tool-meta { color: #c3d3e8; font-size: 0.82rem; margin-bottom: 8px; }
.pin-btn {
  position: absolute; right: 14px; bottom: -14px;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 999px;
  padding: 5px 12px; font-size: 0.78rem; cursor: pointer; color: var(--navy-800);
}
.pin-btn.is-pinned { background: var(--yellow-fill); border-color: var(--yellow-border); color: #6b551a; }

.tool-card-body { padding: 20px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.tool-card-body label { font-size: 0.82rem; font-weight: 600; color: var(--navy-800); margin-top: 4px; }
.tool-card-body input[type="text"],
.tool-card-body input[type="number"],
.tool-card-body textarea,
.tool-card-body select {
  font-family: var(--font-mono); font-size: 1rem;
  background: var(--blue-fill); border: 1.5px solid var(--blue-border); border-radius: 8px;
  padding: 10px 11px; width: 100%; color: var(--ink);
  min-height: 44px;
}
.tool-card-body textarea { resize: vertical; font-family: var(--font-body); }
.tool-card-body select { font-family: var(--font-body); }
.sub-block { border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 6px; }
.sub-block:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.symbol-pad { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 4px; }
.symbol-pad button {
  font-family: var(--font-mono); font-size: 1.05rem; min-width: 40px; min-height: 40px;
  background: #fff; border: 1.5px solid var(--line-strong); border-radius: 8px; cursor: pointer;
  color: var(--navy-800);
}
.symbol-pad button:hover { background: var(--blue-fill); }

.assign-inputs { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0; }
.assign-chip { display: flex; align-items: center; gap: 6px; font-weight: 600; font-family: var(--font-mono); }
.assign-chip select { width: auto; min-width: 64px; padding: 8px; }

.tool-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.btn {
  font-family: var(--font-body); font-weight: 600; font-size: 0.88rem;
  border-radius: 8px; padding: 10px 16px; min-height: 44px; cursor: pointer; border: 1.5px solid transparent;
}
.btn-primary { background: var(--navy-900); color: #fff; }
.btn-primary:hover { background: var(--navy-700); }
.btn-ghost { background: #fff; border-color: var(--line-strong); color: var(--navy-800); }
.btn-ghost:hover { background: var(--neutral-fill); }

.error-box:empty, .result-area:empty, .work-area:empty, .pattern-area:empty { display: none; }
.result-area {
  background: var(--green-fill); border: 1px solid var(--green-border); border-radius: var(--radius);
  padding: 12px 14px; font-family: var(--font-mono); font-size: 0.95rem;
}
.result-line { margin: 3px 0; }
.result-label { font-family: var(--font-body); font-weight: 600; color: var(--ink-soft); font-size: 0.82rem; }
.val-true { color: var(--true-color); }
.val-false { color: var(--false-color); }

.work-area {
  background: var(--blue-fill); border: 1px solid var(--blue-border); border-radius: var(--radius);
  padding: 12px 14px; font-family: var(--font-mono); font-size: 0.88rem; display: none;
}
.tool-card.work-expanded .work-area.has-content { display: block; }
.work-step { margin: 4px 0; }
.work-tag {
  display: inline-block; font-family: var(--font-body); font-weight: 700; font-size: 0.68rem;
  letter-spacing: 0.03em; text-transform: uppercase; color: var(--navy-800);
  background: rgba(255,255,255,0.6); border-radius: 4px; padding: 1px 6px; margin-right: 6px;
}
.excel-note { color: #4a5a6b; }

.tool-card-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.tool-card-controls .btn { flex: 1 1 auto; font-size: 0.8rem; padding: 9px 10px; min-height: 40px; }

/* ---------------- Truth tables ---------------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.truth-table { border-collapse: collapse; width: 100%; font-family: var(--font-mono); font-size: 0.92rem; }
.truth-table th, .truth-table td {
  border: 1px solid var(--line); padding: 6px 10px; text-align: center; min-width: 38px;
}
.truth-table thead th { background: var(--navy-900); color: #fff; font-family: var(--font-body); font-size: 0.78rem; }
.truth-table td.tt-final, .truth-table th.tt-final { background: var(--neutral-fill); font-weight: 700; }
.truth-table tbody tr:nth-child(even) { background: rgba(18,39,74,0.02); }

/* ---------------- Symbol reference ---------------- */
.symbol-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 16px 0; }
@media (min-width: 640px) { .symbol-grid { grid-template-columns: 1fr 1fr; } }
.symbol-card {
  display: flex; gap: 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 14px; box-shadow: var(--shadow-card);
}
.symbol-glyph {
  font-family: var(--font-mono); font-size: 1.8rem; color: var(--navy-900);
  width: 52px; height: 52px; flex: none; display: flex; align-items: center; justify-content: center;
  background: var(--blue-fill); border-radius: 10px;
}
.symbol-name { font-weight: 700; color: var(--navy-900); }
.symbol-read { font-size: 0.86rem; color: var(--ink-soft); margin: 2px 0; }
.symbol-meaning { font-size: 0.9rem; }

/* ---------------- Section list (scaffold pages) ---------------- */
.section-list { list-style: none; margin: 10px 0; padding: 0; }
.section-list li {
  padding: 8px 10px; border-bottom: 1px dashed var(--line); font-size: 0.92rem;
}
.section-list li:last-child { border-bottom: none; }

/* ---------------- Definition lists (reference tools) ---------------- */
.def-list { margin: 8px 0; }
.def-list dt { font-weight: 700; color: var(--navy-800); margin-top: 10px; font-size: 0.92rem; }
.def-list dt:first-child { margin-top: 0; }
.def-list dd { margin: 2px 0 0; font-size: 0.9rem; color: var(--ink-soft); }

/* ---------------- Changelog ---------------- */
.changelog-entry { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow-card); }
.changelog-entry ul { margin: 8px 0 0; padding-left: 20px; }
.changelog-entry li { margin-bottom: 6px; }

/* ---------------- Footer ---------------- */
.app-footer { border-top: 1px solid var(--line); margin-top: 40px; }
.app-footer-inner {
  max-width: 1200px; margin: 0 auto; padding: 16px; color: var(--ink-soft); font-size: 0.82rem;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.app-footer-inner a { color: var(--ink-soft); }
.dot { opacity: 0.5; }

/* ---------------- Print / clean view ---------------- */
@media print {
  .app-banner, .site-nav, .app-footer, .nav-toggle, .pin-btn, .tool-card-controls, .symbol-pad { display: none !important; }
  body { background: #fff; }
  .app-main { padding: 0; }
  .tool-card { box-shadow: none; border: 1px solid #999; break-inside: avoid; }
  .work-area { display: block !important; }
}

/* ---------------- Reduced motion ---------------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
