/* =========================================================
   CGPA Calculator – styles
   Colors are defined once as variables, then swapped for dark mode.
   ========================================================= */

/* Inter, stored with the site (no request to Google). Scripts Inter doesn't cover,
   like Urdu or Hindi, fall back to the system font. Licence: fonts/OFL.txt */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("fonts/inter-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("fonts/inter-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e1e5ee;
  --text: #151a2d;
  --muted: #5d6680;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eceafe;
  --on-primary: #ffffff;
  --danger: #c93434;
  --danger-soft: #fdeeee;
  --info: #2b6cd4;
  --result-from: #4f46e5;
  --result-to: #0e9f9a;
  --warn: #9a5800;
  --warn-soft: #fff6e5;
  --warn-border: #f2d6a2;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 18px;
  --radius-sm: 12px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1020;
  --surface: #161a2e;
  --surface-2: #1d2240;
  --border: #2a3052;
  --text: #e9ebf7;
  --muted: #9aa3c2;
  --primary: #8f86ff;
  --primary-hover: #a59eff;
  --primary-soft: #252650;
  --on-primary: #0d1020;
  --danger: #ff8080;
  --danger-soft: #3a1e2a;
  --info: #84b4ff;
  --result-from: #4338ca;
  --result-to: #0f766e;
  --warn: #ffc46b;
  --warn-soft: #2b2314;
  --warn-border: #5a4520;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s, color 0.2s;
}

main { flex: 1; }

h1, h2 { margin: 0; letter-spacing: -0.015em; line-height: 1.25; }
h2 { font-size: 1.2rem; }
p { margin: 0; }

.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.tiny { font-size: 0.8rem; }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; }

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--result-from), var(--result-to));
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.icon-btn:hover { border-color: var(--primary); }
.icon-btn:active { transform: scale(0.95); }
/* ---------- Menu ---------- */
.header-actions { display: flex; align-items: center; gap: 8px; }
.site-nav { display: flex; gap: 2px; margin-inline-end: 6px; }
.site-nav a {
  padding: 8px 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--muted);
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }
.site-nav a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
/* Right-to-left languages (Urdu, Arabic): mirror the dropdown arrow */
[dir="rtl"] select { background-position: left 13px center; }
[dir="rtl"] .formula-line, [dir="rtl"] .formula-work, [dir="rtl"] .formula-block { unicode-bidi: plaintext; }

/* Language menu */
.lang-menu { position: relative; }
.lang-menu summary { list-style: none; cursor: pointer; }
.lang-menu summary::-webkit-details-marker { display: none; }
.lang-btn { width: auto; min-width: 42px; padding: 0 10px; gap: 6px; display: flex; align-items: center; }
.lang-code { font-size: 0.78rem; font-weight: 800; letter-spacing: 0.03em; }
.lang-list {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  z-index: 30;
  width: 240px;
  max-height: min(70vh, 520px);
  overflow-y: auto;
  padding: 6px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.lang-list a {
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}
.lang-list a:hover { background: var(--surface-2); color: var(--primary); }
.lang-list a[aria-current="true"] { color: var(--primary); background: var(--primary-soft); }
@media (max-width: 380px) { .lang-btn .lang-code { display: none; } .lang-btn { padding: 0; min-width: 42px; justify-content: center; } }

.menu-btn { display: none; }
.icon-close { display: none; }
.menu-btn[aria-expanded="true"] .icon-menu { display: none; }
.menu-btn[aria-expanded="true"] .icon-close { display: block; }

@media (max-width: 820px) {
  .menu-btn { display: grid; }
  .site-nav {
    display: none;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    margin: 0;
    padding: 8px 16px 16px;
    flex-direction: column;
    gap: 4px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
  }
  .site-nav.open { display: flex; }
  .site-nav a { padding: 12px 14px; font-size: 1rem; }
}

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

/* ---------- Hero ---------- */
.hero { padding: 28px 0 18px; }
.hero h1 { font-size: clamp(1.5rem, 4.5vw, 2.2rem); font-weight: 800; }
.hero p { margin-top: 6px; color: var(--muted); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.scale-card { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 24px; }
.scale-text { flex: 1 1 260px; }
.scale-title { display: block; font-weight: 700; font-size: 1.05rem; }
.scale-select { flex: 1 1 260px; max-width: 360px; font-weight: 600; }

.layout { display: grid; gap: 20px; margin: 20px 0 40px; }
.sidebar { display: grid; gap: 20px; align-content: start; }

@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
  .sidebar { position: sticky; top: 84px; }
}

/* ---------- Tabs ---------- */
.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 15px;
}
.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 0.98rem;
  line-height: 1.2;
  padding: 10px 6px;
  border-radius: 11px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: background-color 0.15s, color 0.15s;
}
.tab small { font-weight: 500; font-size: 0.72rem; opacity: 0.85; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.12);
}

