:root {
  --bg: #14110a;
  --bg-elevated: #201a0c;
  --card: #241d0f;
  --card-border: #3a2f16;
  --text: #fdf6e3;
  --text-dim: #a89b78;
  --accent: #ffc93d;
  --accent-dim: #6b5106;
  --accent-glow: #ffe066;
  --green: #35d07f;
  --warn: #ffb443;
  --danger: #ff4757;
  --font-display: "Share Tech Mono", "Courier New", monospace;
  --font-body: "Work Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ---------- MAIN SCREEN ---------- */

.topbar {
  position: relative;
  padding: 48px 24px 20px;
  text-align: center;
  flex-shrink: 0;
}

.settings-gear {
  position: absolute;
  top: max(44px, env(safe-area-inset-top));
  right: 20px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  padding: 8px;
  line-height: 1;
}

.clock {
  font-family: var(--font-display);
  font-size: 60px;
  font-weight: 400;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}
.clock .ampm, .ringing-time .ampm {
  font-size: 0.32em;
  font-weight: 400;
  margin-left: 6px;
  color: var(--text-dim);
  vertical-align: middle;
}

.app-intro {
  flex-shrink: 0;
  padding: 0 24px 16px;
  text-align: center;
}
.app-intro-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 1px;
  color: var(--accent);
  margin: 0 0 6px;
}
.app-intro-desc {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
  margin: 0;
}

.date {
  font-size: 16px;
  color: var(--text-dim);
  margin-top: 4px;
}

