:root{
  /* Vibrant, comfortable dark theme */
  --bg: 12, 14, 30;
  --fg: 245, 247, 255;
  --muted: 185, 195, 218;

  /* lively accents */
  --brand: 94, 176, 255;
  --brand2: 173, 109, 255;
  --accent: 72, 230, 178;

  --glass: 255,255,255;

  --radius-xl: 20px;
  --radius-2xl: 28px;
  --shadow: 0 14px 36px rgba(0,0,0,.48);
  --border: 1px solid rgba(255,255,255,.16);
  --blur: blur(16px);
}

html{ min-height:100%; }

/* 🌞 Light theme: modern golden gradient */
html[data-theme="light"]{
  --bg: 250, 246, 233;
  --fg: 28, 24, 20;
  --muted: 108, 98, 86;

  --brand: 255, 196, 86;
  --brand2: 255, 215, 141;
  --accent: 80, 160, 120;
  --border: 1px solid rgba(0,0,0,.08);
  --shadow: 0 10px 25px rgba(0,0,0,.10);
}

*{ box-sizing: border-box; }

/* Form controls don't inherit the page font by default — make them match */
button, input, select, textarea, optgroup{ font-family: inherit; }
body{
  margin:0;
  font-family:"Google Sans","Noto Sans Khmer",system-ui,-apple-system,Segoe UI,Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif;
  color: rgb(var(--fg));
  background:
    radial-gradient(1200px 520px at 8% -10%, rgba(var(--brand),.28), transparent 60%),
    radial-gradient(1200px 620px at 110% 6%, rgba(var(--brand2),.28), transparent 60%),
    linear-gradient(180deg, rgba(24,26,40,1) 0%, rgba(16,18,33,1) 45%, rgba(12,14,26,1) 100%);
  background-repeat: no-repeat;
  background-color: rgb(12,14,26);   /* matches gradient end, so overscroll never shows a different colour */
  min-height:100vh;
}

/* override background for light theme with golden feel */
html[data-theme="light"] body{
  background:
    radial-gradient(1200px 520px at 8% -10%, rgba(var(--brand),.18), transparent 60%),
    radial-gradient(1200px 620px at 110% 6%, rgba(var(--brand2),.18), transparent 60%),
    linear-gradient(180deg, #fff7e6 0%, #fbe6b2 45%, #f8d98f 100%);
  background-repeat: no-repeat;
  background-color: #f8d98f;
}

.muted{ color: rgb(var(--muted)); }
.hidden{ display:none !important; }
.grow{ flex:1 1 0; }

/* Glass card */
.glass{
  background: linear-gradient(180deg, rgba(var(--glass),.16), rgba(var(--glass),.08));
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: var(--border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow);
}

/* Layout */
.app{ max-width: 920px; margin: 0 auto; padding: 20px 16px 60px; }

/* Topbar */
.topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding: 10px 14px;
}
.brand{ display:flex; align-items:center; gap:10px; font-weight:700; letter-spacing:.3px; }
.logo{
  width:34px; height:34px; display:grid; place-items:center; font-weight:700;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(var(--brand),.55), rgba(var(--brand2),.55));
  color:#fff;
}

.controls{ display:flex; align-items:center; gap:10px; }

