/* =========================================================
   SpeedDistanceCalculator.com — COMPLETE CSS (FINAL)
   ✅ Attractive light theme (not dull)
   ✅ Inputs:
      - #inputsGrid is flex
      - 2nd + 3rd blocks stay in one row when JS adds .pair45 (45% each)
      - Unit box never cuts text (km/h, hour, seconds)
      - Distance row uses space properly (no wasted right side)
   ✅ Dropdown:
      - Closed select text centered
      - Options centered
   ✅ Steps:
      - ONLY mathematical operations look handwritten
      - Normal text stays normal (NOT cursive)
      - Handwritten math ink = RED
      - Lined notebook background ONLY behind math tokens area
      - Slight human tilt + subtle pen-pressure shadow ONLY on math
   ✅ Responsive: 360px → 2000px
   ========================================================= */


/* ================= TOKENS ================= */
:root{
  --bg:#f4f7fb;
  --bg2:#eef3fb;

  --card:#ffffff;
  --text:#0f172a;
  --muted:#475569;
  --muted2:#64748b;

  --line:#e5e7eb;

  --brand:#2563eb;
  --brand2:#1d4ed8;
  --brand3:#60a5fa;

  --brandSoft:rgba(37,99,235,.10);
  --brandSoft2:rgba(37,99,235,.18);

  --good:#10b981;
  --warn:#f59e0b;
  --bad:#ef4444;

  --shadow:0 12px 30px rgba(2,6,23,.10);
  --shadow2:0 10px 22px rgba(2,6,23,.08);
  --shadow3:0 22px 60px rgba(2,6,23,.12);

  --r10:10px;
  --r12:12px;
  --r14:14px;
  --r16:16px;
  --r18:18px;
  --r24:24px;

  --max:1140px;

  /* handwritten stack (browser safe) */
  --hand: "Segoe Print","Bradley Hand","Comic Sans MS","Chalkboard SE","Marker Felt",cursive;

  /* red ink */
  --ink:#b10012;
  --inkDark:#8f000e;
}


/* ================= RESET ================= */
*{box-sizing:border-box;margin:0;padding:0}
html{scroll-behavior:smooth}
body{
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  line-height:1.55;
  color:var(--text);
  background:
    radial-gradient(1100px 620px at 12% 0%, rgba(37,99,235,.12), transparent 62%),
    radial-gradient(900px 560px at 92% 10%, rgba(96,165,250,.10), transparent 60%),
    linear-gradient(180deg, var(--bg), var(--bg2));
  min-height:100vh;
  overflow-x:hidden;
}
img{max-width:100%;height:auto;display:block}
a{color:inherit;text-decoration:none}

/* Skip link */
.skip{
  position:absolute;left:-9999px;top:auto;width:1px;height:1px;overflow:hidden;
}
.skip:focus{
  position:fixed;left:16px;top:16px;width:auto;height:auto;
  padding:10px 12px;border-radius:var(--r14);
  background:#fff;border:1px solid var(--line);
  box-shadow:var(--shadow2);
  z-index:9999;
}


/* ================= HEADER ================= */
header{
  position:sticky;top:0;z-index:50;
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(12px);
  border-bottom:1px solid rgba(229,231,235,.80);
  transition: background .25s ease, box-shadow .25s ease, border-color .25s ease, transform .25s ease;
}
header.is-scrolled{
  background: rgba(255,255,255,.94);
  box-shadow: 0 10px 26px rgba(2,6,23,.10);
  border-bottom-color: rgba(219,230,247,1);
}

.topbar{
  max-width:var(--max);
  margin:0 auto;
  padding:12px 16px;
  display:flex;
  align-items:center;
  gap:12px;
  flex-wrap:wrap;
}

.brand{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:240px;
}

.logo{
  width:38px;height:38px;border-radius:var(--r14);
  background:
    radial-gradient(18px 18px at 30% 30%, rgba(255,255,255,.90), transparent 60%),
    linear-gradient(135deg, var(--brand), var(--brand3));
  border:1px solid rgba(37,99,235,.18);
  box-shadow: 0 18px 46px rgba(37,99,235,.20);
  transition: transform .25s ease;
}
header.is-scrolled .logo{transform: translateY(-1px)}

.brand strong{font-size:14px;letter-spacing:.2px}
.brand span{display:block;font-size:12px;color:var(--muted2);margin-top:-2px}

