@font-face {
  font-family: 'DM Sans';
  src: url('/fonts/dm-sans-v17-latin-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: optional;
}

@font-face {
  font-family: 'DM Serif Display';
  src: url('/fonts/dm-serif-display-v17-latin-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: optional;
}

:root {
    --blue: #2b4acb;
    --blue-light: #3d5de8;
    --blue-pale: #e8ecfb;
    --text: #1a1a2e;
    --muted: #6b7280;
    --border: #e5e7eb;
    --bg: #f9fafb;
    --white: #ffffff;
    --red: #dc2626;
  }
  body { 
  font-family: 'DM Sans', sans-serif; 
  background: var(--bg); 
  color: var(--text); 
  min-height: 100vh; 
  font-size: 16px; 
  line-height: 1.6;
  display: flex;           /* + ye add */
  flex-direction: column;  /* + ye add */
}


  header { background: var(--white); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
  .header-inner { max-width: 960px; margin: auto; padding: 0 1.25rem; height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
  .logo { font-family: 'DM Serif Display', serif; font-size: 1.3rem; color: var(--blue); text-decoration: none; letter-spacing: -.3px; }
  nav { display: flex; gap: .25rem; flex-wrap: wrap; }
  nav a { font-size: .8rem; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; color: var(--blue); text-decoration: none; padding: .35rem .65rem; border-radius: 4px; transition: background .15s; }
  nav a:hover, nav a.active { background: var(--blue-pale); }

  .container { max-width: 960px; margin: auto; padding: 2rem 1.25rem 4rem; }
  .page { display: none; }
  .page.active { display: block; }

  .hero { background: var(--white); border: 1px solid var(--border); border-radius: 12px; padding: 2.5rem 2rem; margin-bottom: 2rem; }
  .hero h1 { font-family: 'DM Serif Display', serif; font-size: clamp(1.6rem, 4vw, 2.2rem); color: var(--text); margin-bottom: 1rem; line-height: 1.2; }
  .hero p { color: var(--muted); max-width: 680px; font-size: .97rem; }
  .tab-links { display: flex; gap: 1.5rem; margin-top: 2rem; flex-wrap: wrap; }
  .tab-link { font-size: .8rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--blue); text-decoration: none; padding-bottom: 4px; border-bottom: 2px solid transparent; transition: border-color .2s; }
  .tab-link:hover { border-color: var(--blue); }

  .help-card { background: var(--white); border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem 2rem; margin-bottom: 1.5rem; }
  .help-card h2 { font-family: 'DM Serif Display', serif; font-size: 1.35rem; margin-bottom: .75rem; }
  .help-card p { color: var(--muted); font-size: .92rem; }
  .mode-links { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
  .mode-link { font-size: .78rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--blue); text-decoration: none; cursor: pointer; }
  .mode-link:hover { text-decoration: underline; }

  .weight-entry-card { background: var(--white); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; margin-bottom: 1.5rem; }
  .weight-entry-card h2 { font-family: 'DM Serif Display', serif; font-size: 1.35rem; margin-bottom: .75rem; }
  .weight-entry-card p { color: var(--muted); font-size: .92rem; margin-bottom: 1.25rem; }
  .weight-input-row { display: flex; gap: .75rem; align-items: flex-end; }
  .weight-input-group { flex: 1; }
  .weight-input-group label { display: block; font-size: .75rem; color: var(--muted); margin-bottom: .35rem; font-weight: 500; letter-spacing: .03em; }
  .weight-input-group input { width: 100%; border: none; border-bottom: 2px solid var(--border); padding: .45rem .1rem; font-size: 1rem; font-family: inherit; background: transparent; outline: none; transition: border-color .2s; color: var(--text); }
  .weight-input-group input:focus { border-color: var(--blue); }
  .weight-input-group input::placeholder { color: #bbb; }
  .confirm-btn { background: var(--blue); color: white; border: none; border-radius: 6px; padding: .55rem 1.3rem; font-size: .85rem; font-weight: 600; letter-spacing: .06em; cursor: pointer; font-family: inherit; text-transform: uppercase; transition: background .15s; white-space: nowrap; }
  .confirm-btn:hover { background: var(--blue-light); }

  .calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
  @media(max-width: 600px) { .calc-grid { grid-template-columns: 1fr; } }
  .calc-panel { background: var(--white); border: 1px solid var(--border); border-radius: 12px; padding: 1.75rem 1.5rem; }
  .calc-panel h3 { font-family: 'DM Serif Display', serif; font-size: 1.2rem; margin-bottom: 1.25rem; }

  .weight-tabs { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
  .weight-tab { background: var(--bg); border: 1.5px solid var(--border); border-radius: 8px; padding: .4rem .9rem; font-size: .9rem; font-weight: 500; font-family: inherit; cursor: pointer; color: var(--text); transition: all .15s; }
  .weight-tab.active { background: var(--blue); color: white; border-color: var(--blue); }
  .weight-tab:hover:not(.active) { border-color: var(--blue); color: var(--blue); background: var(--blue-pale); }

  .input-row { display: flex; gap: .75rem; align-items: flex-end; margin-bottom: 1rem; }
  .input-group { flex: 1; }
  .input-group label { display: block; font-size: .75rem; color: var(--muted); margin-bottom: .35rem; font-weight: 500; letter-spacing: .03em; }
  .input-group input { width: 100%; border: none; border-bottom: 2px solid var(--border); padding: .45rem .1rem; font-size: 1rem; font-family: inherit; background: transparent; outline: none; transition: border-color .2s; }
  .input-group input:focus { border-color: var(--blue); }
  .input-group input::placeholder { color: #ccc; }
  .add-btn { background: var(--blue); color: white; border: none; border-radius: 6px; padding: .55rem 1.1rem; font-size: .85rem; font-weight: 600; letter-spacing: .05em; cursor: pointer; font-family: inherit; text-transform: uppercase; transition: background .15s; white-space: nowrap; }
  .add-btn:hover { background: var(--blue-light); }

  .grades-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; min-height: 36px; }
  .grade-chip { background: var(--blue-pale); color: var(--blue); border-radius: 20px; padding: .3rem .8rem; font-size: .9rem; font-weight: 500; cursor: pointer; transition: background .15s, color .15s; display: flex; align-items: center; gap: .3rem; }
  .grade-chip:hover { background: var(--red); color: white; }
  .grade-chip .x { font-size: .7rem; opacity: .6; }

  .result-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 220px; }
  .result-panel h3 { font-family: 'DM Serif Display', serif; font-size: 1.2rem; margin-bottom: 1.5rem; }
  .result-label { color: var(--muted); font-size: .9rem; margin-bottom: .75rem; }
  .result-value { font-family: 'DM Serif Display', serif; font-size: clamp(3rem, 8vw, 5rem); color: var(--blue); letter-spacing: -2px; line-height: 1; transition: color .3s; }
  .result-value.empty { color: #c7d2fe; }
  .result-sub { color: var(--muted); font-size: .8rem; margin-top: .75rem; }
  .reset-btn {
    margin-top: 1.25rem;
    background: #e8457a;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: .5rem 1.4rem;
    font-size: .82rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s, transform .1s;
    display: none;
  }
  .reset-btn:hover { background: #d63368; transform: translateY(-1px); }
  .reset-btn:active { transform: translateY(0); }
  .reset-btn.visible { display: inline-flex; align-items: center; gap: .4rem; }

  .info-section { display: flex; flex-direction: column; gap: 1.5rem; }
  .info-card { background: var(--white); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; }
  .info-card h2 { font-family: 'DM Serif Display', serif; font-size: 1.4rem; margin-bottom: 1rem; }
  .info-card p { color: var(--muted); font-size: .94rem; margin-bottom: 1rem; }
  .formula-box { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem 1.5rem; margin: 1rem 0; font-size: 1.05rem; text-align: center; font-style: italic; }
  .formula-box .frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 .25rem; }
  .formula-box .num { border-bottom: 2px solid var(--text); padding-bottom: 3px; }
  .formula-box .den { padding-top: 3px; }
  .calc-link { font-size: .78rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--blue); text-decoration: none; cursor: pointer; }
  .calc-link:hover { text-decoration: underline; }

  /* ── VALIDATION ── */
  .input-group input.error,
  .weight-input-group input.error { border-color: var(--red) !important; }
  .field-error {
    font-size: .78rem; color: var(--red);
    margin-top: .35rem; display: none; align-items: center; gap: .3rem;
  }
  .field-error.visible { display: flex; }
  .field-error::before { content: '⚠'; font-size: .75rem; }

  @keyframes shake {
    0%,100% { transform: translateX(0); }
    20%      { transform: translateX(-6px); }
    40%      { transform: translateX(6px); }
    60%      { transform: translateX(-4px); }
    80%      { transform: translateX(4px); }
  }
  .shake { animation: shake .35s ease; }

  /* ── KEYBOARD FOCUS STYLES ── */
  :focus-visible {
    outline: 3px solid var(--blue);
    outline-offset: 2px;
    border-radius: 4px;
  }
  .grade-chip:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
  .weight-tab:focus-visible  { outline: 3px solid var(--blue); outline-offset: 2px; }
  /* Inputs use border-bottom — show outline only for keyboard */
  .input-group input:focus-visible,
  .weight-input-group input:focus-visible { outline: none; }

  /* ── TOUCH TARGETS (min 44px for WCAG 2.5.5) ── */
  .add-btn, .confirm-btn, .reset-btn { min-height: 44px; }
  .weight-tab { min-height: 44px; }
  nav a { min-height: 44px; display: flex; align-items: center; }
  .grade-chip { min-height: 36px; }

  /* ── TABLET (768px) ── */
  @media(max-width: 768px) {
    .formula-box { font-size: .88rem; overflow-x: auto; }
    .weight-input-row { flex-direction: column; align-items: stretch; }
    .confirm-btn { width: 100%; }
  }

  /* ── MOBILE (480px) ── */
  @media(max-width: 480px) {
    .header-inner { flex-direction: column; height: auto; padding: .75rem 1rem; gap: .5rem; }
    nav { display: none; }
    nav a { font-size: .72rem; padding: .3rem .5rem; }
    .hero, .help-card, .calc-panel, .info-card, .weight-entry-card { padding: 1.25rem; }
    .hero h1 { font-size: 1.45rem; }
    .input-row { flex-direction: column; align-items: stretch; }
    .add-btn { width: 100%; justify-content: center; }
    .result-panel { min-height: 180px; }
    .result-value { font-size: clamp(2.5rem, 14vw, 4rem); }
    .tab-links { gap: 1rem; }
    .mode-links { gap: 1rem; }
    .formula-box { font-size: .8rem; padding: 1rem; overflow-x: auto; }
    .weight-entry-card p { font-size: .88rem; }
  }

  /* ── VERY SMALL (360px) ── */
  @media(max-width: 360px) {
    nav a { font-size: .68rem; padding: .25rem .4rem; }
    .hero, .help-card, .calc-panel, .info-card, .weight-entry-card { padding: 1rem; }
  }

  /* ══ FOOTER ══════════════════════════════════════════════ */
  footer {
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 2.5rem 1.25rem 2rem;
  margin-top: 2rem;
  min-height: 200px;
  contain: layout style;
  flex-shrink: 0;
  }
  .footer-inner {
    max-width: 960px;
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    text-align: center;
  }
  .footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .4rem 1.5rem;
  }
  .footer-links a {
    font-size: .8rem;
    color: var(--blue);
    text-decoration: none;
    transition: color .15s;
  }
  .footer-links a:hover { color: var(--blue); }
  .footer-links a:hover, .footer-links a[aria-current="page"] { color: var(--blue); background: var(--blue-pale); border-radius: 4px; padding: .35rem .65rem; }
  .footer-socials {
    display: flex;
    gap: 1rem;
    align-items: center;
  }
  .footer-socials a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    color: var(--muted);
    text-decoration: none;
    transition: border-color .15s, color .15s, background .15s;
    font-size: .95rem;
  }
  .footer-socials a:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-pale); }
  .footer-copy {
    font-size: .78rem;
    color: var(--muted);
  }
  .footer-divider {
    width: 100%;
    max-width: 960px;
    height: 1px;
    background: var(--border);
  }
  @media(max-width: 480px) {
    .footer-links { gap: .4rem 1rem; }
    .footer-socials a { width: 34px; height: 34px; font-size: .85rem; }
  }