/* Language switch: segmented control with a sliding highlight */
.lang-bar{
  position: relative;
  display: grid; grid-template-columns: 1fr 1fr;
  width: 140px; padding: 4px;
  border: var(--border);
  background: rgba(255,255,255,.08);
  border-radius: 999px;
}
.lang-bar::after{
  content:""; position:absolute; top:4px; bottom:4px; left:4px;
  width: calc((100% - 8px) / 2);
  border-radius: 999px;
  background: linear-gradient(135deg, #3f7fe6, #7c5ce6);
  box-shadow: 0 3px 10px rgba(0,0,0,.30);
  transition: transform .25s ease;
}
.lang-bar[data-active="en"]::after{ transform: translateX(100%); }
.lang-bar button{
  position: relative; z-index: 1;
  height: 34px; padding: 0 10px;
  border: none; border-radius: 999px; background: transparent; cursor: pointer;
  font: inherit; font-size: .88rem; font-weight: 600; line-height: 1.2; letter-spacing: .2px;
  color: rgb(var(--muted));
  transition: color .2s ease;
}
.lang-bar button:hover{ color: rgb(var(--fg)); }
.lang-bar button.active{ color: #fff; }
.lang-bar button:focus-visible{ outline: 2px solid rgb(var(--fg)); outline-offset: 2px; }
@media (max-width: 560px){
  .lang-bar{ width: 112px; }
  .lang-bar button{ padding: 0 4px; font-size: .8rem; }
  .topbar .brand{ min-width: 0; font-size: .95rem; }
}
html[data-theme="light"] .lang-bar{ background: rgba(255,255,255,.55); }
html[data-theme="light"] .lang-bar::after{ background: linear-gradient(135deg, #ffc456, #f5a623); box-shadow: 0 3px 10px rgba(120,80,0,.25); }
html[data-theme="light"] .lang-bar button.active{ color: #2b1d00; }

/* Theme button */
.icon-btn{
  border: var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,.08));
  border-radius: 14px; width: 44px; height: 44px;
  display:grid; place-items:center; cursor:pointer;
  transition: transform .15s ease, background .2s ease, box-shadow .25s ease;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
.icon-btn:hover{ transform: translateY(-1px); background: rgba(255,255,255,.18); }
.icon-btn:active{ transform: scale(.98); }

/* Hero */
.hero{ margin-top:14px; padding:24px 18px; text-align:center; }
.hero h1{ margin:0 0 6px; font-size: clamp(1.25rem, 0.9rem + 2vw, 2rem); }
.hero p{ margin:0; }

/* Tabs */
.tabs{
  margin-top: 16px;
  display:grid; grid-template-columns: repeat(auto-fit, minmax(120px,1fr));
  gap:10px; padding: 12px;
}
.tab-btn{
  border: var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.06));
  border-radius: var(--radius-xl);
  padding: 10px 12px; text-align:center; font-weight:600;
  display:flex; align-items:center; justify-content:center; gap:8px;
  cursor:pointer;
  transition: transform .2s ease, background .2s ease, box-shadow .25s ease;
  box-shadow: 0 8px 22px rgba(0,0,0,.25);
}
.tab-btn[aria-selected="true"]{
  background: linear-gradient(135deg, rgba(var(--brand),.45), rgba(var(--brand2),.45));
  box-shadow: 0 8px 24px rgba(0,0,0,.28), 0 0 0 2px rgba(255,255,255,.16) inset, 0 0 40px rgba(var(--brand),.20);
}
.tab-btn:active{ transform: scale(.98); }
.tab-btn{ line-height: 1.25; }
.tab-btn span{ min-width: 0; }
.tab-sub{ display:block; margin-top:2px; font-size:.72rem; font-weight:500; opacity:.8; }

/* 8 tabs: two even rows of 4 on wider screens (narrow screens keep the auto-fit grid, 2 per row) */
@media (min-width: 700px){
  .tabs{ grid-template-columns: repeat(4, 1fr); }
}

/* Coming-soon (disabled) tabs: visibly greyed out and inert */
.tab-btn:disabled,
html[data-theme="dark"] .tab-btn:disabled{
  opacity: .4;
  filter: grayscale(1);
  cursor: not-allowed;
  box-shadow: none;
  color: rgb(var(--muted));
  text-shadow: none;
}
.tab-btn:disabled:active{ transform: none; }

/* Panels */
.panels{ margin-top: 16px; display:grid; gap:16px; }
.panel{ padding:16px; }
.panel-title{ margin: 0 0 10px; font-size: 1.1rem; }

/* Form controls */
.row{ display:flex; gap:12px; align-items:stretch; margin: 10px 0; }
.selects{ align-items:flex-end; }
.field{ display:flex; flex-direction:column; gap:6px; min-width:0; }
.row > .field:only-child{ flex: 1 1 100%; }   /* the Value row: use the whole width */
.input-wrap{ width: 100%; }
.label{ font-size:.9rem; color: rgb(var(--muted)); padding-left: 6px; }

/* input + clear button */
.input-wrap{ position:relative; display:flex; align-items:center; }
.input-wrap .input{ flex:1; padding-right: 40px; }
.icon-btn.clear{
  position:absolute; right:6px;
  background: transparent; border:none; box-shadow:none;
  width:32px; height:32px; display:flex; align-items:center; justify-content:center;
  cursor:pointer; font-size:18px; color: rgb(var(--muted));
  transition: transform .15s ease, color .2s ease;
}
.icon-btn.clear:hover{ transform: scale(1.1); color: rgb(var(--fg)); }

.input, .select{
  width:100%;
  border: var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.06));
  border-radius: 14px; padding: 14px 14px;
  color: rgb(var(--fg)); outline: none; font-size: 1rem;
  transition: box-shadow .2s ease, transform .12s ease, background .2s ease;
  box-shadow: 0 6px 18px rgba(0,0,0,.28);
}
.input:focus, .select:focus{
  box-shadow: 0 0 0 3px rgba(var(--brand), .55), 0 8px 22px rgba(0,0,0,.28);
  background: rgba(255,255,255,.18);
  transform: translateY(-1px);
}