nav{
  margin-left:auto;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
  justify-content:flex-end;
}
nav a{
  font-size:13px;
  color:var(--muted);
  padding:8px 10px;
  border-radius:var(--r12);
  border:1px solid transparent;
  transition: background .2s ease, border-color .2s ease, color .2s ease, transform .08s ease;
}
nav a:hover{
  color:var(--text);
  background: var(--brandSoft);
  border-color: var(--brandSoft2);
}
nav a:active{transform: translateY(1px)}


/* ================= BUTTONS ================= */
.btn{
  appearance:none;
  border:1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  color:var(--text);
  padding:10px 12px;
  border-radius:var(--r14);
  font-weight:900;
  font-size:13px;
  cursor:pointer;
  display:inline-flex;
  gap:8px;
  align-items:center;
  white-space:nowrap;
  box-shadow: 0 8px 18px rgba(2,6,23,.06);
  transition: transform .08s ease, box-shadow .2s ease, border-color .2s ease, filter .2s ease;
}
.btn:hover{
  border-color: rgba(37,99,235,.22);
  box-shadow: 0 14px 30px rgba(2,6,23,.10);
  filter: brightness(1.02);
}
.btn:active{transform: translateY(1px)}
.btn.primary{
  color:#fff;
  border-color: rgba(29,78,216,.35);
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  box-shadow: 0 18px 52px rgba(37,99,235,.22);
}
.btn.primary:hover{box-shadow: 0 20px 58px rgba(37,99,235,.26)}
.btn.good{
  border-color: rgba(16,185,129,.24);
  background: linear-gradient(135deg, rgba(16,185,129,.16), rgba(16,185,129,.08));
}
.btn.mini{padding:9px 10px;border-radius:var(--r12);font-size:12px;font-weight:950}


/* ================= LAYOUT ================= */
main{max-width:var(--max);margin:0 auto;padding:18px 16px 64px}

.hero{
  display:grid;
  grid-template-columns:1.2fr .8fr;
  gap:16px;
  align-items:stretch;
  margin-top:14px;
}

.card{
  background:var(--card);
  border:1px solid rgba(229,231,235,.95);
  border-radius:var(--r24);
  box-shadow:var(--shadow3);
  overflow:hidden;
}

.headline{padding:18px 18px 12px}
h1{
  margin:0;
  font-size:clamp(22px,2.6vw,36px);
  line-height:1.15;
  letter-spacing:-.3px;
}
.sub{
  margin:10px 0 0;
  color:var(--muted);
  font-size:14px;
  max-width:72ch;
}


/* ================= INPUTS GRID ================= */
#inputsGrid{
  display:flex;
  flex-wrap:wrap;
  gap:12px;
  padding:14px 18px 10px;
}

/* each block full width default */
#inputsGrid > [data-block]{flex:0 0 100%;max-width:100%}

/* JS adds .pair45 to 2nd & 3rd blocks */
#inputsGrid > .pair45{flex:0 0 45%;max-width:45%;min-width:0}

/* keep solve always full width */
#inputsGrid > [data-block="solve"]{flex:0 0 100%;max-width:100%}

label{
  display:block;
  font-size:12px;
  color:var(--muted2);
  margin:0 0 6px 2px;
  letter-spacing:.2px;
}


/* ================= FIELD (INPUT + UNIT) =================
   Your HTML structure:
   .field (outer) contains:
     - input
     - div.field.selectWrap (inner) contains select
========================================================= */
.field{
  position:relative;
  display:flex;
  align-items:stretch;
  border:1px solid rgba(229,231,235,.95);
  border-radius:var(--r16);
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  overflow:hidden;
  transition: border-color .18s ease, box-shadow .18s ease, transform .12s ease;
}
.field:hover{
  border-color: rgba(37,99,235,.22);
  box-shadow: 0 12px 26px rgba(2,6,23,.08);
}
.field:focus-within{
  border-color: rgba(37,99,235,.55);
  box-shadow: 0 14px 30px rgba(37,99,235,.16);
  transform: translateY(-1px);
}

