:root {
  color-scheme: light;
  --bg: #fbfbf8;
  --page-top: #ffffff;
  --page-mid: #fcfcfa;
  --page-bottom: #f4f5f1;
  --glow-1: rgba(29, 78, 216, 0.08);
  --glow-2: rgba(15, 118, 110, 0.08);
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --line: rgba(17, 17, 17, 0.08);
  --line-strong: rgba(17, 17, 17, 0.14);
  --text: #111111;
  --muted: rgba(17, 17, 17, 0.56);
  --soft: rgba(17, 17, 17, 0.04);
  --accent: #1d4ed8;
  --accent-soft: rgba(29, 78, 216, 0.08);
  --teal: #0f766e;
  --shadow: 0 24px 80px rgba(17, 17, 17, 0.08);
  --inner-highlight: rgba(255, 255, 255, 0.9);
  --inner-highlight-strong: rgba(255, 255, 255, 0.96);
  --brand-bg: rgba(255, 255, 255, 0.82);
  --control-bg: rgba(255, 255, 255, 0.78);
  --bubble-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(247, 247, 244, 0.88));
  --field-bg: rgba(255, 255, 255, 0.88);
  --result-bg: linear-gradient(180deg, rgba(15, 118, 110, 0.05), rgba(255, 255, 255, 0.92));
  --result-invalid-bg: linear-gradient(180deg, rgba(180, 35, 24, 0.04), rgba(255, 255, 255, 0.92));
  --result-icon-bg: rgba(15, 118, 110, 0.08);
  --result-chip-bg: rgba(15, 118, 110, 0.08);
  --ad-bg:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(247, 247, 244, 0.72)),
    repeating-linear-gradient(
      135deg,
      rgba(17, 17, 17, 0.03) 0,
      rgba(17, 17, 17, 0.03) 10px,
      transparent 10px,
      transparent 20px
    );
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --content: min(100vw - 20px, 372px);
}

html[data-theme="night"] {
  color-scheme: dark;
  --bg: #0d0d11;
  --page-top: #111217;
  --page-mid: #0d0e12;
  --page-bottom: #07070a;
  --glow-1: rgba(92, 123, 255, 0.16);
  --glow-2: rgba(30, 215, 180, 0.09);
  --surface: rgba(28, 28, 32, 0.9);
  --surface-strong: #1d1f25;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #f5f5f7;
  --muted: rgba(245, 245, 247, 0.6);
  --soft: rgba(255, 255, 255, 0.06);
  --accent: #8bb4ff;
  --accent-soft: rgba(139, 180, 255, 0.1);
  --teal: #78e0d2;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --inner-highlight: rgba(255, 255, 255, 0.08);
  --inner-highlight-strong: rgba(255, 255, 255, 0.14);
  --brand-bg: rgba(28, 28, 32, 0.82);
  --control-bg: rgba(28, 28, 32, 0.74);
  --bubble-bg: linear-gradient(180deg, rgba(33, 34, 39, 0.94), rgba(24, 25, 29, 0.88));
  --field-bg: rgba(28, 28, 32, 0.88);
  --result-bg: linear-gradient(180deg, rgba(51, 96, 117, 0.16), rgba(28, 28, 32, 0.92));
  --result-invalid-bg: linear-gradient(180deg, rgba(164, 46, 40, 0.12), rgba(28, 28, 32, 0.92));
  --result-icon-bg: rgba(139, 180, 255, 0.12);
  --result-chip-bg: rgba(139, 180, 255, 0.1);
  --ad-bg:
    linear-gradient(180deg, rgba(28, 28, 32, 0.88), rgba(24, 25, 29, 0.72)),
    repeating-linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.04) 0,
      rgba(255, 255, 255, 0.04) 10px,
      transparent 10px,
      transparent 20px
    );
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at 18% 12%, var(--glow-1), transparent 20%),
    radial-gradient(circle at 82% 18%, var(--glow-2), transparent 18%),
    linear-gradient(180deg, var(--page-top) 0%, var(--page-mid) 42%, var(--page-bottom) 100%);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: transparent;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(100vw - 16px, 1280px);
  margin: 0 auto;
  min-height: 100dvh;
  padding: 8px 0 12px;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas:
    "top"
    "panel"
    "ad";
  grid-template-rows: auto auto minmax(50dvh, 1fr);
  gap: 12px;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  padding: 4px 1px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  max-width: 310px;
  min-height: 40px;
  border: none !important;
  border-radius: 0;
  background: transparent !important;
  box-shadow: none !important;
  overflow: hidden;
}

.brand img {
  display: block;
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  flex: 0 0 40px;
}

.brand-title {
  margin: 0;
  color: var(--text);
  font-size: clamp(0.72rem, 2.7vw, 0.9rem);
  font-weight: 800;
  line-height: 1.16;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.segmented {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--control-bg);
  box-shadow: inset 0 1px 0 var(--inner-highlight);
}

