/* ============================================================
   CSS RESET + DESIGN SYSTEM
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #111114;
  --surface: rgba(255,255,255,0.02);
  --border: rgba(255,255,255,0.06);
  --border-strong: rgba(255,255,255,0.12);
  --text-primary: #e4e4e8;
  --text-secondary: rgba(255,255,255,0.6);
  --text-muted: rgba(255,255,255,0.55);
  --error: rgba(220,50,50,0.8);
  --error-bg: rgba(220,50,50,0.1);
  --font-sans: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

html { height: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

input, button, select { font-family: inherit; }

/* ============================================================
   SETUP VIEW
   ============================================================ */
#setup-view {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr 26rem;
  max-width: 1500px;
  margin: 0 auto;
}

/* -- Resume Banner -- */
.resume-banner {
  grid-column: 1 / -1;
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2.5rem;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid var(--border);
}
.resume-banner.visible { display: flex; }
.resume-banner-text {
  font-size: 0.95rem;
  color: var(--text-secondary);
}
.resume-banner-text strong {
  color: var(--text-primary);
  font-weight: 600;
}
.resume-banner-actions {
  display: flex;
  gap: 0.5rem;
}

/* -- Editor Pane (Left) -- */
.editor-pane {
  padding: 2.5rem 2.5rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.editor-header { margin-bottom: 2rem; }
.editor-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
}
.editor-subtitle {
  font-size: 0.95rem;
  font-weight: 300;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* Phase List */
.phase-list { flex: 1; }

.phase-item {
  display: grid;
  grid-template-columns: 3rem 1fr auto 2.2rem 1.8rem;
  gap: 1rem;
  align-items: center;
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}
.phase-item.drag-over-top {
  border-top: 2px solid rgba(255,255,255,0.3);
}
.phase-item.drag-over-bottom {
  border-bottom: 2px solid rgba(255,255,255,0.3);
}
.phase-item.dragging { opacity: 0.4; }

/* Color Swatch */
.color-swatch {
  width: 3rem;
  height: 3rem;
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease;
  border: none;
  padding: 0;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch::after {
  content: '';
  position: absolute;
  inset: 1.5px;
  border-radius: 8.5px;
  border: 1px solid rgba(255,255,255,0.1);
  pointer-events: none;
}

/* Phase Name */
.phase-name-input {
  font-size: 1.1rem;
  font-weight: 600;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-primary);
  padding: 0.45rem 0.6rem;
  width: 100%;
  letter-spacing: -0.01em;
  transition: border-color 0.15s ease;
}
.phase-name-input:focus {
  outline: none;
  border-color: var(--border-strong);
}
.phase-name-input::placeholder { color: var(--text-muted); }

/* Time Control */
.time-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.mode-pill {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.mode-pill:hover { border-color: var(--border-strong); color: var(--text-secondary); }
.mode-pill.active {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.75);
  border-color: rgba(255,255,255,0.15);
}
.time-input {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 500;
  width: 6rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 0.5rem 0.6rem;
  text-align: center;
  transition: border-color 0.15s ease;
}
.time-input:focus { outline: none; border-color: var(--border-strong); }
.time-input.error { border-color: var(--error); background: var(--error-bg); }
.time-input.readonly {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
  border-color: transparent;
  background: transparent;
}
.time-input-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.time-input-label.readonly { opacity: 0.3; }
.next-day-badge {
  display: none;
  font-size: 0.6rem;
  font-weight: 700;
  color: #e0a040;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.next-day-badge.visible { display: inline; }

/* Delete + Drag */
.delete-btn {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.delete-btn:hover { background: var(--error-bg); color: var(--error); }
.delete-btn svg { width: 16px; height: 16px; }
.drag-handle {
  color: rgba(255,255,255,0.3);
  cursor: grab;
  font-size: 1.1rem;
  text-align: center;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.drag-handle:active { cursor: grabbing; }

/* Add Phase */
.add-phase-row { padding: 0 0 0.8rem 0; }
.add-phase-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.add-phase-btn:hover { border-color: rgba(255,255,255,0.25); color: var(--text-primary); background: rgba(255,255,255,0.06); }
.add-phase-btn:active { transform: scale(0.98); }

/* Editor Footer */
.editor-footer {
  margin-top: auto;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.editor-footer strong { color: var(--text-secondary); font-weight: 600; }

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
  color: var(--text-muted);
}
.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}
.empty-state-text {
  font-size: 1rem;
  margin-bottom: 1.2rem;
}

/* -- Color Picker Popover -- */
.color-picker-popover {
  position: absolute;
  z-index: 20;
  background: #1a1a1e;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 0.8rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  display: none;
}
.color-picker-popover.visible { display: block; }
.color-picker-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}
.color-preset {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
}
.color-preset:hover { transform: scale(1.1); }
.color-preset.selected { border-color: rgba(255,255,255,0.6); }
.color-picker-custom {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.color-picker-custom label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.color-picker-custom input[type="color"] {
  width: 2rem;
  height: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: transparent;
  padding: 0;
}

/* -- Sidebar (Right) -- */
.sidebar {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 2.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}
.sidebar-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.7rem;
}

/* Templates */
.template-list { display: flex; flex-direction: column; gap: 0.25rem; }
.template-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.template-item:hover { background: rgba(255,255,255,0.04); }
.template-item.active { background: rgba(255,255,255,0.06); }
.template-name { font-size: 0.9rem; font-weight: 500; }
.template-meta { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.15rem; }
.template-delete {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.1);
  cursor: pointer;
  padding: 0.2rem;
  border: none;
  background: none;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.template-delete:hover { color: var(--error); background: var(--error-bg); }
.template-save-row {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.4rem;
}
.template-save-input {
  flex: 1;
  font-size: 0.85rem;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
}
.template-save-input:focus { outline: none; border-color: var(--border-strong); }
.template-save-input::placeholder { color: var(--text-muted); }

/* Radio Options (brightness, transition, sound) */
.radio-options { display: flex; flex-direction: column; gap: 0.2rem; }
.radio-option {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s ease;
  border: none;
  background: none;
  color: var(--text-secondary);
  width: 100%;
  text-align: left;
}
.radio-option:hover { background: rgba(255,255,255,0.04); }
.radio-option.active { background: rgba(255,255,255,0.06); color: var(--text-primary); }
.radio-dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  position: relative;
  flex-shrink: 0;
}
.radio-option.active .radio-dot::after {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: var(--text-primary);
}
.brightness-swatch {
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

/* Start Button */
.start-section { margin-top: auto; }
.start-btn {
  width: 100%;
  padding: 0.9rem;
  border-radius: 12px;
  border: none;
  background: var(--text-primary);
  color: var(--bg);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s ease;
}
.start-btn:hover { opacity: 0.9; }
.start-btn:active { transform: scale(0.98); }
.start-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}
.start-meta {
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Shared small button */
.btn-sm {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-sm:hover { border-color: var(--border-strong); color: var(--text-primary); }
.btn-sm.primary {
  background: var(--text-primary);
  color: var(--bg);
  border-color: transparent;
}
.btn-sm.primary:hover { opacity: 0.85; }

/* ============================================================
   TIMER VIEW
   ============================================================ */
#timer-view {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  justify-content: center;
  padding: 3rem 3rem 3rem 8vw;
  transition: background 1.2s ease;
  overflow: hidden;
}
#timer-view.active { display: flex; }

/* Flash overlay */
.flash-overlay {
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}

/* Transition layers */
.transition-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem 3rem 3rem 8vw;
  pointer-events: none;
  z-index: 5;
}

/* Phase info (top-right) */
.phase-info-tr {
  position: absolute;
  top: 2rem;
  right: 2.5rem;
  text-align: right;
}
.phase-counter {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.4;
}
.phase-dots {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
  margin-top: 0.4rem;
  flex-wrap: wrap;
  max-width: 12rem;
}
.phase-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  transition: background 0.3s ease;
}
.phase-dot.done { background: rgba(255,255,255,0.4); }
.phase-dot.current {
  background: rgba(255,255,255,0.8);
  box-shadow: 0 0 6px rgba(255,255,255,0.3);
}

