:root {
  --ink: #f4f1ea;
  --ink-dim: rgba(244, 241, 234, 0.72);
  --glass: rgba(9, 18, 38, 0.58);
  --glass-border: rgba(255, 255, 255, 0.16);
  --safety: #ffb81c;
  --safety-dark: #e09a00;
  --ok: #3ddc84;
  --bad: #ff5a5a;
  --ui-font: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b1d3f;
  color: var(--ink);
  font-family: var(--ui-font);
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.topbar__left { display: flex; flex-direction: column; gap: 10px; }
.topbar__left > * { pointer-events: auto; }

.hud {
  min-width: 168px;
  padding: 10px 14px 12px;
  border-radius: 12px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.hud__row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.hud__label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.hud__pct { font-size: 20px; font-variant-numeric: tabular-nums; }
.hud__bar {
  margin-top: 8px;
  height: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.hud__bar span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: repeating-linear-gradient(-45deg, var(--safety) 0 8px, var(--safety-dark) 8px 16px);
  transition: width 0.45s cubic-bezier(.2, .8, .2, 1);
}
.hud.is-complete .hud__bar span { background: var(--ok); }
.hud.is-complete .hud__pct { color: var(--ok); }

/* ---------- Clock + weather ---------- */
.clock {
  min-width: 168px;
  padding: 10px 14px 11px;
  border-radius: 12px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.clock__time {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.clock__date { font-size: 12px; color: var(--ink-dim); margin-top: 2px; }
.clock__wx {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-dim);
  min-height: 20px;
}
.clock__wx strong { color: var(--ink); font-size: 15px; font-variant-numeric: tabular-nums; }
.clock__icon { display: inline-flex; width: 20px; height: 20px; }
.clock__icon:empty { display: none; }
.wx-picker {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--glass-border);
}
.wx-picker button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  min-width: 28px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.wx-picker button:hover { background: rgba(255, 255, 255, 0.14); }
.wx-picker button[aria-pressed="true"] {
  background: rgba(255, 184, 28, 0.2);
  border-color: var(--safety);
}
.wx-picker button:focus-visible { outline: 2px solid #9cc7ff; outline-offset: 1px; }

.clock__place {
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  font: 700 14px/1 var(--ui-font);
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.12s ease, background-color 0.2s ease, box-shadow 0.2s ease;
  white-space: nowrap;
}
.btn[hidden] { display: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid #9cc7ff; outline-offset: 2px; }
.btn--primary {
  background: var(--safety);
  color: #1b1405;
  box-shadow: 0 6px 20px rgba(255, 184, 28, 0.28), inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}
.btn--primary:hover { background: #ffc640; }
.btn--ghost {
  background: var(--glass);
  color: var(--ink);
  border-color: var(--glass-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.btn--ghost:hover { background: rgba(20, 34, 64, 0.75); }

/* ---------- Tagline under the sketch ---------- */
.tagline {
  position: fixed;
  left: 50%;
  top: var(--tagline-top, 60%);
  transform: translate(-50%, 8px);
  width: max-content;
  max-width: calc(100vw - 32px);
  margin: 0;
  padding: 8px 16px;
  border-radius: 99px;
  background: rgba(9, 18, 38, 0.6);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  text-align: center;
  font-size: clamp(13px, 1.4vw, 16px);
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.8s ease, transform 0.8s ease;
  pointer-events: none;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.6);
}
.tagline.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Controls hint ---------- */
.controls {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 13px;
  color: var(--ink-dim);
  width: max-content;
  max-width: calc(100vw - 32px);
}
.controls[hidden] { display: none; }
.controls span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
kbd {
  display: inline-block;
  min-width: 24px;
  padding: 3px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-bottom-width: 2px;
  font: 600 12px/1.2 var(--ui-font);
  color: var(--ink);
  text-align: center;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translate(-50%, 10px);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(9, 18, 38, 0.85);
  border: 1px solid var(--glass-border);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast[data-tone="bad"] { border-color: rgba(255, 90, 90, 0.6); }
.toast[data-tone="ok"] { border-color: rgba(61, 220, 132, 0.6); }

/* ---------- Touch pad ---------- */
.pad {
  position: fixed;
  left: 0; right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 12px;
  pointer-events: none;
}
.pad[hidden] { display: none; }
.pad button {
  pointer-events: auto;
  width: 56px; height: 56px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--ink);
  font: 700 18px/1 var(--ui-font);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pad button.is-down { background: rgba(255, 184, 28, 0.35); }
.pad__group { display: flex; gap: 8px; }
.pad__group--v { flex-direction: column; }
.pad .pad__grab { width: 84px; background: var(--safety); color: #1b1405; border: 0; font-size: 15px; }
body.has-pad .controls { display: none; }
body.has-pad .toast { bottom: auto; top: 176px; }

/* ---------- Completion dialog ---------- */
.done {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 10, 24, 0.35);
  animation: fade 0.4s ease both;
}
.done[hidden] { display: none; }
.done__card {
  width: min(500px, 100%);
  padding: 28px 24px 24px;
  border-radius: 18px;
  background: rgba(9, 18, 38, 0.88);
  border: 1px solid rgba(61, 220, 132, 0.45);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: rise 0.5s cubic-bezier(.2, .8, .2, 1) both;
}
.done__kicker {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ok);
  font-weight: 700;
}
.done h2 { margin: 8px 0 8px; font-size: 26px; }
.done p { margin: 0; color: var(--ink-dim); }
.done__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(0.98); } }

@media (max-width: 640px) {
  .topbar { gap: 8px; }
  .hud { min-width: 0; width: 128px; padding: 8px 10px 10px; }
  .clock { min-width: 0; width: 128px; padding: 8px 10px 9px; }
  .clock__time { font-size: 18px; }
  .clock__wx { flex-wrap: wrap; gap: 2px 5px; font-size: 12px; }
  .wx-picker { gap: 3px; }
  .wx-picker button { min-width: 0; height: 28px; }
  .wx-picker svg { width: 16px; height: 16px; }
  .topbar__left { gap: 8px; }
  .hud__pct { font-size: 16px; }
  .actions { flex-direction: column; align-items: stretch; gap: 8px; }
  .btn { min-height: 40px; padding: 0 12px; font-size: 13px; }
  .controls__extra { display: none !important; }
}

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