/* =====================================================
   Design tokens – change two colors & the whole UI shifts
   ===================================================== */
:root {
  --clr-accent: #0073e6;
  --clr-accent-dark: #005bb5;
  --clr-bg-body: #f9f9f9;
  --clr-bg-card: #ffffff;
  --radius: 8px;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.1);
  --ff-body: Arial, sans-serif;
}

/* ========== SCIENTIFIC CALCULATOR (home-page only) ========== */
.homepage-calculator {
  background: #2c2c2e;
  width: 90%;
  max-width: 420px;
  margin: 2em auto;
  padding: 1em;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.4);
  font-family: 'Segoe UI', Tahoma, sans-serif;
}

/* ----- Screen ----- */
.homepage-calculator .hc-screen {
  background: #000;
  color: #0f0;
  font-size: 1.8em;
  font-family: 'Digital-7 Mono', monospace;
  text-align: right;
  padding: 0.5em 0.75em;
  border: 2px inset #555;
  border-radius: 4px;
  margin-bottom: 0.75em;
  height: 1.2em;
  line-height: 1.2;     /*  keep a nice vertical rhythm */
  min-height: 2.2em;    /*  one comfortable row         */
  display: flex;        /*  vertically centre the text  */
  align-items: center;
   user-select: none;
   white-space: nowrap;  /*  stays on one line           */
   overflow-x: auto;     /*  scrolls sideways if too long */
   overflow-y: hidden;
}

/* =========================
   keep the sci-calc display in one line
   ========================= */
.homepage-calculator .hc-screen {
  white-space: nowrap;   /* ✨ never wrap to a 2nd line */
  overflow-x: auto;      /* ✨ allow sideways scrolling if it gets long */
  overflow-y: hidden;    /* ✨ block vertical spill */
}


/* ----- Buttons grid ----- */
.homepage-calculator .hc-buttons {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

/* ----- Generic button style ----- */
.homepage-calculator .hc-btn {
  background: linear-gradient(to bottom, #e0e0e0, #b0b0b0);
  border: 1px solid #888;
  border-radius: 6px;
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.5),
    inset 0 -2px 4px rgba(0,0,0,0.5),
    0 2px 2px rgba(0,0,0,0.2);
  color: #000;
  font-size: 1em;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5em;
  transition: background 0.1s, transform 0.1s;
}

/* ----- Variants ----- */
.homepage-calculator .hc-op {
  background: linear-gradient(to bottom, #ffdd57, #f5c518);
  color: #111;
}
.homepage-calculator .hc-fn {
  background: linear-gradient(to bottom, #d0d0ff, #a0a0f0);
  color: #111;
}

/* ----- Button interactions ----- */
.homepage-calculator .hc-btn:hover  {
  background: linear-gradient(to bottom, #f0f0f0, #c0c0c0);
}
.homepage-calculator .hc-btn:active {
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.7);
  transform: translateY(1px);
}

/* ----- Mobile tweaks (≤480 px) ----- */
@media (max-width: 480px) {
  .homepage-calculator .hc-screen { font-size: 1.4em; }
  .homepage-calculator .hc-btn    { font-size: 0.9em; padding: 0.4em; }
}


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

body {
  font-family: var(--ff-body);
  margin: 0;
  padding: 0;
  background: var(--clr-bg-body);
  color: #333;
  line-height: 1.6;
}

:focus-visible {
  outline: 3px solid var(--clr-accent);
  outline-offset: 2px;
}

/* ===== Header ===== */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--clr-accent);
  padding: .5rem 1rem;
  position: relative;         
}
.site-header .site-title a {
  color: #fff;
  font-size: 1.5rem;
  text-decoration: none;
}

.search-bar {
  position: relative;  
}

/* === Site-wide calculator search input ====================== */
#calculator-search {
  width: 100%;          /* stretch to fill its container */
  max-width: 320px;     /* but never wider than 320 px   */
  padding: .45rem .6rem;/* inner spacing: top/bottom 0.45rem, left/right 0.6rem */
  font-size: 1rem;      /* 1 rem ≈ 16 px on most browsers */
  border-radius: 4px;   /* soft rounded corners          */
  border: none;         /* no visible border             */
}


/* === Calculator search dropdown ======================= */
#search-results {
  position: absolute;
  top: calc(100% + .3rem);   /* just under the input */
  left: 0;
  width: 100%;
  max-width: 320px;          /* align with the input */
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid #ccc;
  background: #fff;
  display: none;             /* JS toggles this */
  z-index: 1000;             /* floats above everything */
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  border-radius: 4px;
}

#search-results a {
  display: block;
  padding: .45rem .6rem;
  text-decoration: none;
  color: #000;
  font-size: .95rem;
}

#search-results a:hover {
  background: #f1f1f1;
}

/* ===== Layout wrapper ===== */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  background: var(--clr-bg-card);
}

/* ─── Calculator Section ─────────────────────────────── */
.calculator-section {
  background: #f4f4f4;
  padding: 3rem 1rem;
  text-align: center;
}

.calculator-card {
  background: var(--clr-bg-card);
  border: 2px solid var(--clr-accent);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 480px;
  margin: 0 auto;
}

/* ─── Form ───────────────────────────────────────────── */
.calculator-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* unified field+unit inline layout  */
.input-with-unit {
  display: flex;
  align-items: center;
  gap: .5rem;
}
/* 1. Let the row wrap on tiny screens */
.input-with-unit { flex-wrap: wrap; }