/* Timer content */
.timer-next-hint {
  font-size: clamp(1.1rem, 2.2vw, 1.8rem);
  font-weight: 400;
  opacity: 0.5;
  margin-bottom: 0.3rem;
  letter-spacing: 0.02em;
}
.timer-phase-name {
  font-size: clamp(2rem, 6vw, 5rem);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: 0.4rem;
  text-shadow: 0 2px 20px rgba(0,0,0,0.3);
}
.timer-countdown {
  font-family: var(--font-mono);
  font-size: clamp(5rem, 18vw, 16rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  text-shadow: 0 4px 40px rgba(0,0,0,0.4);
  transition: color 0.5s ease;
}
.timer-countdown.pulse {
  animation: pulse-opacity 1s ease-in-out infinite;
}
.timer-countdown.urgent {
  color: #ffccaa;
}
.timer-times {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  margin-top: 0.6rem;
}
.timer-end-time {
  font-size: clamp(1rem, 2vw, 1.6rem);
  font-weight: 400;
  opacity: 0.5;
  letter-spacing: 0.03em;
}
.timer-times-sep {
  font-size: clamp(0.8rem, 1.5vw, 1.2rem);
  opacity: 0.25;
}
.timer-session-end {
  font-size: clamp(1rem, 2vw, 1.6rem);
  font-weight: 400;
  opacity: 0.35;
  letter-spacing: 0.03em;
}
.timer-paused-badge {
  display: none;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  opacity: 0.5;
  margin-top: 0.8rem;
}
.timer-paused-badge.visible { display: block; }

/* Controls (bottom-right) */
.timer-controls {
  position: absolute;
  bottom: 1.5rem;
  right: 2rem;
  display: flex;
  gap: 0.5rem;
  opacity: 0.55;
  transition: opacity 0.3s ease;
}
.timer-controls:hover { opacity: 1; }
.timer-ctrl {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: 1.5px solid rgba(128,128,128,0.5);
  background: rgba(0,0,0,0.3);
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.timer-ctrl:hover {
  background: rgba(0,0,0,0.45);
  border-color: rgba(128,128,128,0.7);
}
.timer-ctrl svg { width: 12px; height: 12px; }

/* Progress bar */
.session-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: rgba(255,255,255,0.08);
}
.session-progress-fill {
  height: 100%;
  background: rgba(255,255,255,0.35);
  transition: width 0.5s linear;
  border-radius: 0 3px 3px 0;
}

/* ============================================================
   END SCREEN (overlay on timer)
   ============================================================ */
.end-screen {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem;
  background: var(--bg);
}
.end-screen.visible { display: flex; }
.end-title {
  font-size: clamp(1.5rem, 4vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 1rem;
}
.end-subtitle {
  font-size: 0.9rem;
  opacity: 0.5;
  margin-bottom: 2rem;
}
.end-phases {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 2.5rem;
  max-width: 24rem;
  width: 100%;
}
.end-phase-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.75rem;
  opacity: 0.6;
}
.end-phase-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.end-phase-name { flex: 1; text-align: left; }
.end-phase-time {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  opacity: 0.7;
}
.end-back-btn {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.7rem 2rem;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
}
.end-back-btn:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.3); }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes pulse-opacity {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}
@keyframes flash-in-out {
  0% { opacity: 0; }
  30% { opacity: 0.18; }
  100% { opacity: 0; }
}
@keyframes slide-in-right {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
@keyframes slide-out-left {
  from { transform: translateX(0); }
  to { transform: translateX(-100%); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  #setup-view {
    grid-template-columns: 1fr;
  }
  .editor-pane {
    padding: 2rem 1.5rem;
  }
  .sidebar {
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 1.5rem;
  }
  .phase-item {
    grid-template-columns: 2.2rem 1fr auto 1.5rem 1.2rem;
    gap: 0.5rem;
  }
  .time-control { flex-wrap: wrap; }
}
@media (max-width: 768px) {
  .phase-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.8rem;
    padding: 1rem 0;
  }
  .phase-item .color-swatch {
    width: 2.5rem;
    height: 2.5rem;
    flex-shrink: 0;
  }
  .phase-item .phase-name-input {
    flex: 1;
    min-width: 0;
  }
  .phase-item .delete-btn {
    flex-shrink: 0;
  }
  .phase-item .time-control {
    width: 100%;
    flex-wrap: wrap;
  }
  .phase-item .drag-handle { display: none; }
  #timer-view { padding: 2rem 2rem 2rem 5vw; }
}
