/* ==========================================================
   MG Math Visual Lab — Warm Paper Academic Design System
   Self-hosted Montserrat + editorial serif; zero external dependencies.
   ========================================================== */
@font-face {
  font-family: "Montserrat";
  src: url("fonts/Montserrat-Variable.woff2") format("woff2");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ground: #F5F2EA;
  --surface: #FFFDF8;
  --surface-2: #FAF7F0;
  --line: #E6E0D3;
  --line-soft: #EFEADF;
  --navy: #172A48;
  --navy-2: #223B63;
  --navy-soft: #E9EEF5;
  --navy-text: #C7CEDD;
  --ink: #16203A;
  --ink-2: #4B556B;
  --ink-3: #737B8E;
  --accent: #C86D44;
  --accent-soft: #FBECE4;
  --gold: #B8862D;
  --gold-soft: #FBF1DB;
  --gold-bright: #E8B04A;
  --sage: #1D6B53;
  --sage-soft: #E4F3EC;
  --serif: "Iowan Old Style", "Palatino Linotype", "Charter", "Georgia", "Songti SC", "STSong", "Noto Serif SC", serif;
  --sans: "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(23, 42, 72, 0.04), 0 4px 12px -6px rgba(23, 42, 72, 0.08);
  --shadow-md: 0 2px 6px rgba(23, 42, 72, 0.05), 0 14px 28px -12px rgba(23, 42, 72, 0.14);
  --t: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.18s ease, transform 0.16s ease;
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--ground);
  color: var(--ink);
  font: 400 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, select {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2.5px solid var(--gold);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.skip {
  position: fixed;
  left: 16px;
  top: -100px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--r-sm);
  background: var(--navy);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
}

.skip:focus {
  top: 12px;
}

[hidden] {
  display: none !important;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(245, 242, 234, 0.9);
  backdrop-filter: saturate(1.2) blur(12px);
  -webkit-backdrop-filter: saturate(1.2) blur(12px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mark {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: var(--navy);
  color: #fff;
  display: grid;
  place-items: center;
  font: 700 17px/1 var(--serif);
  letter-spacing: -0.04em;
  border: 1px solid rgba(232, 176, 74, 0.35);
  box-shadow: inset 0 -2px 0 rgba(232, 176, 74, 0.45), 0 4px 12px -4px rgba(23, 42, 72, 0.32);
  transition: var(--t);
}

.mark em {
  font-style: normal;
  color: var(--gold-bright);
}

.brand:hover .mark {
  background: var(--navy-2);
  transform: translateY(-1px);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink);
}

.brand-text small {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.site-nav a {
  padding: 7px 15px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
  transition: var(--t);
}

.site-nav a:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.site-nav a[aria-current="page"] {
  background: var(--navy);
  color: #fff;
}

/* ---------- Main Container ---------- */
main {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 28px 64px;
  flex: 1;
}

/* ---------- Compact Navy Editorial Hero ---------- */
.hero {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
  padding: 28px 34px;
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, #172A48 0%, #1F365B 68%, #25406A 100%);
  color: #fff;
  box-shadow: 0 14px 30px -16px rgba(23, 42, 72, 0.45);
}

.hero::after {
  content: "";
  position: absolute;
  right: 170px;
  bottom: 0;
  width: 260px;
  height: 126px;
  pointer-events: none;
  opacity: 0.14;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 260 126'%3E%3Cpolygon points='38,94 64,42 104,52 94,100' fill='none' stroke='%23E8B04A' stroke-width='1.8'/%3E%3Ccircle cx='64' cy='42' r='3.5' fill='%23E8B04A'/%3E%3Cpath d='M116 112 C 154 110, 174 22, 198 22 S 234 110, 256 112' fill='none' stroke='%23FFFFFF' stroke-width='2.2' stroke-linecap='round'/%3E%3Ccircle cx='198' cy='22' r='3.8' fill='%23E8B04A'/%3E%3C/svg%3E") no-repeat center / contain;
}

.hero-copy {
  position: relative;
  z-index: 1;
  min-width: 0;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 8px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-bright);
}

.hero h1 {
  margin: 0;
  font: 600 clamp(25px, 3.2vw, 35px)/1.16 var(--serif);
  letter-spacing: -0.02em;
  color: #fff;
}

.hero-sub {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--navy-text);
  max-width: 600px;
}

.hero-stat {
  position: relative;
  z-index: 1;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 132px;
  padding: 14px 18px;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  text-align: center;
}

.hero-stat strong {
  font: 600 34px/1 var(--serif);
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
}

.hero-stat span {
  margin-top: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--navy-text);
  white-space: nowrap;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 26px;
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--t);
}

.filter-pill:hover {
  border-color: #CFC6B4;
  color: var(--ink);
  background: #fff;
}

.filter-pill[aria-pressed="true"] {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.filter-pill .pill-n {
  font-size: 11.5px;
  font-weight: 700;
  opacity: 0.72;
  font-variant-numeric: tabular-nums;
}

.filter-pill[aria-pressed="true"] .pill-n {
  color: var(--gold-bright);
  opacity: 1;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 240px;
  max-width: 320px;
  min-width: 200px;
}

.search-ico {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--ink-3);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 36px;
  padding: 0 32px 0 35px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--ink);
  transition: var(--t);
}

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

.search-box input:focus {
  outline: none;
  background: #fff;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(23, 42, 72, 0.1);
}

.search-clear {
  position: absolute;
  right: 6px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: var(--line-soft);
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.toolbar-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
  font-size: 12.5px;
  color: var(--ink-2);
}

