:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #101419;
  color: #f5f7f2;
  --panel: #181e25;
  --panel-soft: #202832;
  --line: #303946;
  --muted: #98a3ad;
  --text: #f5f7f2;
  --accent: #7ddf96;
  --accent-strong: #46c878;
  --warning: #f2b84b;
  --danger: #ff6b6b;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  background:
    radial-gradient(circle at 20% 0%, rgba(125, 223, 150, 0.18), transparent 28rem),
    linear-gradient(180deg, #101419 0%, #121820 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 480px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(32px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.app-view {
  display: grid;
  gap: 16px;
}

.topbar,
.section-title,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar h1,
.lock-screen h1,
.section-title h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1,
.lock-screen h1 {
  font-size: 28px;
  line-height: 1;
}

.eyebrow,
.metric-label {
  display: block;
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 20px;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}

.icon-button:active {
  background: var(--line);
}

.hero-panel,
.entry-panel,
.chart-panel,
.history-panel,
.stats-grid article,
.dialog-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(24, 30, 37, 0.88);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
}

.hero-panel {
  display: flex;
  align-items: end;
  justify-content: space-between;
  padding: 20px 22px;
}

#currentWeight {
  display: block;
  font-size: 48px;
  line-height: 0.95;
  letter-spacing: -0.02em;
}

.trend-pill {
  max-width: 42%;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(125, 223, 150, 0.14);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stats-grid article {
  padding: 14px;
}

.stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.stats-grid strong {
  font-size: 20px;
}

.entry-panel,
.chart-panel,
.history-panel {
  padding: 16px;
}

.section-title {
  margin-bottom: 14px;
}

.section-title h2 {
  font-size: 17px;
}

.section-title button,
.section-title select,
.dialog-actions button:not(.primary-button) {
  min-height: 38px;
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 14px;
  font-size: 14px;
  transition: background 0.15s;
}

.section-title button:active,
.section-title select:active,
.dialog-actions button:not(.primary-button):active {
  background: var(--line);
}

.entry-form,
.stack,
.dialog-card {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #11171d;
  color: var(--text);
  padding: 0 14px;
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(125, 223, 150, 0.14);
}

.weight-input {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #11171d;
}

.weight-input input {
  border: 0;
  background: transparent;
  font-size: 20px;
  min-height: 52px;
}

.weight-input span {
  padding-right: 14px;
  color: var(--muted);
  font-size: 16px;
}

.primary-button {
  min-height: 52px;
  border-radius: 10px;
  background: var(--accent);
  color: #07120b;
  font-weight: 900;
  font-size: 16px;
  transition: background 0.15s, transform 0.1s;
}

.primary-button:active {
  background: var(--accent-strong);
  transform: scale(0.98);
}

canvas {
  width: 100%;
  height: 240px;
  display: block;
  border-radius: 6px;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 40vh;
  max-height: 40dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.history-empty {
  color: var(--muted);
  margin: 4px 0 0;
  line-height: 1.4;
  font-size: 14px;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  background: #141a21;
}

.history-row time {
  color: var(--muted);
  font-size: 13px;
}

.history-row strong {
  font-size: 17px;
}

.delete-button {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
  font-size: 18px;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}

.delete-button:active {
  background: rgba(255, 107, 107, 0.24);
}

.lock-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  padding-bottom: env(safe-area-inset-bottom);
}

.lock-screen p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.form-error {
  min-height: 20px;
  margin: -2px 0 0;
  color: var(--danger);
  font-size: 14px;
  font-weight: 700;
}

.brand-mark {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #07120b;
  font-weight: 950;
  font-size: 28px;
}

dialog {
  width: min(calc(100vw - 32px), 460px);
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

.dialog-card {
  padding: 18px;
}

/* iPhone 13 Pro Max specific (428px logical width) */
@media (max-width: 430px) {
  .app-shell {
    padding-inline: 14px;
  }

  .hero-panel {
    padding: 18px 20px;
  }

  #currentWeight {
    font-size: 44px;
  }

  .trend-pill {
    max-width: 46%;
    font-size: 11px;
    padding: 7px 10px;
  }

  .stats-grid {
    gap: 8px;
  }

  .stats-grid article {
    padding: 12px 14px;
  }

  .topbar h1,
  .lock-screen h1 {
    font-size: 26px;
  }
}

@media (max-width: 360px) {
  #currentWeight {
    font-size: 38px;
  }

  .trend-pill {
    max-width: 48%;
    font-size: 10px;
  }

  .stats-grid strong {
    font-size: 18px;
  }

  .brand-mark {
    width: 56px;
    height: 56px;
    font-size: 24px;
  }
}
