/*
 * ss-tools.css - styles for the calculators and student utilities.
 *
 * THEMING: every colour is a CSS variable on .ss-tool / .ss-page. To match the main site,
 * override the --ss-* variables in the site's own CSS (see README "Matching the site theme").
 * Dark mode switches on any of: html[data-theme="dark"], html.dark, html.night, body.dark,
 * body.dark-mode, body.night, [data-bs-theme="dark"]. Add the site's real selector if it differs.
 */

.ss-tool, .ss-page {
  --ss-bg: transparent;
  --ss-surface: #ffffff;
  --ss-surface-2: #f3f5f7;
  --ss-text: #1b2430;
  --ss-muted: #5a6675;
  --ss-border: #cfd6de;
  --ss-accent: #0b6a8a;
  --ss-accent-text: #ffffff;
  --ss-accent-soft: #e2f1f6;
  --ss-danger: #b3261e;
  --ss-danger-soft: #fdecea;
  --ss-ok: #1b6e3c;
  --ss-ok-soft: #e6f4ea;
  --ss-warn: #8a5a00;
  --ss-warn-soft: #fff4dc;
  --ss-radius: 8px;
  --ss-gap: 14px;
  --ss-font: inherit;
  --ss-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html[data-theme="dark"] .ss-tool, html[data-theme="dark"] .ss-page,
html.dark .ss-tool, html.dark .ss-page,
html.night .ss-tool, html.night .ss-page,
body.dark .ss-tool, body.dark .ss-page,
body.dark-mode .ss-tool, body.dark-mode .ss-page,
body.night .ss-tool, body.night .ss-page,
[data-bs-theme="dark"] .ss-tool, [data-bs-theme="dark"] .ss-page {
  --ss-surface: #18212b;
  --ss-surface-2: #212c38;
  --ss-text: #e8edf2;
  --ss-muted: #9aa8b7;
  --ss-border: #3a4857;
  --ss-accent: #4cc2e6;
  --ss-accent-text: #07202b;
  --ss-accent-soft: #15333f;
  --ss-danger: #ff8a80;
  --ss-danger-soft: #3a1d1b;
  --ss-ok: #7ddc9b;
  --ss-ok-soft: #173424;
  --ss-warn: #ffc857;
  --ss-warn-soft: #3a2f12;
}

.ss-tool { color: var(--ss-text); font-family: var(--ss-font); line-height: 1.5; max-width: 760px; margin: 0 0 1.5rem; }
.ss-tool *, .ss-tool *::before, .ss-tool *::after { box-sizing: border-box; }

/* ---------- form ---------- */
.ss-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--ss-gap); margin: 0 0 var(--ss-gap); }
.ss-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.ss-field[hidden] { display: none; }
.ss-field--wide { grid-column: 1 / -1; }
.ss-field > label { font-weight: 600; font-size: .95rem; }
.ss-input { display: flex; align-items: stretch; min-width: 0; }
.ss-tool input[type="text"], .ss-tool select, .ss-tool textarea {
  width: 100%; min-width: 0; min-height: 44px; padding: 8px 12px; font: inherit; color: var(--ss-text);
  background: var(--ss-surface); border: 1px solid var(--ss-border); border-radius: var(--ss-radius);
}
.ss-tool textarea { min-height: 88px; resize: vertical; }
.ss-input > input + select, .ss-input > input + .ss-unit { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.ss-input > input:has(+ select), .ss-input > input:has(+ .ss-unit) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.ss-input > input + select { width: auto; flex: 0 0 auto; max-width: 45%; background: var(--ss-surface-2); }
.ss-unit { display: inline-flex; align-items: center; padding: 0 12px; background: var(--ss-surface-2); border: 1px solid var(--ss-border); color: var(--ss-muted); white-space: nowrap; font-size: .95rem; }
.ss-help { color: var(--ss-muted); font-size: .85rem; margin: 0; }
.ss-tool :focus-visible { outline: 3px solid var(--ss-accent); outline-offset: 2px; }
.ss-tool input:focus-visible, .ss-tool select:focus-visible, .ss-tool textarea:focus-visible { outline-offset: 0; border-color: var(--ss-accent); }

/* ---------- buttons ---------- */
.ss-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: var(--ss-gap) 0; }
.ss-actions--center { justify-content: center; }
.ss-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 18px; font: inherit; font-weight: 600;
  color: var(--ss-text); background: var(--ss-surface); border: 1px solid var(--ss-border); border-radius: var(--ss-radius); cursor: pointer;
}
.ss-btn:hover:not(:disabled) { border-color: var(--ss-accent); }
.ss-btn--primary { background: var(--ss-accent); border-color: var(--ss-accent); color: var(--ss-accent-text); }
.ss-btn--primary:hover:not(:disabled) { filter: brightness(1.08); }
.ss-btn--icon { min-width: 44px; padding: 8px; }
.ss-btn:disabled { opacity: .5; cursor: not-allowed; }
.ss-status { color: var(--ss-ok); font-size: .9rem; }