@media (min-width: 520px) { .tabs { grid-template-columns: repeat(4, 1fr); } }

.panel { animation: fade-in 0.2s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.panel-head p { margin-top: 4px; }

/* ---------- Form controls ---------- */
input[type="text"], select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px; /* 16px stops phones from zooming in on focus */
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]::placeholder { color: var(--muted); opacity: 0.75; }
select {
  appearance: none;
  -webkit-appearance: none;
  padding-inline-end: 36px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%238a93ad' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
}
input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
[aria-invalid="true"] { border-color: var(--danger) !important; }
[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-soft) !important; }

.field { min-width: 0; }
.field-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

/* Segmented switch (Grade / Marks, scale picker) */
.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 13px;
}
.segmented.full { display: flex; }
.segmented.full label { flex: 1; text-align: center; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  padding: 8px 16px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s, color 0.15s;
}
.segmented input:checked + label {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.12);
}
.segmented input:focus-visible + label { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ---------- Subject / semester rows ---------- */
.row-list { display: flex; flex-direction: column; gap: 12px; }

.row {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  animation: fade-in 0.2s ease;
}

/* Phone layout: name on top, numbers below */
.subject-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 46px;
  grid-template-areas:
    "name   name  remove"
    "credit grade grade";
}
.semester-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 46px;
  grid-template-areas:
    "label label  remove"
    "gpa   credit credit";
}
.f-name   { grid-area: name; }
.f-credit { grid-area: credit; }
.f-grade  { grid-area: grade; }
.f-gpa    { grid-area: gpa; }
.sem-label { grid-area: label; }
.remove-btn { grid-area: remove; }

.mode-grade .lbl-marks, .mode-grade .in-marks, .mode-grade .lbl-points, .mode-grade .in-points,
.mode-marks .lbl-grade, .mode-marks .in-grade, .mode-marks .lbl-points, .mode-marks .in-points,
.mode-points .lbl-grade, .mode-points .in-grade, .mode-points .lbl-marks, .mode-points .in-marks { display: none; }

