:root{
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  --bg1:#f6f7fb;
  --bg2:#eef2ff;
  --card:#ffffff;
  --text:#0f172a;
  --muted:#475569;
  --line:#e2e8f0;
  --line2:#d7dbe7;
  --brand:#2563eb;
  --brand2:#7c3aed;
  --shadow: 0 18px 50px rgba(2,6,23,0.12);
  --shadow2: 0 8px 24px rgba(2,6,23,0.10);
  --radius: 18px;

  --pad: 14px;
  --pad-lg: 18px;
  --tap: 44px;
}

*{ box-sizing:border-box; }

html, body { height: 100%; }

body{
  margin:0;
  padding:16px 12px 110px; /* extra bottom space for sticky actions on mobile */
  color:var(--text);
  background:
    radial-gradient(1200px 600px at 10% 0%, rgba(37,99,235,0.14), rgba(37,99,235,0) 60%),
    radial-gradient(900px 500px at 90% 10%, rgba(124,58,237,0.12), rgba(124,58,237,0) 55%),
    linear-gradient(180deg, var(--bg2), var(--bg1));
}

.wrap{
  max-width: 980px;
  margin:0 auto;
}

.topbar{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
  margin-bottom:12px;
}

.brand{
  display:flex;
  align-items:center;
  gap:12px;
  min-width: 220px;
}

.logo{
  width:42px;
  height:42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  box-shadow: 0 12px 30px rgba(37,99,235,0.25);
  position: relative;
  overflow:hidden;
  flex: 0 0 auto;
}
.logo:before{
  content:"";
  position:absolute;
  inset:-50%;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.55), rgba(255,255,255,0) 55%);
  transform: rotate(18deg);
}