/* ---------------------------------------------
   Select sizing — big vs. unit drop-downs
   --------------------------------------------- */

/* generic selects (e.g. “I want to calculate: …”) */
.input-with-unit select {
  flex: 1 1 auto;       /* grow & shrink with the row */
  min-width: 0;         /* may get narrow on phones   */
}

/* compact unit selectors (“V”, “mV”, “kV”, …) */
.unit-select {
  flex: 0 0 6rem;       /* fixed 6 rem width          */
  width: 6rem;
}

/* Make the main mode selector stretch naturally */
#calc-type {
  flex: 1 1 auto;   /* grow & shrink */
  width: auto;      /* ignore the 6 rem default */
  min-width: 8rem;  /* never get too tiny on phones */
}


.input-with-unit label {
  width: 120px;
  flex-shrink: 0;
  text-align: left;
  font-weight: 500;
}
.input-with-unit input {
  flex: 1 1 0;
}

/* Wider default width for every calculator value box */
.input-with-unit input {
  flex: 1 1 12rem;   /* 12 rem “preferred” width, can still grow/shrink */
  min-width: 8rem;   /* never collapse below 8 rem on small screens     */
}


/* 3. Make the text-box collapse gracefully */
.input-with-unit input { min-width: 0; }

.calculator-form input,
.calculator-form select {
  padding: .5rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

/* action row */
#form-buttons {
  display: flex;
  gap: 1rem;
}

.calculator-form button {
  padding: .75rem;
  font-size: 1rem;
  background: var(--clr-accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background .2s, transform .1s;
}
.calculator-form button:hover   { background: var(--clr-accent-dark); transform: translateY(-1px); }
.calculator-form button:active  { transform: translateY(1px); }

/* result area */
.calculator-result[role="status"] {
  margin-top: 1.5rem;
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--clr-accent);
}

/* hide groups accessibly – JS just toggles the attribute */
[hidden] { display: none !important; }

/* ------- Quadratic Regression table rows as flex containers ------- */
.reg-table tbody tr {
  display: flex;          /* abandon <tr>'s native table lay‑out */
  gap: .5rem;             /* consistent gutter between cells    */
}

/* Let the x and y input cells stretch/shrink */
.reg-table tbody td {
  flex: 1 1 auto;         /* occupy leftover space, shrink if needed */
  min-width: 0;
}

/* Fix the delete‑button cell to a predictable width */
.reg-table tbody td:last-child {
  flex: 0 0 2.2rem;       /* 2.2 rem ≈ 35 px at root font‑size 16 */
  display: flex;          /* center the button inside the cell    */
  justify-content: center;
}

/* Keep the input itself from overruling the shrink */
.reg-table tbody td input {
  width: 100%;               /* fill the cell */
  min-width: 0;              /* and shrink with it */
}

/* ------- Delete button visual style & focus ring ------- */
.del-row {
  width: 2rem;            /* square icon button                   */
  height: 2rem;
  border: none;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
  background: #f44336;    /* material‑style red                   */
  color: #fff;
  cursor: pointer;
}

.del-row:focus-visible {
  outline: 3px solid #2196f3;   /* keyboard focus accessibility   */
}

/* ---------- Header row: flex, same three columns ---------- */
.reg-table thead tr {
  display: flex;          /* match tbody rows */
  gap: .5rem;             /* same horizontal gutter           */
}

.reg-table thead th {
  flex: 1 1 auto;         /* x  |  y  columns expand/shrink   */
  min-width: 0;           /* let them compress on small screens */
  text-align: left;       /* keep labels flush to the left    */
}

/* fixed‑width “Delete” header cell keeps column alignment   */
/* (yours is visually hidden with .sr-only text, but it      */
/* still needs the width so the red button column lines up)  */
.reg-table thead th:last-child {
  flex: 0 0 2.2rem;       /* exactly same 2.2 rem as <td>      */
}



/* ── Article ─────────────────────────────────────────── */
.calculator-article {
  margin: 2rem auto 0;
  max-width: 600px;
  text-align: left;
  background: var(--clr-bg-card);
  padding: 2rem;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-left: 4px solid var(--clr-accent);
}
.calculator-article h3 { margin-top: 0; color: var(--clr-accent); }
.calculator-article h4 { margin: 1rem 0 .5rem; font-size: 1.1rem; }
.calculator-article p  { margin-bottom: 1rem; }
.calculator-article ul { margin: .5rem 0 1rem 1.2rem; }
.calculator-article li { margin-bottom: .3rem; }

/* ===== Categories Grid ===== */
.categories {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 2rem;
  margin: 2rem 1rem;
}
.category h2   { font-size: 1.2rem; margin-bottom: .5rem; }
.category ul   { list-style: none; padding: 0; }
.category li + li { margin-top: .3rem; }
.category a {
  text-decoration: none;
  color: var(--clr-accent);
}
.category a:hover { text-decoration: underline; }

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 1rem 0;
  background: #f1f1f1;
  margin-top: 2rem;
}

/* ===== Mobile (≤480 px) ===== */
@media (max-width: 480px) {
  .calculator-section { padding: 2rem 1rem; }
  .calculator-card    { padding: 1.5rem; }
  .input-with-unit label { width: 100px; font-size: .9rem; }
  .categories { gap: 1rem; margin: 1rem; }
  .category h2 { font-size: 1rem; }
}