.sem-label { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.sem-badge {
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  background: var(--primary-soft);
  color: var(--primary);
}

.remove-btn {
  align-self: end;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.semester-row .remove-btn { align-self: center; height: 40px; }
.remove-btn:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

.row-msg { grid-column: 1 / -1; font-size: 0.86rem; font-weight: 500; }
.row-msg:empty { display: none; }
.row-msg.is-error { color: var(--danger); }
.row-msg.is-error::before { content: "⚠ "; }
.row-msg.is-info { color: var(--info); }

.rows-head { display: none; }

/* Wider screens: one line per row with column headings */
@media (min-width: 640px) {
  .subject-cols, .subject-row {
    grid-template-columns: minmax(0, 1fr) 110px 150px 46px;
    grid-template-areas: "name credit grade remove";
  }
  .semester-cols, .semester-row {
    grid-template-columns: 130px minmax(0, 1fr) minmax(0, 1fr) 46px;
    grid-template-areas: "label gpa credit remove";
  }
  .row { padding: 10px 12px; }
  .semester-row .remove-btn { height: 46px; }
  .rows-head {
    display: grid;
    gap: 10px;
    padding: 0 13px 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
  }
  .row .field-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 650;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-add {
  width: 100%;
  margin-top: 12px;
  color: var(--primary);
  background: transparent;
  border: 1.5px dashed var(--border);
}
.btn-add:hover { border-color: var(--primary); background: var(--primary-soft); }
.btn-soft { color: var(--primary); background: var(--primary-soft); }
.btn-soft:hover { border-color: var(--primary); }
.btn-outline { color: var(--text); background: var(--surface); border-color: var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-outline.danger-hover:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.btn-quiet { color: var(--muted); background: transparent; }
.btn-quiet:hover { color: var(--text); background: var(--surface-2); }
.btn-inline { margin-top: 6px; padding-inline: 0; color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
.btn-inline:hover { background: transparent; color: var(--primary-hover); }

button:focus-visible, .tab:focus-visible, summary:focus-visible, .logo:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions .btn-soft { flex: 1 1 220px; }

/* ---------- Result box ---------- */
.result {
  margin-top: 20px;
  padding: 20px;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--result-from), var(--result-to));
  box-shadow: 0 10px 30px -12px var(--result-from);
}
.result-label { font-size: 0.85rem; font-weight: 600; opacity: 0.9; text-transform: uppercase; letter-spacing: 0.05em; }
.result-value {
  font-size: clamp(2.6rem, 10vw, 3.4rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.result-value small { font-size: 1.1rem; font-weight: 600; opacity: 0.75; letter-spacing: 0; }
.meter { height: 8px; margin: 12px 0 10px; border-radius: 99px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
.meter span { display: block; width: 0; height: 100%; border-radius: inherit; background: #fff; transition: width 0.4s ease; }
.result-cheer { font-weight: 700; }
.result-cheer:empty { display: none; }
.result-sub { font-size: 0.9rem; opacity: 0.9; }
.result-note {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.86rem;
  background: rgba(255, 255, 255, 0.16);
}

/* ---------- "How is it calculated" + formula ---------- */
.howto { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.howto summary { cursor: pointer; font-weight: 600; color: var(--primary); border-radius: 6px; }
.howto p { margin-top: 8px; }

.formula-line {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-weight: 700;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}
.formula {
  margin-top: 16px;
  padding: 16px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
}
.formula > * + * { margin-top: 8px; }
.formula-title { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.formula-line { color: var(--text); }
.formula-work { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--primary); font-weight: 600; overflow-wrap: anywhere; }

.target-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.target-grid .row-msg { margin-top: 6px; }

.conv-grid { display: grid; gap: 14px; }
@media (min-width: 640px) { .conv-grid { grid-template-columns: 1fr 1fr; align-items: start; } }
.big-input { font-size: 1.25rem !important; font-weight: 700; }
.conv-grid .row-msg { margin-top: 6px; }
.conv-grid .segmented label { padding: 11px 8px; }
/* Four scale choices (Bavarian formula): two per row on phones */
.segmented.conv-wrap { flex-wrap: wrap; }
.segmented.conv-wrap label { flex: 1 1 40%; white-space: nowrap; }

/* ---------- Sidebar ---------- */
.side-title { font-size: 1.05rem; }
.sidebar .card > .muted.small { margin-top: 2px; }
.table-wrap { margin: 12px 0 10px; overflow-x: auto; }
.grade-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grade-table th {
  padding: 6px 8px;
  text-align: start;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.grade-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
.grade-table tr:last-child td { border-bottom: 0; }
.grade-table .num { text-align: end; }
.grade-pill {
  display: inline-block;
  min-width: 36px;
  padding: 2px 8px;
  border-radius: 8px;
  text-align: center;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary);
}

.tips ul { margin: 10px 0 0; padding-inline-start: 18px; color: var(--muted); font-size: 0.9rem; }
.tips li + li { margin-top: 6px; }

/* ---------- University calculator links ---------- */
.uni-section { max-width: 1120px; margin: 0 auto 8px; }
.uni-section h2 { font-size: clamp(1.25rem, 3.6vw, 1.5rem); }
.uni-section > p { margin-top: 4px; }
.uni-grid { display: grid; gap: 14px; margin-top: 16px; }
.uni-country { margin: 26px 0 0; font-size: 1.05rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
@media (min-width: 640px) { .uni-grid { grid-template-columns: repeat(3, 1fr); } }
.uni-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s;
}
.uni-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.uni-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.uni-badge {
  align-self: flex-start;
  margin-bottom: 6px;
  padding: 3px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--primary);
  background: var(--primary-soft);
}
.uni-name { font-weight: 700; font-size: 1.02rem; }
.source-note { font-size: 0.9rem; color: var(--muted); }
.breadcrumb { margin-bottom: 10px; font-size: 0.88rem; color: var(--muted); }
.breadcrumb a { color: var(--primary); font-weight: 600; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ---------- Guide content below the tool ---------- */
.hero-link { color: var(--primary); font-weight: 600; text-decoration: none; }
/* Long words (German compounds, etc.) break neatly instead of overflowing on phones */
h1, h2, h3, p, li, .scale-title, .uni-name, .tab, .btn { overflow-wrap: break-word; hyphens: auto; }
.hero-link:hover { text-decoration: underline; }

.guide { max-width: 780px; margin: 0 auto 48px; font-size: 1.02rem; line-height: 1.7; }
.guide section { scroll-margin-top: 80px; }
.guide h2 { font-size: clamp(1.3rem, 3.8vw, 1.6rem); margin: 48px 0 14px; }
.guide h3 { font-size: 1.12rem; margin: 28px 0 10px; }
.guide p { margin: 0 0 14px; }
.guide ul, .guide ol { margin: 0 0 16px; padding-inline-start: 22px; }
.guide li + li { margin-top: 8px; }
.guide a { color: var(--primary); }

.toc { padding: 18px 20px; }
.toc-title { margin: 0 0 8px !important; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.toc ol { margin: 0; padding-inline-start: 20px; }
.toc li + li { margin-top: 4px; }
.toc a { text-decoration: none; font-weight: 600; }
.toc a:hover { text-decoration: underline; }
@media (min-width: 640px) { .toc ol { columns: 2; column-gap: 32px; } }

.formula-block {
  padding: 12px 16px;
  border-inline-start: 4px solid var(--primary);
  border-radius: 10px;
  background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.95rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.table-scroll {
  margin: 0 0 16px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.94rem; line-height: 1.45; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { padding: 10px 14px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table thead th { background: var(--surface-2); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tfoot th, .data-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
.data-table .num { text-align: end; white-space: nowrap; }

.faq details { border-bottom: 1px solid var(--border); }
.faq details:first-of-type { border-top: 1px solid var(--border); }
.faq summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 2px;
  cursor: pointer;
  list-style: none;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary h3 { margin: 0; font-size: 1.02rem; font-weight: 650; }
.faq summary::after {
  content: "+";
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  transition: transform 0.2s;
}
.faq details[open] summary::after { transform: rotate(45deg); }
.faq details p { padding: 0 2px 4px; color: var(--muted); }

.back-top { margin-top: 28px !important; text-align: center; }
.back-top a { font-weight: 600; text-decoration: none; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); padding: 22px 0 28px; font-size: 0.9rem; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 14px 24px; }
.footer-nav { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.footer-nav a { color: var(--muted); font-weight: 600; text-decoration: none; }
.footer-nav a:hover { color: var(--primary); text-decoration: underline; }

/* ---------- About / Privacy / Terms / Contact pages ---------- */
.page-hero { padding: 36px 0 4px; }
.page-hero h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); font-weight: 800; }
.eyebrow {
  margin: 0 0 8px !important;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
}
.lead { margin-top: 12px !important; font-size: 1.12rem; color: var(--muted); }
.updated { font-size: 0.88rem; color: var(--muted); }

.notice {
  margin: 24px 0;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid var(--warn-border);
  background: var(--warn-soft);
}
.notice-title { margin: 0 0 4px !important; font-weight: 700; color: var(--warn); }
.notice p:last-child, .card > ul:last-child, .card > p:last-child { margin-bottom: 0; }

.contact-card { display: flex; align-items: center; gap: 16px; margin: 28px 0 8px; }
.contact-icon {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--result-from), var(--result-to));
}
.contact-card p { margin: 0 !important; }
.contact-email { font-size: clamp(1.1rem, 4.5vw, 1.4rem); font-weight: 800; text-decoration: none; overflow-wrap: anywhere; }
.contact-email:hover { text-decoration: underline; }

/* ---------- Toast message ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--bg);
  background: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  transform: translate(-50%, 160%);
  transition: transform 0.25s ease;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); }

/* ---------- Print / Save as PDF ---------- */
.print-only { display: none; }

@media print {
  :root, :root[data-theme="dark"] {
    --bg: #ffffff; --surface: #ffffff; --surface-2: #f6f7fb; --border: #d9dde7;
    --text: #151a2d; --muted: #5d6680; --primary: #4f46e5; --primary-soft: #eceafe;
    --danger: #c93434; --info: #2b6cd4; --result-from: #4f46e5; --result-to: #0e9f9a;
    color-scheme: light;
  }
  body { display: block; }
  .site-header { position: static; backdrop-filter: none; }
  .icon-btn, .tabs, .btn, .remove-btn, .tips, .howto, .toast, .hero p, .scale-card p, .rows-head, .guide, .site-nav, .footer-nav, .uni-section, .lang-menu { display: none !important; }
  .print-only { display: block; margin: 8px 0 0; color: var(--muted); font-size: 0.85rem; }
  .card { box-shadow: none; break-inside: avoid; }
  .layout { display: block; }
  .layout > * + * { margin-top: 16px; }
  .sidebar { position: static; }
  .row { break-inside: avoid; }
  .row .field-label { position: static; width: auto; height: auto; clip: auto; }
  .result, .grade-pill, .logo-mark { -webkit-print-color-adjust: exact; print-color-adjust: exact; box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.lang-flag { display: inline-block; min-width: 1.4em; }