/* ---------- results ---------- */
.ss-results { margin: 0 0 var(--ss-gap); }
.ss-result-list { margin: 0; display: grid; gap: 8px; }
.ss-result { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 16px; padding: 10px 14px; background: var(--ss-surface-2); border: 1px solid var(--ss-border); border-radius: var(--ss-radius); }
.ss-result dt { color: var(--ss-muted); font-size: .95rem; }
.ss-result dd { margin: 0; text-align: right; }
.ss-value { font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ss-result-hint { display: block; color: var(--ss-muted); font-size: .8rem; }
.ss-result--primary { background: var(--ss-accent-soft); border-color: var(--ss-accent); border-left-width: 5px; }
.ss-result--primary .ss-value { font-size: 1.5rem; }
.ss-notes { margin: 12px 0 0; padding-left: 1.2rem; color: var(--ss-muted); font-size: .9rem; }
.ss-notes li { margin: 4px 0; }
.ss-notes .ss-note--warn { color: var(--ss-warn); font-weight: 600; }
.ss-notes .ss-note--ok { color: var(--ss-ok); font-weight: 600; }
.ss-hint { color: var(--ss-muted); margin: 0; padding: 10px 0; }
.ss-error { color: var(--ss-danger); background: var(--ss-danger-soft); padding: 10px 14px; border-radius: var(--ss-radius); margin: 0; font-weight: 600; }
.ss-sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px; }

/* ---------- tabs ---------- */
.ss-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--ss-gap); border-bottom: 1px solid var(--ss-border); }
.ss-tab { min-height: 44px; padding: 8px 14px; font: inherit; font-weight: 600; color: var(--ss-muted); background: none; border: 0; border-bottom: 3px solid transparent; cursor: pointer; }
.ss-tab[aria-selected="true"] { color: var(--ss-text); border-bottom-color: var(--ss-accent); }

/* ---------- file drop + list ---------- */
.ss-drop { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 26px 16px; text-align: center; border: 2px dashed var(--ss-border); border-radius: var(--ss-radius); background: var(--ss-surface-2); cursor: pointer; margin-bottom: var(--ss-gap); }
.ss-drop:hover, .ss-drop.is-over, .ss-drop:focus-within { border-color: var(--ss-accent); background: var(--ss-accent-soft); }
.ss-drop-title { font-weight: 600; }
.ss-file-list { list-style: none; margin: 0 0 var(--ss-gap); padding: 0; display: grid; gap: 6px; }
.ss-file-list li { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; border: 1px solid var(--ss-border); border-radius: var(--ss-radius); background: var(--ss-surface); }
.ss-file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-file-size { color: var(--ss-muted); font-size: .85rem; white-space: nowrap; }
.ss-file-btns { display: flex; gap: 4px; }

/* ---------- table (CGPA) ---------- */
.ss-table-wrap { overflow-x: auto; margin-bottom: var(--ss-gap); }
.ss-table { width: 100%; border-collapse: collapse; }
.ss-table th { text-align: left; font-size: .9rem; padding: 6px 8px; color: var(--ss-muted); }
.ss-table td { padding: 4px; }
.ss-table td:nth-child(2), .ss-table td:nth-child(3) { width: 24%; }
.ss-table td:last-child { width: 52px; }