/* ---------- Category Sections & Tool Cards ---------- */
.cat-section {
  margin-bottom: 34px;
}

.cat-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.cat-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.cat-head h2 {
  margin: 0;
  font: 600 22px/1.25 var(--serif);
  color: var(--ink);
}

.cat-sub {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}

.cat-count {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.tool-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  transition: var(--t);
}

.tool-card:hover {
  border-color: #CFC6B4;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.tool-thumb {
  position: relative;
  height: 132px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--surface-2) 0%, #F2EDE1 100%);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool-card.cat-geometry .tool-thumb {
  background: linear-gradient(135deg, #FBF4EE 0%, #F4EAE0 100%);
}

.tool-card.cat-sampling .tool-thumb {
  background: linear-gradient(135deg, #EEF6F2 0%, #E3EFE9 100%);
}

.tool-thumb svg {
  width: 100%;
  max-width: 260px;
  height: 108px;
}

.thumb-badge {
  position: absolute;
  top: 10px;
  left: 12px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  color: var(--ink);
}

.cat-geometry .thumb-badge {
  color: #9A4825;
  border-color: #E7C8B7;
}

.cat-sampling .thumb-badge {
  color: var(--sage);
  border-color: #BCE0D2;
}

.thumb-symbol {
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 2px 9px;
  border-radius: 8px;
  background: var(--navy);
  color: var(--gold-bright);
  font: 700 12px/1.4 var(--serif);
}

.tool-body {
  flex: 1;
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
}

.tool-title-zh {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

.tool-title-en {
  margin: 3px 0 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-3);
}

.tool-desc {
  margin: 10px 0 12px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-2);
}

.tool-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
}

.tool-tag {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
}

.tool-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px 15px;
  border-top: 1px solid var(--line-soft);
  background: rgba(250, 247, 240, 0.55);
}

.btn-primary {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 9px;
  background: var(--navy);
  color: #fff;
  font-size: 13px;
  font-weight: 650;
  transition: var(--t);
}

.btn-primary:hover {
  background: var(--navy-2);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 9px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: var(--t);
}

.btn-secondary:hover {
  border-color: var(--navy);
  color: var(--navy);
  background: var(--navy-soft);
}

/* ---------- Empty State & Footer ---------- */
.empty-state {
  padding: 40px 24px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px dashed var(--line);
  text-align: center;
  color: var(--ink-2);
}

.empty-state strong {
  display: block;
  font-size: 16px;
  color: var(--ink);
  margin-bottom: 6px;
}

.empty-state p {
  margin: 0 0 14px;
  font-size: 13.5px;
}

.empty-reset {
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--navy);
  background: var(--navy);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.site-footer {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 28px 36px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: var(--ink-3);
  font-size: 12.5px;
}

.footer-brand strong {
  font: 700 17px/1.2 var(--serif);
  color: var(--navy);
}

.footer-brand strong span {
  margin-left: 8px;
  font: 600 11.5px/1 var(--sans);
  letter-spacing: 0.1em;
  color: var(--ink-3);
}

.footer-brand p {
  margin: 5px 0 0;
}

.back-top {
  flex: none;
  padding: 7px 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.back-top:hover {
  border-color: var(--navy);
  background: var(--navy);
  color: #fff;
}

/* ---------- Unified Viewer Shell (viewer.html) ---------- */
body.viewer-page {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: var(--navy);
}

.viewer-bar {
  flex: none;
  min-height: 52px;
  padding: 8px 16px;
  background: var(--navy);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.viewer-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.viewer-back {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: var(--t);
}

.viewer-back:hover {
  background: rgba(255, 255, 255, 0.2);
}

.viewer-cat {
  flex: none;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(232, 176, 74, 0.18);
  border: 1px solid rgba(232, 176, 74, 0.35);
  color: var(--gold-bright);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.viewer-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 650;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-title small {
  margin-left: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--navy-text);
}

.viewer-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.viewer-select {
  min-height: 34px;
  max-width: 240px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.viewer-select option,
.viewer-select optgroup {
  background: #172A48;
  color: #fff;
}

.viewer-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--t);
}

.viewer-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.viewer-btn.is-gold {
  background: var(--gold-bright);
  border-color: var(--gold-bright);
  color: var(--navy);
}

.viewer-btn.is-gold:hover {
  background: #f0be60;
}

.viewer-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #fff;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .viewer-title small,
  .viewer-cat {
    display: none;
  }
}

@media (max-width: 760px) {
  .tools-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .header-inner {
    padding: 12px 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .site-nav {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .site-nav a {
    padding: 8px 4px;
    text-align: center;
    font-size: 12px;
  }

  main {
    padding: 16px 16px 44px;
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
    padding: 22px 20px;
    gap: 14px;
  }

  .hero::after {
    right: -20px;
    bottom: -6px;
    width: 180px;
    height: 90px;
  }

  .hero-stat {
    flex-direction: row;
    gap: 10px;
    min-width: 0;
    padding: 9px 14px;
  }

  .hero-stat strong {
    font-size: 24px;
  }

  .hero-stat span {
    margin-top: 0;
  }

  .search-box {
    max-width: none;
    width: 100%;
  }

  .viewer-bar {
    padding: 8px 10px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .viewer-left {
    width: 100%;
  }

  .viewer-right {
    width: 100%;
  }

  .viewer-select {
    flex: 1;
    max-width: none;
  }

  .site-footer {
    padding: 20px 16px 32px;
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    transition: none !important;
  }
}