.segment {
  min-width: 36px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 0 10px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--muted);
  transition:
    background-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.segment-icon {
  min-width: 30px;
  width: 30px;
  padding: 0;
  display: grid;
  place-items: center;
}

.segment-emoji {
  padding: 0 8px;
  font-size: 1rem;
  letter-spacing: 0;
}

.segment-emoji[aria-pressed="true"],
.segment-icon[aria-pressed="true"] {
  background: transparent;
  box-shadow: none;
}

.icon {
  display: block;
  font-size: 0.78rem;
  line-height: 1;
  font-weight: 700;
  color: currentColor;
}

.segment[aria-pressed="true"] {
  color: var(--text);
  background: var(--surface-strong);
  box-shadow:
    0 1px 0 var(--inner-highlight-strong),
    0 8px 18px rgba(17, 17, 17, 0.08);
}

.segment:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.panel {
  grid-area: panel;
  display: grid;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.field {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--field-bg);
  box-shadow: inset 0 1px 0 var(--inner-highlight);
}

.field:focus-within {
  border-color: rgba(29, 78, 216, 0.22);
  box-shadow:
    inset 0 1px 0 var(--inner-highlight-strong),
    0 0 0 4px rgba(29, 78, 216, 0.08);
}

.field-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 0;
  border: 0;
  background: transparent !important;
  box-shadow: none;
}

.glyph {
  font-size: 1.35rem;
  line-height: 1;
}

.field-input {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: clamp(1rem, 3.2vw, 1.16rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  outline: none;
}

.field-input[aria-invalid="true"] {
  color: #b42318;
}

.field-input::placeholder {
  color: rgba(17, 17, 17, 0.24);
}

.field-unit {
  justify-self: end;
  min-width: 46px;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
}

.field-emoji {
  min-width: 40px;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
  letter-spacing: 0;
  border: 0;
  background: transparent !important;
  box-shadow: none;
}

.result {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  padding: 12px 12px;
  border: 1px solid rgba(15, 118, 110, 0.12);
  border-radius: 18px;
  background: var(--result-bg);
}

.result[data-state="invalid"] {
  border-color: rgba(180, 35, 24, 0.18);
  background: var(--result-invalid-bg);
}

.result-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 0;
  border: 0;
  background: transparent !important;
  box-shadow: none;
}

.result-main {
  min-width: 0;
  text-align: center;
}

.result-line {
  display: flex;
  align-items: baseline;
  justify-content: center;
  line-height: 1;
}

.result-measure {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.result-measure-ml {
  display: none;
}

.result[data-system="metric"] .result-measure-ml {
  display: flex;
  margin-left: 14px;
  padding-left: 14px;
  border-left: 1px solid var(--line-strong);
}

.result-value {
  font-size: clamp(1.95rem, 9vw, 2.8rem);
  font-weight: 720;
  letter-spacing: -0.06em;
}

.result-unit {
  margin-top: 0.18em;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--result-chip-bg);
  color: var(--teal);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.result-emoji {
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
  background: transparent;
}

.result-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.ad-slot {
  grid-area: ad;
  width: 100%;
  min-height: 50dvh;
  margin: 0;
  border: 1px dashed var(--line-strong);
  border-radius: 22px;
  background: var(--ad-bg);
  box-shadow: inset 0 1px 0 var(--inner-highlight);
  overflow: hidden;
}

.ad-placeholder {
  width: 100%;
  min-height: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 420px) {
  .topbar {
    align-items: flex-start;
  }

  .controls {
    justify-content: flex-start;
  }

  .topbar {
    gap: 8px;
  }

  .brand {
    gap: 7px;
    max-width: calc(100% - 150px);
  }

  .brand img {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .brand-title {
    font-size: 0.72rem;
  }

  .field {
    grid-template-columns: 30px minmax(0, 1fr) auto;
    padding: 8px 9px;
  }

  .field-icon {
    width: 30px;
    height: 30px;
    border-radius: 10px;
  }
}

@media (min-width: 760px) {
  .app-shell {
    grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
    grid-template-areas:
      "top ad"
      "panel ad";
    grid-template-rows: auto 1fr;
    column-gap: 16px;
    row-gap: 12px;
    align-items: start;
  }

  .panel {
    width: min(100%, 372px);
    justify-self: start;
  }

  .ad-slot {
    min-height: 0;
    height: 100%;
    align-self: stretch;
  }
}

.site-footer {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  padding: 4px 0 16px;
  color: var(--muted);
  font-size: 0.78rem;
}

.site-footer a {
  color: inherit;
}

@media (prefers-reduced-motion: no-preference) {
  .panel,
  .bubble,
  .field,
  .segment,
  .brand {
    transition:
      transform 220ms ease,
      box-shadow 220ms ease,
      background-color 220ms ease,
      border-color 220ms ease;
  }

  .bubble:hover {
    transform: translateY(0) scale(1.01);
  }

  .segment:hover:not([aria-pressed="true"]) {
    background: rgba(17, 17, 17, 0.04);
    color: var(--text);
  }

  .brand:hover {
    transform: translateY(-1px);
  }
}