/* input */
.field > input{
  flex:1;
  min-width:0;
  padding:12px 14px;
  border:0;
  outline:none;
  background:transparent;
  color:var(--text);
  font-size:14px;
  font-weight:900;
  letter-spacing:.1px;
}
.field > input::placeholder{color:#94a3b8;font-weight:800}
.field > input:disabled{background:#f3f6fb;color:#64748b;cursor:not-allowed}

/* unit wrapper (inner .field) */
.field > .field{
  flex:0 0 auto;
  width:clamp(112px, 30%, 170px); /* ✅ wide enough for km/h, hour, seconds */
  min-width:112px;
  border:0 !important;
  border-left:1px solid rgba(229,231,235,.95) !important;
  border-radius:0 !important;
  background:transparent !important;
  display:flex;
  align-items:stretch;
  overflow:hidden;
}

/* ✅ Distance row: unit is not very useful wide -> compact it, give input more space */
#inputsGrid > [data-block="distance"] .field > .field{
  width:clamp(92px, 18%, 138px);
  min-width:92px;
}

/* select (closed) centered */
.field select{
  max-width:none;              /* IMPORTANT: prevents cutting */
  width:100%;
  border:0;
  outline:none;
  background: linear-gradient(180deg, #f8fbff, #f1f7ff);
  color:var(--text);
  padding:12px 42px 12px 12px; /* arrow room */
  font-size:13px;
  font-weight:950;
  cursor:pointer;
  -webkit-appearance:none;
  appearance:none;
  white-space:nowrap;

  /* ✅ center the text */
  text-align:center;
  text-align-last:center;
  -moz-text-align-last:center;
}

/* options centered */
.field select option{
  text-align:center;
  background:#fff;
  color:var(--text);
}

/* dropdown arrow (for selectWrap) */
.field.selectWrap::after{
  content:"";
  position:absolute;
  right:14px;
  top:50%;
  width:10px;height:10px;
  border-right:2px solid rgba(15,23,42,.55);
  border-bottom:2px solid rgba(15,23,42,.55);
  transform: translateY(-60%) rotate(45deg);
  pointer-events:none;
  opacity:.9;
}


/* ================= ACTIONS / HINT ================= */
.actionsBelowTime{
  padding:0 18px 18px;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}
.hint{
  color:var(--muted2);
  font-size:12px;
  padding:0 18px 8px;
}


/* ================= OUTPUT ================= */
.out{
  border-top:1px solid rgba(229,231,235,.95);
  background:
    radial-gradient(520px 190px at 10% 10%, rgba(37,99,235,.06), transparent 60%),
    linear-gradient(180deg, #fbfdff, #ffffff);
  padding:16px 18px 18px;
}
.resultBar{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}
.big{
  font-size:clamp(18px,2.2vw,28px);
  font-weight:950;
  letter-spacing:-.2px;
  margin:0;
}
.big small{
  display:block;
  margin-top:6px;
  font-size:12px;
  font-weight:850;
  color:var(--muted);
}
.miniActions{display:flex;gap:8px;flex-wrap:wrap}


/* ================= STEPS ================= */
.steps{margin-top:12px;display:grid;gap:10px}

.stepBox{
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  border:1px solid rgba(229,231,235,.95);
  border-radius:var(--r18);
  padding:12px;
  box-shadow: 0 10px 22px rgba(2,6,23,.06);
}

/* Step title stays NORMAL (not cursive) */
.stepTitle{
  font-size:12px;
  color:var(--muted2);
  margin:0 0 8px;
  font-weight:950;
  letter-spacing:.22px;
  text-transform:uppercase;
  font-family:inherit;
}

/* =========================================================
   ✅ ONLY MATH OPERATIONS HANDWRITTEN (RED INK)
   IMPORTANT: We apply handwriting ONLY to .mono tokens inside .math.
   Normal words like "Convert" stay NORMAL.
   ========================================================= */
.stepBox .math{
  /* keep words NORMAL */
  font-family: inherit;
  font-size:14.5px;
  font-weight:800;
  color:var(--text);
  line-height:1.55;
  margin:0;
  word-break:break-word;
}

/* The math tokens (pills) become handwritten red */
.stepBox .math .mono,
.stepBox .mono{
  font-family: var(--hand);
  color: var(--ink);
  font-size:15.5px;
  font-weight:800;

  /* human writing feel */
  transform: rotate(-0.28deg);
  transform-origin:left top;
  text-shadow: 0.2px 0.2px 0 rgba(0,0,0,.10);

  /* notebook area only for tokens */
  background:
    linear-gradient(180deg, rgba(255,255,255,.92), rgba(255,255,255,.92)),
    repeating-linear-gradient(
      to bottom,
      rgba(15,23,42,.08) 0px,
      rgba(15,23,42,.08) 1px,
      transparent 1px,
      transparent 28px
    );

  border:1px solid rgba(37,99,235,.22);
  border-radius:14px;
  padding:6px 10px;
  display:inline-block;
  margin:2px 2px;
}

/* make tokens a little darker on hover like ink */
.stepBox .math .mono:hover{color:var(--inkDark)}

/* Optional fraction helper if you use .frac in future */
.stepBox .math .frac{
  display:inline-grid;
  grid-template-rows:auto 3px auto;
  align-items:center;
  justify-items:center;
  padding:0 4px;
}
.stepBox .math .frac .bar{
  height:3px;
  width:100%;
  background: var(--ink);
  border-radius:999px;
  opacity:.95;
}

/* messages */
.msg{
  margin-top:10px;
  padding:10px 12px;
  border-radius:var(--r16);
  border:1px solid rgba(229,231,235,.95);
  background:#f8fbff;
  color:var(--muted);
  font-size:12px;
}
.msg.ok{border-color: rgba(16,185,129,.30); background: rgba(16,185,129,.08); color:#0b1a2a}
.msg.warn{border-color: rgba(245,158,11,.35); background: rgba(245,158,11,.10); color:#0b1a2a}
.msg.bad{border-color: rgba(239,68,68,.28); background: rgba(239,68,68,.10); color:#0b1a2a}


/* ================= RIGHT COLUMN ================= */
.side{display:grid;gap:16px}
.adbox{
  border-radius:var(--r24);
  border:1px dashed rgba(37,99,235,.30);
  background:
    radial-gradient(420px 160px at 15% 20%, rgba(37,99,235,.10), transparent 60%),
    rgba(37,99,235,.05);
  padding:16px;
  min-height:160px;
  display:flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  color:var(--muted);
  font-size:13px;
}
.adbox strong{color:var(--text)}
.quick{padding:16px}

.list{list-style:none;margin:0;padding:0;display:grid;gap:10px}
.list li{
  display:flex;gap:10px;align-items:flex-start;
  padding:10px;
  border-radius:var(--r16);
  border:1px solid rgba(229,231,235,.95);
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  color:var(--muted);
  font-size:13px;
  box-shadow: 0 8px 18px rgba(2,6,23,.06);
}
.dot{
  width:10px;height:10px;border-radius:999px;margin-top:6px;flex:0 0 auto;
  background: linear-gradient(135deg, var(--brand), var(--brand3));
  box-shadow: 0 10px 26px rgba(37,99,235,.18);
}


/* ================= CONTENT / FOOTER ================= */
section{margin-top:18px}
.contentGrid{display:grid;grid-template-columns:1fr 1fr;gap:16px}
.pad{padding:18px}
h2{margin:0 0 10px;font-size:18px;letter-spacing:-.2px;color:var(--text)}
p{margin:0 0 10px;color:var(--muted);font-size:14px}

footer{
  margin-top:26px;
  border-top:1px solid rgba(229,231,235,.95);
  background:#fff;
}
.foot{
  max-width:var(--max);
  margin:0 auto;
  padding:18px 16px;
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:center;
  justify-content:space-between;
  color:var(--muted2);
  font-size:12px;
}
.foot .links{display:flex;gap:12px;flex-wrap:wrap}


/* ================= RESPONSIVE ================= */
@media (max-width: 980px){
  .hero{grid-template-columns:1fr}
  .contentGrid{grid-template-columns:1fr}
  nav{justify-content:flex-start;margin-left:0}
  .brand{min-width:unset}
}

@media (max-width: 540px){
  .btn.primary{flex:1}
  .actionsBelowTime .btn:not(.primary){flex:1}
  .miniActions{width:100%}
  .miniActions .btn{flex:1}
}

/* 360px → 520px: keep inputs perfect */
@media (min-width: 360px) and (max-width: 520px){
  #inputsGrid{padding:12px 14px 10px;gap:10px}

  /* keep pair45 side by side */
  #inputsGrid > .pair45{flex:0 0 45%;max-width:45%}

  /* keep unit readable (no cut) */
  .field > .field{
    width:clamp(108px, 34%, 160px);
    min-width:108px;
  }
  #inputsGrid > [data-block="distance"] .field > .field{
    width:clamp(92px, 22%, 132px);
    min-width:92px;
  }

  .field > input{padding:11px 12px;font-size:14px}
  .field select{padding:11px 38px 11px 10px;font-size:12.8px}

  /* tokens slightly smaller on small screens */
  .stepBox .math .mono{font-size:15px;padding:6px 9px}
}

/* Print */
@media print{
  header, .adbox, nav, .miniActions, .actionsBelowTime{display:none !important}
  body{background:#fff;color:#000}
  .card,.stepBox{box-shadow:none}
  .card{border:1px solid #ccc}
}