/* Dark mode: tab text brighter */
html[data-theme="dark"] .tab-btn { color: #fff; }
html[data-theme="dark"] .tab-btn[aria-selected="true"] { color: #fff; text-shadow: 0 0 6px rgba(255,255,255,.35); }

/* Optgroup labels white in dark */
html[data-theme="dark"] select optgroup { color: #fff; font-weight: 600; }

/* Pulse on change */
@keyframes pulse { 0%{transform:scale(1)} 45%{transform:scale(1.02)} 100%{transform:scale(1)} }
.pulse-on-change:focus, .pulse-on-change:active{ animation: pulse .35s ease; }

/* Swap and Copy */
.swap{ align-self: end; }

/* 🔁 Quick spin for emoji only */
@keyframes spinOnce { to { transform: rotate(360deg); } }
.swap-icon.spin { display:inline-block; animation: spinOnce .35s linear; }

/* Result: a read-only display, deliberately NOT styled like an input */
.result{ align-items:stretch; }
.result-box{
  position: relative;
  flex: 1 1 auto; padding: 14px 64px 14px 14px;
  border: 1.5px dashed rgba(var(--accent), .60);
  background: rgba(var(--accent), .13);
  border-radius: 16px; box-shadow: none;
  cursor: default;
}
.result-label{ color: rgb(var(--muted)); font-size:.85rem; margin-bottom: 4px; }
.result-label::before{ content:"🔒 "; font-size:.9em; }
.result-value{
  font-weight:700;
  font-size: clamp(0.95rem, 0.9rem + 0.6vw, 1.2rem);
  word-break: break-word;
}
/* copy button sits inside the box, like the clear button inside the value box */
.icon-btn.copy{
  position:absolute; right:10px; top:50%; transform: translateY(-50%);
  width:40px; height:40px; border-radius:12px; font-size:18px;
  background: rgba(255,255,255,.12); border:none; box-shadow:none;
}
.icon-btn.copy:hover{ transform: translateY(-50%) scale(1.08); background: rgba(255,255,255,.22); }
.icon-btn.copy:active{ transform: translateY(-50%) scale(.96); }
html[data-theme="light"] .result-box{ background: rgba(var(--accent), .16); }
html[data-theme="light"] .icon-btn.copy{ background: rgba(255,255,255,.55); }

/* Quick Reference — small computed facts inside each panel */
.quickref{
  margin-top: 14px;
  padding: 12px 14px;
  border: var(--border);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.04));
}
.quickref-title{
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
  color: rgb(var(--muted));
  margin-bottom: 8px;
}
.quickref-list{ display:grid; gap: 6px; }
.quickref-row{
  font-size: .92rem;
  font-variant-numeric: tabular-nums;
}

/* Precision */
.precision{ display:flex; align-items:center; justify-content:space-between; gap:12px; padding: 12px 16px; margin-top: 4px; }
.precision-label{ color: rgb(var(--muted)); }
.range{ width: 180px; accent-color: rgb(var(--brand)); }
.panel .precision{
  background: none; border: none; box-shadow: none; border-radius: 0;
  backdrop-filter: none; -webkit-backdrop-filter: none;
  padding: 6px 4px; margin: 8px 0 0;
}
.panel .precision .range{ width: min(240px, 55%); }

/* About / FAQ */
.about{ margin-top: 20px; padding: 22px 20px; }
.about h2{ margin: 0 0 8px; font-size: 1.1rem; }
.about > p{ margin: 0 0 14px; color: rgb(var(--muted)); }
.about-intro p{ margin: 0 0 12px; color: rgb(var(--muted)); line-height: 1.6; }
.about-intro p:last-child{ margin-bottom: 14px; }
.about-source{ margin: 0 0 18px; font-size: .92rem; color: rgb(var(--muted)); line-height: 1.5; }
.about-source a{ color: rgb(var(--brand)); text-decoration: underline; text-underline-offset: 2px; }

/* Footer: all available scales */
.scales{ margin: 0 0 18px; padding: 20px; text-align:left; color: rgb(var(--fg)); }
.scales h2{ margin: 0 0 14px; font-size: 1.05rem; }
.scales-grid{ display:grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.scale-card{
  padding: 12px 14px;
  border: var(--border);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.04));
}
.scale-card h3{ margin: 0 0 8px; font-size: .9rem; letter-spacing:.2px; }
.scale-group{ margin: 0 0 8px; font-size: .86rem; line-height: 1.55; color: rgb(var(--muted)); }
.scale-group:last-child{ margin-bottom: 0; }
.scale-group-label{
  display:block; font-size:.74rem; font-weight:700; letter-spacing:.3px;
  text-transform: uppercase; color: rgb(var(--fg)); opacity:.75;
}
/* Coming-soon categories echo the greyed-out tabs */
.scale-card.soon{ opacity:.45; filter: grayscale(1); }
.scale-soon{ margin:0; font-size:.86rem; color: rgb(var(--muted)); }
@media (max-width: 700px){ .scales-grid{ grid-template-columns: 1fr; } }
html[data-theme="light"] .scale-group-label{ opacity:.85; }