.titles h1{
  font-size: 20px;
  margin:0;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.titles .sub{
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.2;
}

.statusPill{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:8px 12px;
  border-radius: 999px;
  border:1px solid var(--line);
  background: rgba(255,255,255,0.85);
  box-shadow: var(--shadow2);
  font-size: 12px;
  color: #0b1220;
}

.dot{
  width:8px;height:8px;border-radius:999px;
  background: var(--brand);
  box-shadow: 0 0 0 4px rgba(37,99,235,0.15);
}

.card{
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(226,232,240,0.95);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}

.hero{
  padding: var(--pad-lg) var(--pad-lg) 10px;
  border-bottom: 1px solid rgba(226,232,240,0.85);
  background:
    radial-gradient(900px 300px at 10% 0%, rgba(37,99,235,0.10), rgba(37,99,235,0) 55%),
    radial-gradient(900px 300px at 90% 20%, rgba(124,58,237,0.08), rgba(124,58,237,0) 55%);
}

.tagline{
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.content{
  padding: var(--pad);
  display:grid;
  gap: 12px;
}

/* Mode control */
.mode{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  flex-wrap:wrap;
  padding: 12px;
  border-radius: 14px;
  background: rgba(248,250,252,0.85);
  border: 1px solid rgba(226,232,240,0.95);
}
.mode strong{ font-size: 13px; color:#0b1220; }

.seg{
  display:flex;
  border: 1px solid rgba(226,232,240,0.95);
  background: #fff;
  border-radius: 999px;
  overflow:hidden;
  box-shadow: 0 6px 18px rgba(2,6,23,0.06);
}
.seg label{
  display:flex;
  align-items:center;
  gap:8px;
  padding: 10px 12px;
  cursor:pointer;
  user-select:none;
  font-size: 13px;
  color:#0f172a;
  white-space:nowrap;
  min-height: var(--tap);
}
.seg input{ display:none; }
.seg label span{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:18px;height:18px;border-radius:999px;
  border: 1px solid rgba(226,232,240,0.95);
  background: #fff;
  font-size: 12px;
  color: #334155;
}
.seg input:checked + label{
  background: linear-gradient(135deg, rgba(37,99,235,0.12), rgba(124,58,237,0.10));
  font-weight: 800;
}
.seg input:checked + label span{
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  border-color: transparent;
  color:#fff;
}

/* Form grid: 1 col on mobile, 2 cols on wider screens */
.grid{
  display:grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

@media (min-width: 780px){
  body{ padding:28px 18px 40px; }
  .content{ padding: 18px; gap: 14px; }
  .grid{ grid-template-columns: 1fr 1fr; }
  .titles h1{ font-size: 22px; }
}

.field{
  background: #fff;
  border: 1px solid rgba(226,232,240,0.95);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 8px 22px rgba(2,6,23,0.05);
}

.field label{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin: 0 0 8px;
  font-size: 13px;
  color: #0b1220;
  font-weight: 800;
}

.hint{
  font-weight: 600;
  font-size: 12px;
  color: #64748b;
}

input, select{
  width:100%;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid rgba(215,219,231,0.98);
  font-size: 16px; /* prevents iOS zoom on focus */
  outline:none;
  background: #fff;
  color: var(--text);
  min-height: var(--tap);
}

input:focus, select:focus{
  border-color: rgba(37,99,235,0.65);
  box-shadow: 0 0 0 4px rgba(37,99,235,0.18);
}

.helper{
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

/* Presets: grid on mobile so they don’t wrap awkwardly */
.presets{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap:10px;
  margin-top: 10px;
}
@media (max-width: 360px){
  .presets{ grid-template-columns: 1fr; }
}

.preset{
  border: 1px solid rgba(226,232,240,0.95);
  background: #fff;
  border-radius: 999px;
  padding: 10px 10px;
  cursor:pointer;
  font-size: 13px;
  box-shadow: 0 8px 22px rgba(2,6,23,0.05);
  min-height: var(--tap);
}
.preset:hover{
  border-color: rgba(37,99,235,0.55);
  box-shadow: 0 10px 26px rgba(2,6,23,0.08);
}

/* Advanced */
details.advanced{
  border-radius: 14px;
  border: 1px dashed rgba(203,213,225,0.98);
  background: rgba(255,255,255,0.95);
  padding: 12px;
}
details.advanced summary{
  cursor:pointer;
  user-select:none;
  font-weight: 900;
  font-size: 13px;
  color:#0b1220;
  list-style:none;
  display:flex;
  align-items:center;
  gap:10px;
}
details.advanced summary::-webkit-details-marker{ display:none; }

.chev{
  width: 18px; height: 18px; border-radius: 999px;
  display:inline-flex; align-items:center; justify-content:center;
  background: rgba(37,99,235,0.10);
  border: 1px solid rgba(37,99,235,0.20);
  font-size: 12px;
  color: var(--brand);
  transition: transform 160ms ease;
}
details[open] .chev{ transform: rotate(90deg); }

/* Sticky action bar on mobile */
.actions{
  display:flex;
  gap: 10px;
  flex-wrap:wrap;
  align-items:center;
  justify-content:space-between;
  padding: 10px;
  border-radius: 16px;
  border: 1px solid rgba(226,232,240,0.95);
  background: rgba(255,255,255,0.92);
}

@media (max-width: 780px){
  .actions{
    position: sticky;
    bottom: 10px;
    z-index: 20;
    box-shadow: 0 14px 34px rgba(2,6,23,0.12);
    backdrop-filter: blur(8px);
  }
  .actions > button{
    flex: 1 1 calc(50% - 10px);
  }
  .actions > button.primary{
    flex-basis: 100%;
  }
}

button{
  border:0;
  border-radius: 14px;
  padding: 12px 14px;
  cursor:pointer;
  font-size: 14px;
  box-shadow: 0 10px 24px rgba(2,6,23,0.10);
  min-height: var(--tap);
}

.primary{
  color:#fff;
  background: linear-gradient(135deg, var(--brand), var(--brand2));
}

.secondary{
  background: #fff;
  color: #1e3a8a;
  border: 1px solid rgba(226,232,240,0.95);
}

.ghost{
  background: rgba(241,245,249,0.95);
  color: #0f172a;
  border: 1px solid rgba(226,232,240,0.95);
  box-shadow: 0 8px 18px rgba(2,6,23,0.07);
}

button:active{
  transform: translateY(1px);
}

.error{
  color: #b91c1c;
  font-size: 13px;
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(185,28,28,0.08);
  border: 1px solid rgba(185,28,28,0.20);
  display:none;
}

.warn{
  color: #7c2d12;
  font-size: 13px;
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(124,45,18,0.07);
  border: 1px solid rgba(124,45,18,0.18);
  display:none;
}

.output{
  background: #fff;
  border: 1px solid rgba(226,232,240,0.95);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 10px 26px rgba(2,6,23,0.06);
}

.headlineTop{
  font-size: 16px;
  font-weight: 900;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}

.big{
  font-size: 18px;
  font-weight: 900;
  margin: 0 0 6px;
}

@media (min-width: 780px){
  .headlineTop{ font-size: 18px; }
  .big{ font-size: 18px; }
}

.muted{
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.verdict{
  margin-top: 10px;
  font-size: 14px;
  font-weight: 900;
  color: #0b1220;
}

.caption{
  margin-top: 6px;
  font-size: 14px;
  color: #0b1220;
}

.list{
  margin: 12px 0 0;
  padding-left: 18px;
  color: #0f172a;
}
.list li{ margin: 6px 0; }

.meter{
  margin-top: 12px;
  border-radius: 999px;
  background: rgba(226,232,240,0.95);
  height: 12px;
  overflow:hidden;
  border: 1px solid rgba(203,213,225,0.95);
}
.meter > div{
  height:100%;
  width:0%;
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  transition: width 220ms ease;
}

.meterLabels{
  display:flex;
  justify-content:space-between;
  font-size: 11px;
  color: #64748b;
  margin-top: 6px;
  gap: 10px;
}
.meterLabels span{
  flex: 1 1 0;
}
.meterLabels span:nth-child(2){
  text-align:center;
}
.meterLabels span:nth-child(3){
  text-align:right;
}

details.breakdown{
  margin-top: 12px;
  background: rgba(248,250,252,0.85);
  border: 1px solid rgba(226,232,240,0.95);
  border-radius: 14px;
  padding: 10px 12px;
}
details.breakdown summary{
  cursor:pointer;
  user-select:none;
  font-weight: 900;
  font-size: 13px;
  color:#0b1220;
  list-style:none;
  display:flex;
  align-items:center;
  gap:10px;
}
details.breakdown summary::-webkit-details-marker{ display:none; }

.mathLine{
  margin-top: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  background: #0b1220;
  color: #e5e7eb;
  padding: 10px 12px;
  border-radius: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.share{
  background: #fff;
  border: 1px dashed rgba(203,213,225,0.98);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 10px 26px rgba(2,6,23,0.06);
}

.shareHead{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  flex-wrap:wrap;
  margin-bottom: 10px;
}

.shareHead strong{ font-size: 13px; }

.share code{
  display:block;
  padding: 10px 12px;
  border-radius: 12px;
  background: #0b1220;
  color: #e5e7eb;
  overflow-x:auto;
  font-size: 12px;
  user-select: all;
  line-height: 1.35;
  word-break: break-all;
  -webkit-overflow-scrolling: touch;
}

.inlinePill{
  background:#f1f5f9;
  border:1px solid #e2e8f0;
  padding:6px 10px;
  border-radius:999px;
  font-size:12px;
  color:#0b1220;
}

.note{
  margin: 12px 0 0;
  font-size: 12px;
  color: #64748b;
  line-height: 1.45;
}

.footer{
  margin: 10px 0 0;
  font-size: 12px;
  color: #64748b;
}

/* Accessibility: reduce motion */
@media (prefers-reduced-motion: reduce){
  *{ scroll-behavior: auto !important; }
  button, .meter > div{ transition: none !important; }
}