:root {
  color-scheme: light;
  --bg: #f2f7f6;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --text: #142523;
  --muted: #687875;
  --line: #dce8e5;
  --primary: #0f766e;
  --primary-dark: #0a5a54;
  --primary-soft: #dff3ef;
  --accent: #d8a31a;
  --danger: #b94545;
  --shadow: 0 16px 42px rgba(22, 73, 67, 0.1);
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 15px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100svh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -8%, rgba(65, 181, 166, 0.22), transparent 30rem),
    linear-gradient(180deg, #f7fbfa 0%, var(--bg) 48%, #edf5f3 100%);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.24);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 500px);
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

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

.brand-mark {
  display: grid;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  place-items: center;
  color: white;
  border-radius: 16px;
  background: linear-gradient(145deg, #15958a, #0c625c);
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.23);
}

.brand-mark svg {
  width: 32px;
  height: 32px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(21px, 6vw, 26px);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.brand p {
  overflow: hidden;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.install-button,
.copy-button,
.text-button {
  border: 0;
  cursor: pointer;
}

.install-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  min-height: 40px;
  padding: 0 12px;
  color: var(--primary);
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-weight: 700;
  backdrop-filter: blur(12px);
}

.install-button svg,
.copy-button svg,
.primary-button svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.install-button svg {
  width: 18px;
  height: 18px;
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 12px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.connection-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #33a66f;
  box-shadow: 0 0 0 4px rgba(51, 166, 111, 0.12);
}

.connection-pill.offline .connection-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(216, 163, 26, 0.13);
}

.card {
  border: 1px solid rgba(215, 231, 227, 0.88);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.input-card {
  padding: 20px;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.section-heading h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.text-button {
  padding: 5px 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 650;
}

.field-stack {
  display: grid;
  gap: 14px;
}

.field {
  display: block;
}

.field-label {
  display: block;
  margin: 0 0 8px 3px;
  color: #536461;
  font-size: 13px;
  font-weight: 700;
}

.input-wrap {
  display: flex;
  align-items: center;
  min-height: 68px;
  overflow: hidden;
  border: 1.5px solid var(--line);
  border-radius: 18px;
  background: #f8fbfa;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.input-wrap:focus-within {
  border-color: rgba(15, 118, 110, 0.72);
  background: var(--surface-strong);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.09);
}

.input-wrap input {
  width: 100%;
  min-width: 0;
  padding: 13px 6px 13px 17px;
  color: var(--text);
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 29px;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  letter-spacing: -0.035em;
}

.input-wrap input::-webkit-inner-spin-button,
.compact-input input::-webkit-inner-spin-button {
  display: none;
  margin: 0;
  appearance: none;
}

.input-unit {
  flex: 0 0 auto;
  padding: 0 17px 0 10px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 750;
}

.form-error {
  margin: 12px 2px 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 650;
}

.primary-button {
  display: flex;
  width: 100%;
  min-height: 58px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 18px;
  color: white;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(135deg, #12877e, #0b6962);
  box-shadow: 0 13px 26px rgba(15, 118, 110, 0.22);
  cursor: pointer;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.01em;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.primary-button svg {
  width: 21px;
  height: 21px;
}

.primary-button:active {
  transform: translateY(1px) scale(0.995);
  box-shadow: 0 8px 17px rgba(15, 118, 110, 0.2);
  filter: brightness(0.98);
}

.result-card {
  position: relative;
  overflow: hidden;
  margin-top: 16px;
  padding: 21px;
  color: white;
  border-radius: var(--radius-xl);
  background: linear-gradient(145deg, #117c74 0%, #095b56 100%);
  box-shadow: 0 18px 42px rgba(8, 91, 86, 0.25);
}

.result-card::after {
  position: absolute;
  right: -42px;
  bottom: -68px;
  width: 190px;
  height: 190px;
  content: "";
  border: 34px solid rgba(255, 255, 255, 0.055);
  border-radius: 50%;
  pointer-events: none;
}

.result-card.result-iodine {
  background: linear-gradient(145deg, #8a6220 0%, #654615 100%);
  box-shadow: 0 18px 42px rgba(101, 70, 21, 0.22);
}

.result-card.result-balanced {
  background: linear-gradient(145deg, #49655f 0%, #314a45 100%);
  box-shadow: 0 18px 42px rgba(49, 74, 69, 0.2);
}

.result-topline {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.result-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.11);
  font-size: 12px;
  font-weight: 750;
}

.copy-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 9px;
  color: rgba(255, 255, 255, 0.88);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  font-weight: 700;
}

.copy-button svg {
  width: 15px;
  height: 15px;
}

.result-action {
  position: relative;
  z-index: 1;
  margin: 20px 0 2px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 14px;
  font-weight: 650;
}

.result-value-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.result-value-row strong {
  font-size: clamp(48px, 15vw, 66px);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  font-weight: 820;
  letter-spacing: -0.065em;
}

.result-value-row span {
  font-size: 19px;
  font-weight: 750;
}

.result-summary {
  position: relative;
  z-index: 1;
  margin: 8px 0 20px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  line-height: 1.6;
}

.result-metrics {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.12);
}

.result-metrics div {
  min-width: 0;
  padding: 12px 9px;
  background: rgba(0, 0, 0, 0.08);
}

.result-metrics span,
.result-metrics strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-metrics span {
  margin-bottom: 5px;
  color: rgba(255, 255, 255, 0.65);
  font-size: 10px;
}

.result-metrics strong {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.settings-card {
  margin-top: 16px;
  padding: 0 18px;
}

.settings-card summary,
.formula-card summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.settings-card summary::-webkit-details-marker,
.formula-card summary::-webkit-details-marker {
  display: none;
}

.settings-card summary {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-card summary strong {
  font-size: 16px;
}

.settings-card summary svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--muted);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transition: transform 180ms ease;
}

.settings-card[open] summary svg {
  transform: rotate(180deg);
}

.settings-body {
  padding: 0 0 18px;
  border-top: 1px solid var(--line);
}

.compact-field {
  display: flex;
  min-height: 57px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid rgba(220, 232, 229, 0.75);
  color: #4d5e5a;
  font-size: 13px;
  font-weight: 650;
}

.compact-input {
  display: flex;
  flex: 0 0 126px;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f8fbfa;
}

.compact-input:focus-within {
  border-color: rgba(15, 118, 110, 0.65);
}

.compact-input input {
  width: 100%;
  min-width: 0;
  padding: 9px 4px 9px 10px;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
}

.compact-input b {
  padding-right: 10px;
  color: var(--muted);
  font-size: 12px;
}

.settings-note {
  margin: 14px 1px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.formula-card {
  margin: 12px 4px 0;
  color: var(--muted);
  font-size: 12px;
}

.formula-card summary {
  display: inline-flex;
  padding: 8px 4px;
  color: var(--primary);
  font-weight: 750;
}

.formula-content {
  padding: 13px 14px;
  border: 1px dashed #cbded9;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
  line-height: 1.55;
}

.formula-content p {
  margin: 9px 0 4px;
}

.formula-content p:first-child {
  margin-top: 0;
}

.formula-content code {
  display: block;
  overflow-wrap: anywhere;
  color: #38504c;
  font-family: inherit;
  font-size: 12px;
}

.ios-tip {
  position: fixed;
  z-index: 20;
  right: 14px;
  bottom: calc(14px + var(--safe-bottom));
  left: 14px;
  display: flex;
  max-width: 472px;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: auto;
  padding: 13px 15px;
  color: white;
  border-radius: 16px;
  background: rgba(20, 37, 35, 0.94);
  box-shadow: 0 16px 35px rgba(0, 0, 0, 0.24);
  font-size: 13px;
  line-height: 1.45;
  backdrop-filter: blur(16px);
}

.ios-tip button {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  color: white;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.13);
  cursor: pointer;
  font-size: 20px;
}

footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 21px 8px 3px;
  color: #85938f;
  font-size: 11px;
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 30;
  top: calc(12px + var(--safe-top));
  left: 50%;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  color: white;
  border-radius: 999px;
  background: rgba(20, 37, 35, 0.94);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: opacity 180ms ease, transform 180ms ease;
  white-space: nowrap;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

[hidden] {
  display: none !important;
}

@media (max-width: 370px) {
  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .input-card,
  .result-card {
    padding: 17px;
  }

  .brand-mark {
    flex-basis: 44px;
    width: 44px;
    height: 44px;
    border-radius: 14px;
  }

  .brand p {
    max-width: 195px;
  }

  .input-wrap input {
    font-size: 26px;
  }

  .result-metrics div {
    padding-right: 6px;
    padding-left: 6px;
  }

  .result-metrics strong {
    font-size: 11px;
  }
}

@media (min-width: 700px) {
  body {
    padding: 24px 0;
  }

  .app-shell {
    min-height: calc(100svh - 48px);
    border: 1px solid rgba(208, 226, 221, 0.82);
    border-radius: 34px;
    background: rgba(246, 251, 249, 0.74);
    box-shadow: 0 30px 80px rgba(23, 74, 68, 0.12);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d1716;
    --surface: rgba(22, 35, 33, 0.94);
    --surface-strong: #1a2a28;
    --text: #edf7f5;
    --muted: #9aadaa;
    --line: #2e4440;
    --primary: #51c7bb;
    --primary-dark: #2ca79b;
    --primary-soft: #173d39;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
  }

  body {
    background:
      radial-gradient(circle at 12% -8%, rgba(32, 135, 124, 0.24), transparent 30rem),
      linear-gradient(180deg, #111e1c 0%, var(--bg) 58%, #0b1413 100%);
  }

  .install-button {
    background: rgba(24, 43, 40, 0.82);
  }

  .field-label,
  .compact-field {
    color: #b4c6c2;
  }

  .input-wrap,
  .compact-input {
    background: #13211f;
  }

  .formula-content {
    border-color: #35514c;
    background: rgba(21, 36, 33, 0.78);
  }

  .formula-content code {
    color: #bfd1cd;
  }

  @media (min-width: 700px) {
    .app-shell {
      border-color: rgba(56, 82, 77, 0.74);
      background: rgba(15, 27, 25, 0.8);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
