:root {
  --brand: #0067a5;
  --brand-2: #00a3a3;
  --brand-dark: #004a78;
  --bg: #eef6fb;
  --surface: #ffffff;
  --text: #0d2b3e;
  --muted: #5a7a8c;
  --border: #cfe2ee;
  --danger: #e23b3b;
  --display: #0067a5;
  --shadow: 0 8px 30px rgba(0, 80, 130, 0.12);
}

body.dark {
  --bg: #06141d;
  --surface: #0d2230;
  --text: #e8f4fb;
  --muted: #8fb0c2;
  --border: #16384c;
  --display: #34d6d6;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 44px; width: auto; border-radius: 8px; background: #fff; padding: 2px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 700; font-size: 18px; }
.brand-sub { font-size: 12px; opacity: 0.9; }

.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: #fff;
  font-size: 20px;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.32); }

/* Stage */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 24px 16px;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
}

.label-input {
  width: 100%;
  max-width: 520px;
  text-align: center;
  font-size: 20px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
.label-input:focus { outline: 2px solid var(--brand-2); }

.display {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: clamp(64px, 18vw, 220px);
  letter-spacing: 2px;
  color: var(--display);
  line-height: 1;
  text-align: center;
  user-select: none;
}
.display.warning { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

.phase-label {
  font-size: 22px;
  font-weight: 700;
  color: var(--brand);
  min-height: 26px;
  text-align: center;
}
.phase-label.transition { color: var(--brand-2); }

.setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
}

.field-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.group-title { font-size: 14px; font-weight: 600; color: var(--muted); }
.group-title small { font-weight: 400; opacity: 0.8; }

.repeat-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.repeat-toggle input { width: 20px; height: 20px; accent-color: var(--brand); cursor: pointer; }

.flash-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  text-align: center;
  font-size: clamp(22px, 4vw, 40px);
  font-weight: 800;
  color: #fff;
  background: var(--danger);
  padding: 18px 12px;
  box-shadow: var(--shadow);
  animation: flashpulse 0.6s infinite;
}
.flash-banner[hidden] { display: none; }
@keyframes flashpulse { 50% { background: #b81f1f; } }

.time-fields { display: flex; gap: 14px; }
.time-fields label {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  gap: 6px;
}
.time-fields input {
  width: 92px;
  font-size: 32px;
  text-align: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
.time-fields input:focus { outline: 2px solid var(--brand-2); }

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  max-width: 640px;
}
.presets-title { width: 100%; text-align: center; font-size: 13px; color: var(--muted); }
.presets button {
  min-width: 52px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--brand);
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.presets button:hover { background: var(--brand); color: #fff; }

.controls { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.btn {
  padding: 14px 28px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; }

/* Alarm overlay */
.alarm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 30, 50, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.alarm-overlay[hidden] { display: none; }
.alarm-box {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: pop 0.25s ease;
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.alarm-icon { font-size: 64px; animation: shake 0.6s infinite; }
@keyframes shake { 0%,100%{transform:rotate(-12deg);} 50%{transform:rotate(12deg);} }
.alarm-title { font-size: 40px; font-weight: 800; color: var(--danger); margin: 8px 0; }
.alarm-sub { font-size: 22px; color: var(--text); margin-bottom: 22px; min-height: 26px; }

/* Footer */
.footer { text-align: center; padding: 12px; font-size: 13px; color: var(--muted); }

/* Running state hides setup */
body.running .setup { display: none; }

@media (max-width: 480px) {
  .time-fields input { width: 72px; font-size: 26px; }
  .btn { padding: 12px 20px; font-size: 16px; }
}
