/* ── Variables ── */
:root {
  --radius: 20px;
  --shadow: 0 4px 24px rgba(0,0,0,0.25);
}

body.dark {
  --bg:          #0d1117;
  --surface:     #161b22;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --sleep-bg:    #1a1f6e;
  --sleep-fg:    #818cf8;
  --wake-bg:     #3d2000;
  --wake-fg:     #fbbf24;
  --btn-text:    #fff;
}

body.light {
  --bg:          #f0f4f8;
  --surface:     #ffffff;
  --border:      #d0d7de;
  --text:        #1f2328;
  --text-muted:  #636c76;
  --sleep-bg:    #e0e7ff;
  --sleep-fg:    #4338ca;
  --wake-bg:     #fef3c7;
  --wake-fg:     #b45309;
  --btn-text:    #1f2328;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100dvh;
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

/* ── Login ── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1.5rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 360px;
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 1.75rem;
  color: var(--text);
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  padding: 0.7rem 0.9rem;
  transition: border-color 0.15s;
  width: 100%;
}

.field input:focus {
  outline: none;
  border-color: var(--sleep-fg);
}

.error-msg {
  background: rgba(248,113,113,0.12);
  border: 1px solid #f87171;
  border-radius: 8px;
  color: #f87171;
  font-size: 0.85rem;
  padding: 0.5rem 0.875rem;
}

#login-btn {
  background: var(--sleep-fg);
  border: none;
  border-radius: 12px;
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0.5rem;
  padding: 0.8rem;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
}

#login-btn:hover   { opacity: 0.88; }
#login-btn:active  { transform: scale(0.98); }
#login-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.3rem 0.5rem;
  transition: color 0.15s, border-color 0.15s;
}

#theme-toggle:hover { color: var(--text); border-color: var(--text-muted); }

#logout-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  transition: color 0.15s, border-color 0.15s;
}

#logout-btn:hover { color: var(--text); border-color: var(--text-muted); }

/* ── Main ── */
main {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.5rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Status Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem 1.5rem;
}

.status-card {
  text-align: center;
}

.status-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.last-time {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.duration {
  font-size: 2.5rem;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* ── Action Buttons ── */
.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.875rem;
}

.action-btn {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 2rem 1rem;
  transition: transform 0.12s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.action-btn:active { transform: scale(0.96); }

.btn-icon  { font-size: 2rem; line-height: 1; }
.btn-label { font-size: 0.95rem; font-weight: 700; }

.sleep-btn {
  background: var(--sleep-bg);
  color: var(--sleep-fg);
}

.wake-btn {
  background: var(--wake-bg);
  color: var(--wake-fg);
}

/* ── Picker Sheet ── */
.picker-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.picker-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  z-index: 101;
  padding-bottom: env(safe-area-inset-bottom);
  animation: slide-up 0.25s ease;
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.5rem;
}

.picker-header button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.25rem 0.5rem;
}

.picker-header button:first-child { color: var(--text-muted); }
.picker-header button:last-child  { color: var(--sleep-fg); font-weight: 600; }

.picker-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.picker-wheel-wrap {
  position: relative;
  height: 220px;
  overflow: hidden;
}

/* Gradient overlays that fade items toward the edges */
.picker-fade-top,
.picker-fade-bottom {
  position: absolute;
  left: 0;
  right: 0;
  height: 80px;
  pointer-events: none;
  z-index: 2;
}

.picker-fade-top {
  top: 0;
  background: linear-gradient(to bottom, var(--surface), transparent);
}

.picker-fade-bottom {
  bottom: 0;
  background: linear-gradient(to top, var(--surface), transparent);
}

/* Highlight bar behind the selected item */
.picker-selector {
  position: absolute;
  top: 50%;
  left: 1rem;
  right: 1rem;
  height: 44px;
  transform: translateY(-50%);
  background: var(--bg);
  border-radius: 10px;
  pointer-events: none;
  z-index: 1;
}

.picker-wheel {
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: calc(110px - 22px) 0; /* center first and last items */
}

.picker-wheel::-webkit-scrollbar { display: none; }

.picker-item {
  scroll-snap-align: center;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  color: var(--text-muted);
  transition: color 0.15s, font-weight 0.15s;
  position: relative;
  z-index: 3;
}

.picker-item.selected {
  color: var(--text);
  font-weight: 600;
}

/* ── Custom Time Dialog ── */
.custom-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  width: min(340px, calc(100vw - 2rem));
  z-index: 102;
  animation: fade-in 0.15s ease;
}

.custom-dialog-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
  text-align: center;
}

.custom-dialog input[type="datetime-local"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  padding: 0.7rem 0.9rem;
  width: 100%;
  color-scheme: dark;
}

.custom-dialog-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.custom-dialog-actions button {
  flex: 1;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.75rem;
  transition: opacity 0.15s;
}

.custom-dialog-actions button:first-child {
  background: var(--bg);
  color: var(--text-muted);
}

.custom-dialog-actions button:last-child {
  background: var(--sleep-fg);
  color: #fff;
}

.custom-dialog-actions button:hover { opacity: 0.85; }

/* ── Responsive ── */
@media (max-width: 360px) {
  .duration { font-size: 2rem; }
  .action-btn { padding: 1.5rem 0.75rem; }
}
