:root {
  --bg: #0b0d12;
  --surface: #141821;
  --surface-2: #1c2130;
  --line: #262c3c;
  --text: #e9ecf3;
  --muted: #8d95a8;
  --accent: #7ee0b5;
  --accent-ink: #062418;
  --accent-soft: rgba(126, 224, 181, 0.14);
  --danger: #ff7a7a;
  --danger-soft: rgba(255, 122, 122, 0.12);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #eef0f5;
    --line: #e1e4ec;
    --text: #12151d;
    --muted: #697186;
    --accent: #10a56b;
    --accent-ink: #ffffff;
    --accent-soft: rgba(16, 165, 107, 0.12);
    --danger: #d93a3a;
    --danger-soft: rgba(217, 58, 58, 0.1);
    --shadow: 0 10px 40px rgba(20, 25, 40, 0.14);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
svg path[fill="none"], svg circle[fill="none"] { fill: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer; transition: transform .12s ease, background .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn.danger-ghost { background: transparent; border-color: transparent; color: var(--danger); margin-right: auto; padding: 0 8px; }
.btn.ghost { background: transparent; }
.btn.small { height: 34px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.btn.wide { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 12px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn.small { width: 34px; height: 34px; border-radius: 10px; }
.icon-btn.small svg { width: 18px; height: 18px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input {
  width: 100%; height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="datetime-local"] { -webkit-appearance: none; appearance: none; min-width: 0; display: block; line-height: 48px; }

/* ---------- boot + lock ---------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.lock { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.lock-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.lock h1 { font-size: 26px; letter-spacing: -0.02em; margin-bottom: 12px; }
.logo { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.logo svg { width: 34px; height: 34px; }
.login-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.or { width: 100%; display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.error { color: var(--danger); font-size: 14px; min-height: 20px; text-align: center; }

/* ---------- app shell ---------- */
#app { max-width: 1100px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 20px; }
.top h1 { font-size: 30px; letter-spacing: -0.03em; }
.top-actions { display: flex; align-items: center; gap: 4px; }

.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 6px 10px 16px; margin-bottom: 16px;
  border-radius: 14px; background: var(--accent-soft); color: var(--text); font-size: 14px;
}
.banner span { flex: 1; min-width: 0; }
.banner .btn { white-space: nowrap; }

.list { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }

.card {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 18px 14px;
  animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -4px -6px 4px 0; }
.card .name { font-size: 16px; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; }
.counter {
  font-size: clamp(30px, 8.5vw, 40px); font-weight: 700; letter-spacing: -0.03em; line-height: 1.1;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.counter .u { font-size: .5em; font-weight: 600; color: var(--muted); margin: 0 .35em 0 .06em; letter-spacing: 0; }
.counter .u:last-child { margin-right: 0; }
.seconds { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 4px; }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); margin: 16px 0 8px; overflow: hidden; }
.bar { height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .6s ease; }
.next { font-size: 13px; color: var(--muted); }
.next b { color: var(--text); font-weight: 600; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.stats { font-size: 13px; color: var(--muted); }
.stats .best-now { color: var(--accent); font-weight: 600; }
.reset:hover { border-color: var(--danger); color: var(--danger); }
.card.flash { animation: flash .7s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 var(--accent-soft); } 30% { box-shadow: 0 0 0 6px var(--accent-soft); } 100% { box-shadow: 0 0 0 0 transparent; } }

.empty { text-align: center; max-width: 360px; margin: 12vh auto 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty-title { font-size: 20px; font-weight: 700; color: var(--text); }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); z-index: 10; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; z-index: 11; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 100%; max-width: 460px; max-height: 90dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 22px 22px 0 0; box-shadow: var(--shadow);
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
  animation: up .28s cubic-bezier(.2, .9, .3, 1);
}
@keyframes up { from { transform: translate(-50%, 100%); } }
@media (min-width: 640px) {
  .sheet { bottom: auto; top: 50%; transform: translate(-50%, -50%); border-radius: 22px; border-bottom: 1px solid var(--line); animation: pop .22s ease; }
  @keyframes pop { from { opacity: 0; transform: translate(-50%, -46%); } }
}
.sheet h2 { font-size: 20px; letter-spacing: -0.02em; }
.sheet label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.hint { font-weight: 400; font-size: 12px; }
.muted { color: var(--muted); font-size: 15px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.sheet .error { text-align: left; min-height: 0; }
.menu-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.menu-item { text-align: left; padding: 15px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); font: inherit; cursor: pointer; }
.menu-item:last-child { border-bottom: 0; }
.menu-item:hover { background: var(--surface-2); }
.danger-text { color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span { font-size: 13px; padding: 5px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