/* ---------- resistor visual ---------- */
.ss-visual { margin: 4px 0 var(--ss-gap); overflow-x: auto; }
.ss-resistor { display: flex; align-items: center; justify-content: center; height: 64px; }
.ss-lead { flex: 0 0 48px; height: 5px; background: #9aa0a6; }
.ss-body { display: flex; align-items: stretch; gap: 11px; padding: 0 22px; height: 48px; min-width: 190px; justify-content: center; border-radius: 22px; background: #e8d2a6; box-shadow: inset 0 -6px 0 rgba(0,0,0,.08); }
.ss-band { width: 12px; border-radius: 1px; box-shadow: 0 0 0 1px rgba(0,0,0,.18); }
.ss-band--gap { margin-left: 14px; }

/* ---------- previews / QR ---------- */
.ss-preview { display: flex; justify-content: center; }
.ss-preview img { max-width: 100%; max-height: 360px; border: 1px solid var(--ss-border); border-radius: var(--ss-radius); background: #fff; }
.ss-qr-stage { display: flex; justify-content: center; padding: 8px 0; }
.ss-qr-canvas { max-width: min(100%, 320px); height: auto; border: 1px solid var(--ss-border); border-radius: var(--ss-radius); background: #fff; image-rendering: pixelated; }

/* ---------- timer ---------- */
.ss-timer { text-align: center; margin-inline: auto; }
.ss-timer-phase { font-weight: 600; color: var(--ss-muted); }
.ss-timer-face { font-size: clamp(3.5rem, 18vw, 6.5rem); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; margin: 4px 0 10px; }
.ss-progress { height: 8px; background: var(--ss-surface-2); border-radius: 4px; overflow: hidden; border: 1px solid var(--ss-border); }
.ss-progress > span { display: block; height: 100%; width: 0; background: var(--ss-accent); }
.ss-timer .ss-form { text-align: left; margin-top: 20px; }
.ss-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.ss-check input { width: 20px; height: 20px; accent-color: var(--ss-accent); }

/* ---------- flashcards ---------- */
.ss-card { position: relative; display: block; width: 100%; min-height: 190px; padding: 0; margin-bottom: 8px; font: inherit; color: var(--ss-text); background: var(--ss-surface); border: 2px solid var(--ss-border); border-radius: 12px; cursor: pointer; text-align: center; }
.ss-card:hover { border-color: var(--ss-accent); }
.ss-card-face { display: flex; align-items: center; justify-content: center; min-height: 186px; padding: 24px; font-size: 1.35rem; font-weight: 600; overflow-wrap: anywhere; }
.ss-card-back { display: none; background: var(--ss-accent-soft); border-radius: 10px; font-family: var(--ss-mono); }
.ss-card.is-flipped .ss-card-front { display: none; }
.ss-card.is-flipped .ss-card-back { display: flex; }
.ss-details { margin: var(--ss-gap) 0; }
.ss-details summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }

/* ---------- tool page (server rendered text around the tool) ---------- */
.ss-page { color: var(--ss-text); max-width: 820px; margin: 0 auto; padding: 0 16px 40px; font-family: var(--ss-font); }
.ss-page h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); line-height: 1.2; margin: 1rem 0 .5rem; }
.ss-page h2 { font-size: 1.25rem; margin: 2rem 0 .6rem; }
.ss-page .ss-lead-text { color: var(--ss-muted); font-size: 1.05rem; margin: 0 0 1.25rem; max-width: 65ch; }
.ss-page .ss-formulas { padding-left: 1.2rem; }
.ss-page .ss-formulas li { margin: 6px 0; font-family: var(--ss-mono); font-size: .95rem; }
.ss-page details.ss-faq-item { border-bottom: 1px solid var(--ss-border); padding: 4px 0; }
.ss-page details.ss-faq-item summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.ss-page .ss-faq-item p { margin: 0 0 12px; max-width: 65ch; }
.ss-page .ss-related { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; }
.ss-page .ss-related a { display: inline-block; padding: 8px 14px; border: 1px solid var(--ss-border); border-radius: var(--ss-radius); color: var(--ss-text); text-decoration: none; }
.ss-page .ss-related a:hover { border-color: var(--ss-accent); }
.ss-page .ss-privacy { color: var(--ss-muted); font-size: .9rem; }
.ss-page .ss-tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; padding: 0; list-style: none; }
.ss-page .ss-tool-grid a { display: block; height: 100%; padding: 14px; border: 1px solid var(--ss-border); border-radius: var(--ss-radius); color: var(--ss-text); text-decoration: none; background: var(--ss-surface); }
.ss-page .ss-tool-grid a:hover { border-color: var(--ss-accent); }
.ss-page .ss-tool-grid strong { display: block; margin-bottom: 2px; }
.ss-page .ss-tool-grid span { color: var(--ss-muted); font-size: .9rem; }

@media (max-width: 520px) {
  .ss-result dd { text-align: left; }
  .ss-input > input + select { max-width: 40%; }
}
@media (prefers-reduced-motion: no-preference) {
  .ss-btn, .ss-drop, .ss-card { transition: border-color .15s ease, background-color .15s ease; }
}
