:root {
  --bg: #0e1116;
  --surface: #171b22;
  --surface-2: #1f2530;
  --border: #2a313d;
  --text: #e8ecf2;
  --muted: #8b95a5;
  --accent: #4f8cff;
  --accent-text: #ffffff;
  --go: #22c55e;
  --stop: #ef4444;
  --night: #a78bfa;
  --day: #f5b83d;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dde2ea;
  --text: #121722;
  --muted: #5f6b7c;
  --accent: #2f6fec;
  --go: #16a34a;
  --stop: #dc2626;
  --night: #7c5ce0;
  --day: #d48c06;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 18px rgba(16, 24, 40, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

[hidden] { display: none !important; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 28px);
}

h1, h2 { margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }

/* --- top bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 14px;
}
.topbar h1 { font-size: 28px; font-weight: 750; }
.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }

/* --- cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.progress { display: grid; gap: 14px; }
.meter-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.meter-head span { color: var(--muted); }
.meter-head strong { font-variant-numeric: tabular-nums; font-weight: 650; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.fill { height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width 0.5s ease; }
.fill.night { background: var(--night); }

/* --- timer --- */
.timer-card { text-align: center; padding: 22px 18px 18px; }
.timer-status { color: var(--muted); font-size: 14px; font-weight: 550; }
.timer-card.running .timer-status { color: var(--go); }
.timer-card.running .timer-status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--go);
  margin-right: 8px;
  vertical-align: 1px;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

.timer {
  font-size: clamp(52px, 17vw, 76px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  margin: 4px 0 16px;
  line-height: 1.1;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 14px;
  margin-bottom: 14px;
}
.segmented.three { grid-template-columns: 1fr 1fr 1fr; }
.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 10px 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}
.segmented button svg { width: 18px; height: 18px; }
.segmented button[aria-checked="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.segmented button[data-night="0"][aria-checked="true"] svg { color: var(--day); }
.segmented button[data-night="1"][aria-checked="true"] svg { color: var(--night); }

.active-notes { display: grid; grid-template-columns: 1fr 96px; gap: 8px; margin-bottom: 14px; }

/* --- buttons & inputs --- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 650;
  border-radius: 14px;
  padding: 11px 16px;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  text-decoration: none;
  text-align: center;
  display: inline-block;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.outline { background: transparent; border-color: var(--border); }
.btn.danger { color: var(--stop); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.wide { display: block; width: 100%; margin-top: 18px; }
.btn.big { width: 100%; font-size: 19px; padding: 17px; border-radius: 16px; color: #fff; }
.btn.start { background: var(--go); }
.btn.stop { background: var(--stop); }
.btn:disabled { opacity: 0.6; }

input {
  width: 100%;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
  min-height: 46px;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: var(--muted); }

/* --- drive list --- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 22px 2px 10px; }
.section-head h2 { font-size: 19px; }
.count { color: var(--muted); font-weight: 500; font-size: 15px; }

.drive-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.drive {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  cursor: pointer;
}
.drive .badge {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--day) 16%, transparent);
  color: var(--day);
}
.drive.night .badge { background: color-mix(in srgb, var(--night) 18%, transparent); color: var(--night); }
.drive .badge svg { width: 19px; height: 19px; }
.drive .when { font-weight: 600; }
.drive .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drive .info { min-width: 0; }
.drive .dur { font-weight: 700; font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 18px 0; }

/* --- dialogs (bottom sheets on mobile) --- */
dialog.sheet {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 20px 18px calc(env(safe-area-inset-bottom) + 18px);
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  border-radius: 22px 22px 0 0;
  max-height: 92dvh;
}
@media (min-width: 600px) {
  dialog.sheet { margin: auto; border-radius: 22px; }
}
dialog.sheet[open] { animation: rise 0.22s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(2px); }
dialog h2 { font-size: 20px; margin-bottom: 14px; }
dialog form { display: grid; gap: 12px; }
dialog label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 550; min-width: 0; }
dialog .segmented { margin-bottom: 0; }
.field-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; margin-top: 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.spacer { flex: 1; }
.hint { margin: 0; font-size: 14px; }
.error { color: var(--stop); margin: 0; font-size: 14px; min-height: 0; }
.error:empty { display: none; }

/* --- login --- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card h1 { font-size: 26px; margin-top: 14px; }
.login-card p { margin: 6px 0 20px; }
.login-card form { display: grid; gap: 10px; }
.login-card input { text-align: center; font-size: 22px; letter-spacing: 0.3em; }
.logo {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(140deg, #4f8cff, #7c5ce0);
}
.logo svg { width: 36px; height: 36px; }

/* --- toast --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