/* Footer */
.footer{ margin-top:22px; text-align:center; color: rgb(var(--muted)); }
.footer a{
  color: inherit; text-decoration: none; padding: 4px 10px; border-radius: 10px;
  transition: background .2s ease, color .2s ease;
}
.footer a:hover{ background: rgba(255,255,255,.18); color: rgb(var(--fg)); }

/* Toast */
.toast{
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  opacity: 0; pointer-events: none;
  background: rgba(20,22,40,.85);
  color: #fff; padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,.18);
  transition: opacity .25s ease, transform .25s ease;
  z-index: 9999;
}
html[data-theme="light"] .toast{ background: rgba(60,48,24,.9); border-color: rgba(255,255,255,.25); }
.toast.show{ opacity:1; transform: translateX(-50%) translateY(0); }

/* Mobile */
@media (max-width: 560px){
  .row.selects {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }
  .row.selects .field {
    flex: 1 1 40%;
    min-width: 120px;
  }
  .row.selects .swap {
    flex: 0 0 auto;
    width: 44px; height: 44px;
  }
}

/* Mobile: put input + clear button side by side */
@media (max-width: 560px) {
  .input-wrap {
    position: static;
    display: flex;
    align-items: center;
  }
  .input-wrap .input {
    flex: 1;
    padding-right: 0; /* no need to reserve space */
  }
  .icon-btn.clear {
    position: static;
    margin-left: 6px;
  }
}
/* Light theme contrast fixes */
html[data-theme="light"] .logo{ color: rgb(var(--fg)); }
html[data-theme="light"] .about-source a{ color: #8a5a00; }
html[data-theme="light"] .range{ accent-color: #d99a1f; }


/* Time: per-unit explanation lines */
.unit-info{ display:grid; gap:6px; margin-top:10px; }
.unit-info:empty{ display:none; }
.unit-info p{
  margin:0; padding:8px 12px; font-size:.88rem; line-height:1.5;
  border-left:3px solid rgba(var(--accent), .7);
  border-radius:0 10px 10px 0;
  background: rgba(var(--accent), .08);
}
.unit-info strong{ font-weight:700; }
.unit-info .approx{ color: rgb(var(--muted)); }
#time-disclaimer{ font-size:.86rem; line-height:1.55; margin:10px 2px 0; }
