/* ─────────────────────────────────────────────────────────────────────
 * CapyCalc shared base styles — design tokens + layout shell
 * Used by every standalone tool under /tools/. Tool-specific styles
 * live inside each standalone's own <style> block.
 *
 * Extracted from the live SPA so selectors stay identical: any code
 * that targets these classes continues to work without modification.
 * ───────────────────────────────────────────────────────────────────── */

select { color-scheme: dark; }
select option { background: #1e2536; color: #e2e8f0; }

:root {
  --bg:      #0f1117;
  --bg2:     #161b26;
  --bg3:     #1e2535;
  --bg4:     #252d3d;
  --bg5:     #2c3650;
  --border:  rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.13);
  --text:    #e8ecf4;
  --text2:   #8b95a8;
  --text3:   #5a6373;
  --acc:     #4f7ef8;
  --acc2:    rgba(79,126,248,0.13);
  --acc3:    rgba(79,126,248,0.4);
  --gold:    #f0b429;
  --gold2:   rgba(240,180,41,0.10);
  --gold3:   rgba(240,180,41,0.30);
  --green:   #3ecf8e;
}

/* ── Body ── */
* { box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  margin: 0;
}

/* ── Header ── */
header.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 54px;
  padding: 0 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.2px;
}
.brand img {
  width: 32px; height: 32px;
  border-radius: 6px;
}
.brand-name { font-weight: 700; }
.brand-name .brand-suffix { color: var(--text2); font-weight: 500; }
.hdr-spacer { flex: 1; }

/* ── Hamburger & mobile nav ── */
.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  line-height: 1;
  transition: color 0.1s;
}
.hamburger:hover { color: var(--text); background: var(--bg3); }
.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
}

/* ── Layout ── */
.layout { display: flex; min-height: calc(100vh - 54px); }

/* ── Sidebar ── */
nav.sidebar {
  width: 220px; min-width: 220px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 16px 10px;
  position: sticky;
  top: 54px;
  height: calc(100vh - 54px);
  overflow-y: auto;
  display: flex; flex-direction: column;
  /* Hide scrollbar visually but keep scrollability for taller content */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
nav.sidebar::-webkit-scrollbar { display: none; width: 0; height: 0; }
.nav-items { flex: 1; }
.nav-group {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text3);
  padding: 0 8px;
  margin: 10px 0 4px;
}
.nav-group:first-child { margin-top: 0; }
/* Plain collapsible nav group header */
.nav-group-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  width: 100%; background: transparent; border: none; cursor: pointer;
  font-family: inherit;
  font-size: 10px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text3); padding: 0 8px; margin: 10px 0 4px; text-align: left;
}
.nav-group-toggle:first-child { margin-top: 0; }
.nav-group-toggle:hover { color: var(--text2); }
.nav-group-caret { font-size: 9px; transition: transform 0.18s; display: inline-block; }
.nav-group-toggle.nav-group-collapsed .nav-group-caret { transform: rotate(-90deg); }
.nav-group-children { display: flex; flex-direction: column; }
.nav-group-children.nav-group-hidden { display: none; }

/* ── Capy Tracker — flagship "hub" treatment ── */
.nav-tracker-hub {
  margin: 2px 0 12px;
  border: 1px solid var(--acc3);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--acc2), transparent 60%), var(--bg2);
  box-shadow: 0 0 0 1px rgba(79,126,248,0.06), 0 4px 14px rgba(0,0,0,0.18);
  overflow: hidden;
}
.nav-tracker-head {
  display: flex; align-items: center; gap: 9px;
  width: 100%; background: transparent; border: none; cursor: pointer;
  font-family: inherit; text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}
.nav-tracker-head:hover { background: rgba(79,126,248,0.06); }
.nav-tracker-mark {
  flex: 0 0 auto; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1;
  background: var(--acc2); border: 1px solid var(--acc3); border-radius: 8px;
  overflow: hidden;
}
.nav-tracker-mark-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nav-tracker-titles { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; justify-content: center; }
.nav-tracker-title { font-size: 13.5px; font-weight: 700; color: var(--text); letter-spacing: 0.01em; line-height: 1.2; }
.nav-tracker-head .nav-group-caret {
  flex: 0 0 auto; font-size: 10px; color: var(--text3);
  transition: transform 0.18s; display: inline-block;
}
.nav-tracker-head.nav-group-collapsed .nav-group-caret { transform: rotate(-90deg); }
.nav-tracker-children {
  display: flex; flex-direction: column;
  padding: 5px 8px 7px; position: relative;
}
.nav-tracker-children::before {
  content: ''; position: absolute;
  left: 17px; top: 4px; bottom: 8px; width: 2px;
  background: linear-gradient(var(--acc3), transparent);
  border-radius: 2px; opacity: 0.5;
}
.nav-tracker-children.nav-tracker-hidden { display: none; }
.nav-tracker-children .nav-item { position: relative; }
.nav-tracker-children .nav-item.active { background: var(--acc2); }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 6px 8px;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--text2);
  font-size: 13px;
  line-height: 1.5;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  transition: all 0.12s;
}
.nav-item:visited { color: var(--text2); }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--acc2); color: var(--acc); font-weight: 500; }
.nav-item.active:visited { color: var(--acc); }
.nav-item.dim { opacity: 0.35; cursor: not-allowed; }
.nav-item.dim:hover { background: transparent; color: var(--text2); }
/* Keep the icon (first span) and label (second span) a consistent size across all
   items so varying emoji glyph metrics can't shrink or distort a row. */
