:root {
  color-scheme: dark;
  --bg-0: #070a10;
  --bg-1: #0d1320;
  --card: rgba(18, 24, 38, 0.72);
  --card-solid: #121826;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f6fb;
  --muted: #8b95a8;
  --faint: rgba(255, 255, 255, 0.06);
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.16);
  --warning: #f0b429;
  --warning-soft: rgba(240, 180, 41, 0.16);
  --critical: #ff5d5d;
  --critical-soft: rgba(255, 93, 93, 0.18);
  --ok: #3ecf8e;
  --shadow: rgba(0, 0, 0, 0.45);
  --drawer-width: min(400px, 92vw);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 12% 0%, rgba(91, 140, 255, 0.12), transparent 34%),
    radial-gradient(circle at 88% 100%, rgba(255, 93, 93, 0.08), transparent 30%),
    linear-gradient(160deg, var(--bg-1), var(--bg-0));
  overflow-x: hidden;
}

button,
input {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

.storage-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 10px 16px;
  text-align: center;
  color: #1a1200;
  font-size: 13px;
  font-weight: 600;
  background: linear-gradient(90deg, #f0b429, #ffd36a);
}

.app {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: clamp(20px, 3vw, 40px) clamp(18px, 3vw, 36px) clamp(32px, 4vw, 56px);
  display: flex;
  flex-direction: column;
  gap: clamp(28px, 4vw, 48px);
  min-height: 100dvh;
}

/* ── Top bar ─────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: clamp(16px, 2vw, 22px);
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 6px rgba(62, 207, 142, 0.16);
  animation: pulse 2.2s ease-out infinite;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  opacity: 0.55;
  transition: opacity 180ms ease, background 180ms ease, color 180ms ease, border-color 180ms ease;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  opacity: 1;
  color: var(--text);
  background: var(--faint);
  border-color: var(--line);
}

/* ── Clock ───────────────────────────────────────────── */

.clock-zone {
  text-align: center;
  padding-top: clamp(8px, 1.5vw, 18px);
}

.clock-time {
  display: block;
  font-size: clamp(56px, 11vw, 120px);
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.05em;
  line-height: 1;
}

.clock-date {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: clamp(15px, 2vw, 20px);
  font-weight: 500;
  letter-spacing: 0.04em;
}

/* ── Main countdown ──────────────────────────────────── */

.main-zone {
  flex: 1;
  display: grid;
  place-items: center;
  padding: clamp(12px, 2vw, 28px) 0;
}

.main-empty {
  text-align: center;
  padding: clamp(36px, 6vw, 64px);
  border: 1px dashed var(--line);
  border-radius: calc(var(--radius) + 8px);
  background: var(--faint);
}

.main-empty p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: clamp(16px, 2vw, 20px);
}

.main-countdown {
  width: min(100%, 920px);
  padding: clamp(28px, 4vw, 48px) clamp(24px, 4vw, 48px);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 10px);
  background: var(--card);
  box-shadow: 0 24px 80px var(--shadow);
  text-align: center;
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  transition: border-color 240ms ease, box-shadow 240ms ease;
}

.main-head {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 10px;
}

.main-name {
  margin: 0;
  font-size: clamp(22px, 3.4vw, 36px);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.urgency-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.main-digits {
  margin: 8px 0 18px;
  font-size: clamp(48px, 12vw, 128px);
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1.05;
}

.main-meta {
  margin: 0;
  color: var(--muted);
  font-size: clamp(14px, 1.8vw, 18px);
}

.urgency-warning {
  border-color: rgba(240, 180, 41, 0.35);
  box-shadow: 0 24px 80px var(--shadow), 0 0 0 1px rgba(240, 180, 41, 0.12);
}

.urgency-warning .urgency-badge {
  background: var(--warning-soft);
  color: var(--warning);
}

.urgency-warning .main-digits {
  color: var(--warning);
}

.urgency-critical {
  border-color: rgba(255, 93, 93, 0.4);
  box-shadow: 0 24px 80px var(--shadow), 0 0 40px rgba(255, 93, 93, 0.12);
  animation: breathe 1.8s ease-in-out infinite;
}

.urgency-critical .urgency-badge {
  background: var(--critical-soft);
  color: var(--critical);
}

.urgency-critical .main-digits {
  color: var(--critical);
}

/* ── Upcoming ────────────────────────────────────────── */

.upcoming-zone {
  padding-top: 4px;
}

.section-label {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.upcoming-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.upcoming-card {
  padding: 18px 18px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 24, 38, 0.55);
}

.upcoming-name {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 700;
}

.upcoming-remain {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.upcoming-abs {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.muted-hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ── Buttons ─────────────────────────────────────────── */

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 18px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  transition: filter 160ms ease, transform 160ms ease;
}

.primary-btn:hover {
  filter: brightness(1.08);
}

.primary-btn:active {
  transform: translateY(1px);
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.ghost-btn:hover {
  background: var(--faint);
  border-color: rgba(255, 255, 255, 0.18);
}

.ghost-btn.danger {
  color: var(--critical);
}

.ghost-btn.danger:hover {
  background: var(--critical-soft);
  border-color: rgba(255, 93, 93, 0.35);
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}

/* ── Drawer / overlay ────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(3, 6, 12, 0.55);
  opacity: 0;
  transition: opacity 240ms ease;
}

.overlay.open {
  opacity: 1;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  width: var(--drawer-width);
  height: 100%;
  height: 100dvh;
  border-left: 1px solid var(--line);
  background: var(--card-solid);
  box-shadow: -20px 0 60px var(--shadow);
  transform: translateX(100%);
  transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 18px 28px;
}

.drawer-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.drawer-section:last-child {
  border-bottom: none;
}

.drawer-section h3 {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.exam-form,
.setting-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.exam-form label,
.setting-row:not(.check) {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.exam-form input,
.setting-row input[type="text"],
.setting-row input[type="number"] {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
}

.exam-form input:focus,
.setting-row input:focus {
  border-color: rgba(91, 140, 255, 0.55);
}

.setting-row.check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--text);
  font-size: 14px;
}

.setting-row.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.form-error {
  margin: 0 0 8px;
  color: var(--critical);
  font-size: 13px;
}

.managed-list,
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.managed-row,
.history-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
}

.managed-info,
.history-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.managed-info strong,
.history-row strong {
  font-size: 14px;
}

.managed-info span,
.history-row span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.managed-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: none;
}

.managed-actions .ghost-btn {
  padding: 6px 10px;
  font-size: 12px;
}

.history-row {
  width: 100%;
}

/* ── Animations ──────────────────────────────────────── */

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(62, 207, 142, 0.28);
  }
  70%,
  100% {
    box-shadow: 0 0 0 10px transparent;
  }
}

@keyframes breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.012);
  }
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 720px) {
  .app {
    gap: 24px;
    padding-bottom: 40px;
  }

  .main-digits {
    font-size: clamp(40px, 14vw, 72px);
  }

  .upcoming-list {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
