: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,body{ 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; }
body{
  margin:0;
  font-family:"Noto Sans Khmer","Inter",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%);
  min-height:100%;
}

/* 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%);
}

.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; }

/* ✨ Fancy language switch */
.lang-bar{
  --thumb-x: 0%;
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 6px;
  border: var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.06));
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
  width: 110px;
}

.lang-bar::after{
  content:"";
  position:absolute;
  top:6px; left:6px;
  width: calc(50% - 6px);
  height: calc(100% - 12px);
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(var(--brand),.55), rgba(var(--brand2),.55));
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.35));
  transform: translateX(var(--thumb-x));
  transition: transform .25s ease, background .25s ease;
}

.lang-bar:has([data-lang="km"].active){ --thumb-x: 0%; }
.lang-bar:has([data-lang="en"].active){ --thumb-x: calc(100% + 6px); }
.lang-bar button{
  position: relative; z-index: 1;
  border: none; background: transparent;
  border-radius: 999px; padding: 6px 4px;
  cursor: pointer; font-size: 16px; line-height: 1;
  color: rgba(255,255,255,.9);
  transition: transform .12s ease, color .2s ease;
}
html[data-theme="light"] .lang-bar button{ color: rgba(0,0,0,.75); }
.lang-bar button:hover{ transform: translateY(-1px); }
.lang-bar button.active{ color:#fff; text-shadow: 0 0 12px rgba(255,255,255,.25); }

/* UK flag balancing */
.lang-bar button{
  display:inline-flex; align-items:center; justify-content:center;
  width:48px; height:28px; line-height:1; font-size:18px; padding:0;
}
.lang-bar button[data-lang="en"]{ transform: translateY(0.5px); }

/* 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); }

/* 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; }
.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, .copy{ 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 */
.result{ align-items:center; }
.result-box{
  flex:1 1 auto; padding: 14px;
  border: var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.06));
  border-radius: 16px; box-shadow: 0 6px 18px rgba(0,0,0,.28);
}
.result-label{ color: rgb(var(--muted)); font-size:.85rem; margin-bottom: 4px; }
.result-value{
  font-weight:700;
  font-size: clamp(0.95rem, 0.9rem + 0.6vw, 1.2rem);
  word-break: break-word;
}

/* 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)); }

/* 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,
  .row.selects .copy {
    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;
  }
}