:root {
  --wheel-item-height: 44px;
  color-scheme: light;
  --primary: #1976d2;
  --bg: #f2f4f8;
  --card-bg: #fff;
  --text: #333;
  --text-light: #666;
  --danger: #d32f2f;
  --success: #2e7d32;
  --border: #ddd;
  --input-bg: #f9f9f9;
  --highlight-bg: #f0f2f5;
}

[data-theme="dark"] {
  color-scheme: dark;
  --primary: #64b5f6;
  --on-primary: #102030;
  --bg: #121212;
  --card-bg: #1e1e1e;
  --text: #e0e0e0;
  --text-light: #9e9e9e;
  --danger: #ef5350;
  --success: #66bb6a;
  --border: #333;
  --input-bg: #2a2a2a;
  --highlight-bg: #2d2d2d;
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 12px;
  overscroll-behavior-y: contain;
  transition: background-color 0.3s, color 0.3s;
}

.container {
  max-width: 500px;
  margin: 0 auto;
  padding-bottom: 40px;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.date-display {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-light);
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  border-radius: 8px;
}

.icon-btn:active {
  background: var(--border);
}

.card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  margin-bottom: 12px;
}

.hero-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hero-weight {
  flex: 1;
}

.hero-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.hero-value .unit {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-light);
  margin-left: 4px;
}

.hero-updated {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 2px;
}

.add-weight-btn {
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--primary);
  color: var(--on-primary, white);
  border: none;
  border-radius: 12px;
  white-space: nowrap;
}

.add-weight-btn:active {
  opacity: 0.9;
  transform: scale(0.98);
}

.range-filters {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 12px;
}

.range-btn {
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card-bg);
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: 500;
}

.range-btn.active {
  background: var(--primary);
  color: var(--on-primary, white);
  border-color: var(--primary);
}

.chart-box {
  height: clamp(180px, 32dvh, 260px);
  width: 100%;
}

.target-info {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.target-info:empty {
  display: none;
}

.stats-box {
  display: flex;
  justify-content: space-around;
  text-align: center;
  padding: 8px 0;
  gap: 8px;
}

.stat-item {
  flex: 1;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-bottom: 2px;
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
}

.stat-value.positive {
  color: var(--danger);
}

.stat-value.negative {
  color: var(--success);
}

.stat-value.neutral {
  color: var(--text-light);
}

.stat-value.bmi-under {
  color: var(--primary);
}

.stat-value.bmi-normal {
  color: var(--success);
}

.stat-value.bmi-over {
  color: #9a5700;
}

[data-theme="dark"] .stat-value.bmi-over { color: #ffa726; }

.stat-value.bmi-obese {
  color: var(--danger);
}

.history-header {
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
}

.history-list {
  max-height: min(240px, 35dvh);
  overflow-y: auto;
}

.entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.entry:last-child {
  border-bottom: none;
}

.entry-date {
  font-size: 0.9rem;
  color: var(--text-light);
}

.entry-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.entry-weight {
  font-weight: 700;
  font-size: 0.95rem;
}

.delete-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.2rem;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
}

.no-entries {
  color: var(--text-light);
  font-size: 0.9rem;
  padding: 10px 0;
}

.backup-controls {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.text-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.85rem;
  text-decoration: underline;
  min-height: 44px;
  padding: 6px;
}

.modal {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 320px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.modal h2 {
  margin: 0 0 16px 0;
  font-size: 1rem;
}

.modal-field {
  margin-bottom: 14px;
}

.modal-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-light);
  margin-bottom: 4px;
}

.modal-field input {
  width: 100%;
  padding: 10px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
}

