/* ============================================================
   ICCMA — design tokens
   ============================================================ */
:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --bg-elevated: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-hover: #eef1f4;
  --bg-code: #eef1f4;
  --border: #d7dce2;
  --text: #1b1f24;
  --text-muted: #59636e;
  --accent: #0e7490;
  --accent-strong: #0b5b73;
  --accent-bg: #e3f4f7;
  --shadow: 0 1px 2px rgba(20, 29, 39, 0.06), 0 6px 16px rgba(20, 29, 39, 0.06);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;
  --radius: 6px;
  --sidebar-width: 230px;
  --max-width: 1080px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1117;
    --bg-elevated: #12161d;
    --bg-sidebar: #10141b;
    --bg-hover: #1c232c;
    --bg-code: #161b22;
    --border: #262d38;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #2dd4ee;
    --accent-strong: #7ce6f7;
    --accent-bg: rgba(45, 212, 238, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-elevated: #12161d;
  --bg-sidebar: #10141b;
  --bg-hover: #1c232c;
  --bg-code: #161b22;
  --border: #262d38;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #2dd4ee;
  --accent-strong: #7ce6f7;
  --accent-bg: rgba(45, 212, 238, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ============================================================
   Reset & base
   ============================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}

img {
  max-width: 100%;
  height: auto;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

li {
  margin-bottom: 4px;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-mono);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 1.6rem;
  margin: 0.2em 0 0.7em;
}

h2 {
  font-size: 1.3rem;
  margin: 1.6em 0 0.6em;
}

h3 {
  font-size: 1.1rem;
  margin: 1.4em 0 0.5em;
}

h4 {
  font-size: 1rem;
  margin: 1.3em 0 0.5em;
}

h1::before,
h2::before,
h3::before,
h4::before {
  color: var(--text-muted);
  font-weight: 500;
  margin-right: 0.4em;
}

h1::before {
  content: "#";
}

h2::before {
  content: "##";
}

h3::before {
  content: "###";
}

h4::before {
  content: "####";
}

code,
pre {
  font-family: var(--font-mono);
  background: var(--bg-code);
  border-radius: 4px;
}

/* ============================================================
   Page shell
   ============================================================ */
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
}

.page-header {
  flex: 1 0 100%;
  width: 100%;
  padding: 1.75rem 0 1.1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.site-title {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.site-title::before {
  content: ">";
  color: var(--accent);
  margin-right: 0.35em;
}

.site-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.2em;
}

.page-sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  padding-right: 1.5rem;
  padding-bottom: 2rem;
}

.page-content {
  flex: 1 1 0;
  min-width: 0;
  padding-bottom: 2rem;
}

.content-inner {
  max-width: 100%;
}

.page-footer {
  margin-top: 2.5rem !important;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  text-align: right;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.page-footer a {
  color: var(--text-muted);
}

/* ============================================================
   Theme toggle
   ============================================================ */
.theme-toggle {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text-muted);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

/* ============================================================
   Sidebar navigation (rendered by nav.js)
   ============================================================ */
#nav {
  display: block;
}

.nav-toggle {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 0.6em 0.8em;
  margin-bottom: 0.5em;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  cursor: pointer;
}

.nav-toggle-bars {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
  width: 16px;
}

.nav-toggle-bars span {
  display: block;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}

.nav-links {
  display: flex;
  flex-direction: column;
}

a.menu,
a.menu_sel,
a.menu_sub,
a.menu_sub_sel {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--text-muted);
  padding: 0.5em .7em;
  margin-bottom: 2px;
  border-left: 2px solid transparent;    
  display: block;
  background: transparent;
}

a.menu_sub,
a.menu_sub_sel {
  margin-left: 0.9em;
  font-size: 0.8rem;
}

a.menu:hover,
a.menu_sub:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}

a.menu_sel,
a.menu_sub_sel {
  background: var(--accent-bg);
  border-left-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 600;
}

/* ============================================================
   Callout box
   ============================================================ */
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

.newsbox {
  padding: 0.9em 1em;
  margin-bottom: 1em;  
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-right: 3px solid var(--accent);
  background: var(--accent-bg);
}

.newsbox a {
  color: var(--accent-strong);
  font-weight: 600;
}

/* ============================================================
   Tables (result/track/solver listings)
   ============================================================ */
table {
  display: block;
  overflow-x: auto;
  max-width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin: 1em 0;
  -webkit-overflow-scrolling: touch;
}

table th,
table td {
  border: 1px solid var(--border);
  padding: 0.4em 0.6em;
  text-align: left;
}

table th {
  background: var(--bg-code);
  font-weight: 600;
}

table tr:hover td {
  background: var(--bg-hover);
}

#solver_table {
  color: var(--text-muted);
  font-weight: 400;
  text-align: center;
  width: 90%;
  margin: 2em auto;
}

#solver_table th {
  font-size: 0.8em;
}

#solver_table th,
#solver_table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0.3em;
  vertical-align: middle;
  white-space: nowrap;
}

#solver_table th:hover,
#solver_table td:hover {
  background-color: var(--accent-bg);
}

.res-table {
  display: block;
  overflow-x: auto;
  max-width: 100%;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.res-table .res-row {
  display: table-row;
}

.res-table .res-row .res-cell {
  display: table-cell;
  padding: 1em;
  white-space: nowrap;
  width: 12em;
  vertical-align: top;
}

.res-table .res-row .res-cell .chap {
  margin: 0 0 0.5em;
  font-family: var(--font-sans);
}

.res-table .res-row .res-cell ol li {
  margin: 0.6em 0 0 2em;
}

.track_table {
  table-layout: auto;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 400;
  width: 90%;
  margin: 2em 0;
}

.track_table th {
  font-weight: bold;
}

.track_table th,
.track_table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0.3em 0.4em;
  vertical-align: middle;
  white-space: nowrap;
}

.track_table td {
  text-align: right;
}

.track_table td:first-child {
  text-align: left;
}

.track_table th {
  text-align: center;
}

.track_table th:hover,
.track_table td:hover {
  background-color: var(--accent-bg);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 820px) {
  .page {
    padding: 0 1.1rem;
  }

  .page-header {
    padding: 1.25rem 0 1rem;
  }

  .site-title {
    font-size: 1.15rem;
  }

  .page-sidebar {
    flex: 1 0 100%;
    width: 100%;
    padding-right: 0;
    padding-bottom: 1rem;
  }

  .nav-toggle {
    display: flex;
  }

  .nav-links {
    max-height: 0;
    overflow: hidden;
  }

  #nav.nav-open .nav-links {
    max-height: 2000px;
  }

  .page-content {
    flex: 1 0 100%;
    width: 100%;
  }

  h1 {
    font-size: 1.35rem;
  }

  h2 {
    font-size: 1.15rem;
  }
}

@media (max-width: 480px) {
  .site-subtitle {
    display: none;
  }
}