.install-banner {
  margin: 0 20px 10px;
  padding: 12px 14px 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent-dim);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.install-btn {
  background: var(--accent);
  color: #201a0c;
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.streak-banner {
  margin: 0 20px 10px;
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.next-alarm-banner {
  margin: 0 20px 12px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  text-align: center;
  font-size: 14px;
  color: var(--accent-glow);
  flex-shrink: 0;
}

.alarm-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 100px;
}

.empty-state {
  text-align: center;
  margin-top: 60px;
  color: var(--text-dim);
}
.empty-emoji { font-size: 56px; margin-bottom: 12px; }
.empty-state p { line-height: 1.5; font-size: 16px; }

.alarm-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.alarm-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 18px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.alarm-card.disabled { opacity: 0.45; }

.alarm-card-main { flex: 1; min-width: 0; }

.alarm-card-time {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.alarm-card-meta {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* iOS-style switch */
.switch {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #3a3f4d;
  transition: 0.2s;
  border-radius: 34px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 27px;
  width: 27px;
  left: 2px;
  top: 2px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}
.switch input:checked + .slider {
  background-color: var(--green);
}
.switch input:checked + .slider:before {
  transform: translateX(20px);
}

.fab {
  position: fixed;
  right: 24px;
  bottom: 36px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--accent);
  color: #201a0c;
  font-size: 32px;
  border: none;
  box-shadow: 0 6px 20px rgba(255, 201, 61, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.fab:active { transform: scale(0.93); }

/* ---------- EDIT SCREEN ---------- */

.edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px;
  padding-top: max(20px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--card-border);
  flex-shrink: 0;
}
.edit-header h2 { margin: 0; font-size: 17px; }

.text-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  padding: 6px 8px;
}
.text-btn.save { color: var(--accent); font-weight: 600; }
.text-btn.small { color: var(--accent-glow); font-size: 14px; margin-top: 8px; align-self: flex-start; }

.edit-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.time-picker-wrap {
  display: flex;
  justify-content: center;
  padding: 20px 0;
}
.time-input {
  font-family: var(--font-display);
  font-size: 44px;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: 16px;
  padding: 12px 20px;
  font-variant-numeric: tabular-nums;
  color-scheme: dark;
}

.field-group { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 14px; color: var(--text-dim); }

.day-toggles { display: flex; gap: 6px; justify-content: space-between; }
.day-btn {
  flex: 1;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.day-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.text-input, .select-input {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: 12px;
  padding: 14px 14px;
  font-size: 16px;
  width: 100%;
  color-scheme: dark;
}

.small-select { width: auto; }

.toggle-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.toggle-row .field-label { flex: 1; }

.danger-btn {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  margin-top: 10px;
}

.stakes-hint {
  margin: -14px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

.stakes-settings { gap: 10px; }
.stakes-status { display: flex; flex-direction: column; gap: 10px; }
.stakes-desc {
  margin: 0;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.4;
}
#stakes-subscribed .stakes-desc { color: var(--green); }

.primary-btn {
  background: var(--accent);
  color: #201a0c;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
}
.primary-btn:active { transform: scale(0.98); }

/* Locked (subscriber-only) <option>s inside stakes-amount-select and
   dismiss-mode-select are greyed out by the browser's native disabled-option
   styling — no custom CSS needed there. */

/* ---------- RINGING SCREEN ---------- */

.ringing-screen {
  background: #2b1c02;
  z-index: 50;
}

.ringing-flash {
  position: absolute;
  inset: 0;
  background: var(--accent);
  animation: flash 0.6s infinite alternate;
  opacity: 0.25;
}
@keyframes flash {
  from { opacity: 0.08; }
  to { opacity: 0.4; }
}

.ringing-content {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
  gap: 10px;
}

.ringing-time {
  font-family: var(--font-display);
  font-size: 68px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
.ringing-label {
  font-size: 22px;
  color: #ffe9b0;
  margin-bottom: 30px;
}

.stakes-badge {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--accent-dim);
  color: var(--accent-glow);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  margin-top: -20px;
  margin-bottom: 10px;
}

.dismiss-panel {
  display: flex;
  gap: 16px;
  width: 100%;
  max-width: 420px;
}

.snooze-btn, .dismiss-btn {
  flex: 1;
  padding: 22px 10px;
  border-radius: 18px;
  font-size: 18px;
  font-weight: 700;
  border: none;
}
.snooze-btn {
  background: rgba(255,255,255,0.12);
  color: white;
}
.dismiss-btn {
  background: white;
  color: #2b1c02;
}

/* Reflex game overlay */
.reflex-game {
  position: relative;
  z-index: 3;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 14px;
}
.reflex-header {
  text-align: center;
  flex-shrink: 0;
}
.reflex-title {
  font-size: 18px;
  color: #ffe9b0;
  font-weight: 600;
}
.reflex-streak {
  font-size: 44px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
}
.reflex-feedback {
  font-size: 15px;
  color: var(--warn);
  min-height: 20px;
  margin-top: 4px;
}
.reflex-zone {
  position: relative;
  flex: 1;
  background: rgba(0,0,0,0.25);
  border-radius: 24px;
  overflow: hidden;
}
.reflex-target {
  position: absolute;
  border-radius: 50%;
  background: white;
  border: none;
  box-shadow: 0 0 24px rgba(255, 224, 102, 0.8);
}
.reflex-target:active {
  background: var(--accent);
}

/* Balance Challenge overlay */
.balance-game {
  position: relative;
  z-index: 3;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 14px;
}
.balance-header { text-align: center; flex-shrink: 0; }
.balance-title {
  font-size: 18px;
  color: #ffe9b0;
  font-weight: 600;
}
.balance-feedback {
  font-size: 15px;
  color: var(--warn);
  min-height: 20px;
  margin-top: 6px;
}
.balance-progress-track {
  margin-top: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(0,0,0,0.3);
  overflow: hidden;
}
.balance-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s linear;
}
.balance-camera-wrap {
  position: relative;
  flex: 1;
  border-radius: 24px;
  overflow: hidden;
  background: rgba(0,0,0,0.25);
}
.balance-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* translateZ(0) forces this onto its own GPU layer — works around a WebKit
     bug where camera srcObject video never composites to screen inside an
     iOS standalone (home-screen) web app without it. */
  transform: scaleX(-1) translateZ(0); /* mirror, like a selfie camera */
}
.yt-audio-frame {
  position: fixed;
  width: 1px;
  height: 1px;
  bottom: 0;
  left: 0;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}
#youtube-connected,
#spotify-connected,
#apple-connected {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  padding: 12px 20px;
  border-radius: 14px;
  font-size: 14px;
  z-index: 100;
  max-width: 90%;
  text-align: center;
}

.owner-stats-tab {
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  color: var(--text-dim);
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  z-index: 200;
  opacity: 0.85;
}
.owner-stats-tab:active { opacity: 1; }