.modal-field input::-webkit-outer-spin-button,
.modal-field input::-webkit-inner-spin-button {
  display: none;
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.modal-btn {
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.modal-btn.cancel {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
}

.modal-btn.save {
  background: var(--primary);
  border: none;
  color: var(--on-primary, white);
  font-weight: 600;
}

.helper-text {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 6px;
}

.auto-fill-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.75rem;
  text-decoration: underline;
  padding: 0;
  margin-top: 4px;
}

.picker-card {
  background: var(--card-bg);
  width: 100%;
  max-width: 400px;
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.picker-display {
  text-align: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.picker-display input {
  font-size: 2.5rem;
  font-weight: bold;
  width: 140px;
  text-align: center;
  border: none;
  color: var(--primary);
  background: transparent;
}

.picker-display input::-webkit-outer-spin-button,
.picker-display input::-webkit-inner-spin-button {
  display: none;
}

.picker-display input:focus {
  outline: none;
  border-bottom: 2px solid var(--primary);
}

.picker-display .unit {
  font-size: 1.2rem;
  color: var(--text-light);
  font-weight: 600;
}

.wheel-wrapper {
  display: flex;
  justify-content: center;
  gap: 12px;
  height: 180px;
  position: relative;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 5%, rgba(0, 0, 0, 0.4) 20%, black 35%, black 65%, rgba(0, 0, 0, 0.4) 80%, transparent 95%);
  mask-image: linear-gradient(to bottom, transparent 5%, rgba(0, 0, 0, 0.4) 20%, black 35%, black 65%, rgba(0, 0, 0, 0.4) 80%, transparent 95%);
}

.highlight-bar {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 176px;
  height: 48px;
  background: transparent;
  border-top: 2px solid var(--primary);
  border-bottom: 2px solid var(--primary);
  opacity: 0.5;
  border-radius: 0;
  z-index: 2;
  pointer-events: none;
}

.wheel-col {
  width: 80px;
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  text-align: center;
  flex-shrink: 0;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  user-select: none;
  overscroll-behavior: contain;
  background: var(--input-bg);
  border-radius: 12px;
  position: relative;
  z-index: 1;
}

.wheel-col::-webkit-scrollbar {
  display: none;
}

.wheel-item {
  height: var(--wheel-item-height);
  line-height: var(--wheel-item-height);
  font-size: 1.3rem;
  color: var(--text-light);
  scroll-snap-align: center;
  transition: color 0.15s, font-weight 0.15s;
}

.wheel-item.selected {
  color: var(--primary);
  font-size: 1.4rem;
  font-weight: 700;
}

.wheel-pad {
  height: calc((180px - var(--wheel-item-height)) / 2);
}

.picker-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.picker-actions button {
  flex: 1;
  padding: 14px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
}

.picker-actions .btn-save {
  background: var(--primary);
  color: var(--on-primary, white);
}

.picker-actions .btn-cancel {
  background: var(--highlight-bg);
  color: var(--text);
}

.picker-actions button:active {
  opacity: 0.9;
  transform: scale(0.98);
}

[hidden] { display: none !important; }
button, input { font-family: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
body:has(dialog[open]) { overflow: hidden; }
dialog {
  width: min(92vw, 400px);
  max-height: calc(100dvh - 24px);
  border: 0;
  padding: 0;
  border-radius: 20px;
  background: var(--card-bg);
  color: var(--text);
  overflow: auto;
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
#settingsModal { max-width: 340px; }
.modal { max-width: none; box-shadow: none; }
.picker-card { box-shadow: none; }
.picker-card h2 { margin: 0 0 12px; font-size: 1rem; }
.picker-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0 12px; margin-bottom: 8px; }
.picker-header h2 { margin: 0; }
.picker-date {
  min-height: 44px; padding: 0; border: 0; background: none;
  font-size: .8rem; color: var(--text-light); white-space: nowrap;
  text-decoration: underline; text-underline-offset: 3px;
}
.picker-date:disabled { opacity: 1; text-decoration: none; }
.entry-edit {
  flex: 1; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 44px; padding: 0 8px 0 0;
  border: 0; background: none; color: var(--text); text-align: left;
}
.entry { padding: 2px 0; }
.stat-detail { font-size: .75rem; color: var(--text-light); margin-top: 4px; }
.message, .error { font-size: .875rem; line-height: 1.4; white-space: pre-line; }
.error { color: var(--danger); }
#notice { margin: 0 0 12px; }
#chartMessage { padding: 16px; text-align: center; color: var(--text-light); }
.chart-dates { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: .75rem; color: var(--text-light); }
#updateBtn { display: block; margin: 0 auto 8px; }
.wheel-col { scrollbar-width: none; }
.wheel-col[aria-disabled="true"] { opacity: .35; pointer-events: none; }
#importDetails { max-height: 180px; overflow: auto; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (max-width: 350px) {
  .hero-card { flex-wrap: wrap; }
  .range-filters { gap: 4px; }
  .range-btn { padding-inline: 10px; }
}