.nav-item > span:first-child {
  flex: 0 0 auto;
  width: 18px; text-align: center;
  font-size: 14px; line-height: 1;
}
.nav-ico { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; flex: 0 0 auto; }
.nav-ico-img, .nav-item .nav-ico img { width: 18px !important; height: 18px !important; max-width: 18px; max-height: 18px; object-fit: contain; display: block; }
.nav-item > span:last-child {
  font-size: 13px; line-height: 1.4;
}

/* Sidebar footer (Credits, Discord) */
.nav-discord {
  margin-top: auto;
  padding: 10px 8px 4px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}
.nav-discord-link, .nav-credits-link {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text2);
  text-decoration: none;
  transition: all 0.12s;
}
.nav-discord-link:hover { background: rgba(88,101,242,0.15); color: #5865f2; }
.nav-credits-link:hover { background: var(--bg3); color: var(--text); }

/* ── Main content ── */
main {
  flex: 1;
  overflow-y: auto;
  height: calc(100vh - 54px);
  padding: 24px 28px;
  max-width: none;
  scrollbar-width: thin;
}
@media (max-width: 900px) {
  main { padding: 16px; }
  .hamburger { display: inline-flex; align-items: center; justify-content: center; }
  nav.sidebar {
    position: fixed;
    left: -260px; top: 54px;
    height: calc(100vh - 54px);
    transition: left 0.2s ease;
    z-index: 95;
  }
  nav.sidebar.open { left: 0; }
  .nav-overlay.open { display: block; }
}

/* ── Common helpers ── */
.col-span { grid-column: 1 / -1; }

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 4px 0;
}
.page-sub {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 18px;
  line-height: 1.5;
}
.page-sub strong { color: var(--text); font-weight: 600; }

/* Older-style page header used by most calculators */
.page-hdr {
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.page-hdr-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.page-hdr-sub {
  font-size: 12px;
  color: var(--text3);
  margin-top: 4px;
  font-weight: 400;
}

/* Card chrome — used by Stat Calculator, Tenpen, Pet Sim, etc. */
.wa-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.wa-card.active { border-color: var(--acc3); }
.wa-card-hdr {
  padding: 9px 12px 8px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.wa-card-title { font-size: 12px; font-weight: 600; color: var(--text); }
.wa-card-subtitle { font-size: 10px; color: var(--text3); margin-top: 2px; }

/* Slider / numeric input row — used by CritCalc, Tenpen, etc. */
.cc-slider-row { margin-bottom: 10px; }
.cc-slider-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text2); margin-bottom: 4px;
}
.cc-slider-label > span:first-child { flex: 1; min-width: 0; }
.cc-num-input {
  width: 56px; font-size: 11px; font-weight: 700; text-align: right;
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 4px; -moz-appearance: textfield;
}
.cc-num-input::-webkit-outer-spin-button,
.cc-num-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cc-suffix { font-size: 10px; color: var(--text3); width: 12px; }
.cc-range {
  width: 100%; -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 2px; background: var(--bg4); outline: none;
}
.cc-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%; background: var(--acc);
  cursor: pointer; border: 2px solid var(--bg);
}
.cc-range::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--acc);
  cursor: pointer; border: 2px solid var(--bg);
}

/* Formula display box — used by CritCalc, Tenpen for math derivation */
.cc-formula { font-size: 11px; color: var(--text2); }
.cc-fgroup { margin-bottom: 12px; }
.cc-fgroup:last-child { margin-bottom: 0; }
.cc-flabel { font-size: 11px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.cc-fcode {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg3); border-left: 3px solid var(--acc); border-radius: 4px;
  padding: 7px 10px; font-size: 11px; color: var(--gold);
  margin-bottom: 4px; line-height: 1.5; overflow-x: auto;
}
.cc-fnote { font-size: 10px; color: var(--text3); line-height: 1.55; }

/* ── Base form chrome (inputs, selects, buttons) ── */
input, select, textarea, button {
  font-family: inherit;
}
input[type="number"], input[type="text"], input[type="search"], textarea {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 5px;
  color: var(--text);
  font-size: 13px;
  padding: 5px 8px;
  outline: none;
}
input[type="number"]:focus, input[type="text"]:focus, input[type="search"]:focus, textarea:focus {
  border-color: var(--acc);
}
button.btn,
.btn {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text2);
  font-size: 13px;
  padding: 7px 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}
button.btn:hover,
.btn:hover { color: var(--text); background: var(--bg4); }
button.btn-primary,
.btn-primary {
  background: var(--acc);
  border-color: var(--acc);
  color: #fff;
  font-weight: 600;
}
button.btn-primary:hover,
.btn-primary:hover { filter: brightness(1.1); }

/* ── Scrollbar styling (subtle) ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg5); }
