/* ==========================================================================
   INTERVAL CLOCK - CSS DESIGN SYSTEM (REVISED)
   ========================================================================== */

/* Design Tokens & Variables */
:root {
  --bg-color-main: #06070a;
  --bg-color-card: rgba(15, 18, 28, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-glow: rgba(0, 242, 254, 0.25);
  
  /* Color Palette Accents */
  --accent-cyan: #00f2fe;
  --accent-blue: #4facfe;
  --accent-warning: #ff2a5f;
  --accent-amber: #ff9f0a;
  --accent-amber-rgb: 255, 159, 10;
  
  /* Dynamic State-driven Accents (Modified via body classes) */
  --dynamic-accent: var(--accent-cyan);
  --dynamic-accent-glow: rgba(0, 242, 254, 0.35);
  
  /* Neutral Palette */
  --text-primary: #f5f6f9;
  --text-muted: #838a9d;
  --text-dim: #3a3f50;

  /* Typography */
  --font-display: 'Orbitron', 'Courier New', monospace;
  --font-mono: 'Share Tech Mono', monospace;
  --font-sans: 'Outfit', system-ui, -apple-system, sans-serif;
  
  /* Transitions */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* State overrides for body color themes */
body.state-buffer {
  --dynamic-accent: var(--accent-amber);
  --dynamic-accent-glow: rgba(255, 159, 10, 0.4);
}

body.state-interval {
  --dynamic-accent: var(--accent-cyan);
  --dynamic-accent-glow: rgba(0, 242, 254, 0.4);
}

body.state-paused {
  --dynamic-accent: var(--accent-blue);
  --dynamic-accent-glow: rgba(79, 172, 254, 0.35);
}

/* CSS Reset & Core Layout */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  background-color: var(--bg-color-main);
  color: var(--text-primary);
  font-family: var(--font-sans);
  height: 100vh;
  height: 100dvh;
  overflow-y: auto; /* scroll vertically if viewport height is < 800px */
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

/* Ambient Background Glow */
.glass-bg-glow {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 140vw;
  height: 140vh;
  background: 
    radial-gradient(circle at 30% 20%, rgba(79, 172, 254, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 70% 80%, rgba(255, 159, 10, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(15, 18, 28, 1) 0%, var(--bg-color-main) 70%);
  z-index: -1;
  pointer-events: none;
}

/* App Layout Container */
.app-container {
  width: 100%;
  max-width: 440px;
  height: 100dvh;
  min-height: 800px; /* lock layout height to at least 800px */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 20px;
  z-index: 10;
  position: relative;
  box-sizing: border-box;
}

/* Glassmorphism Card Style Utility */
.card {
  background: var(--bg-color-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: 20px; /* reduced from 28px */
  padding: 14px 20px; /* reduced from 20px 24px */
  box-shadow: 
    0 8px 32px 0 rgba(0, 0, 0, 0.37),
    inset 0 1px 1px rgba(255, 255, 255, 0.05);
  transition: border-color var(--transition-normal);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

/* --------------------------------------------------------------------------
   Header Components
   -------------------------------------------------------------------------- */
.app-header {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 8px;
  height: 38px;
  flex-shrink: 0;
  width: 100%;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-dot {
  width: 8px;
  height: 8px;
  background-color: var(--dynamic-accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--dynamic-accent);
  animation: pulseGlow 2s infinite alternate;
  transition: background-color var(--transition-normal), box-shadow var(--transition-normal);
}

.header-logo h1 {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--text-primary);
}

.wake-lock-label {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Main Content & Clock Panel
   -------------------------------------------------------------------------- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  min-height: 0; /* allows scaling down in flex layout */
}

/* Clock Display Card */
.clock-display-card {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1; /* let it grow and take up remaining space */
  width: auto;
  aspect-ratio: 1 / 1;
  max-width: 320px;
  max-height: 320px;
  min-width: 220px; /* prevent shrinking too small */
  min-height: 220px;
  border-radius: 50%;
  position: relative;
  background: radial-gradient(circle, rgba(15, 18, 28, 0.6) 0%, rgba(5, 6, 10, 0.8) 100%);
  border: 1px solid var(--border-color);
  box-shadow: 
    0 12px 30px rgba(0, 0, 0, 0.5),
    inset 0 4px 20px rgba(255, 255, 255, 0.01);
  margin: 6px auto;
  padding: 8px;
  flex-shrink: 1; /* allow shrink if height is low */
}

/* SVG Progress Ring Wrapping */
.progress-ring-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  container-type: inline-size; /* Add container queries support */
}

.progress-ring-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.progress-ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.02);
  stroke-width: 5;
}

.progress-ring-bar {
  fill: none;
  stroke: var(--dynamic-accent);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 552.92;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.1s linear, stroke var(--transition-normal);
  filter: drop-shadow(0 0 6px var(--dynamic-accent));
}

/* Digital Clock Face Inside the Ring */
.digital-clock-face {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 5;
  width: 100%;
  text-align: center;
}

.phase-label {
  font-family: var(--font-sans);
  font-size: 6.5cqw; /* Scale with container size */
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--dynamic-accent);
  text-shadow: 0 0 8px var(--dynamic-accent-glow);
  text-transform: uppercase;
  margin-bottom: 2px;
  transition: all var(--transition-normal);
}

.time-readout {
  font-family: var(--font-display);
  font-size: 16cqw; /* Shrunk to 16cqw to keep wide characters like 23:59:59 strictly inside the circle */
  font-weight: 700;
  color: var(--dynamic-accent);
  text-shadow: 0 0 15px var(--dynamic-accent-glow);
  letter-spacing: -1.5px;
  line-height: 1;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
  position: relative;
  transition: all var(--transition-normal);
}

.time-readout::before {
  content: "88:88:88";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  color: var(--text-dim);
  opacity: 0.06;
  z-index: -1;
  text-shadow: none;
  pointer-events: none;
}

.cycle-indicator {
  font-family: var(--font-sans);
  font-size: 5.5cqw; /* Scale with container size */
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  padding: 2% 6%;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Settings & Inputs Card
   -------------------------------------------------------------------------- */
.config-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 1;
  min-height: 0;
}

.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.setting-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.editable-label {
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 4px 0;
  flex-basis: 32%;
  min-width: 80px;
  max-width: 120px;
  outline: none;
  cursor: text;
  transition: border-bottom-color var(--transition-fast), color var(--transition-fast);
}

.editable-label:hover {
  color: var(--text-primary);
  border-bottom-color: rgba(255, 255, 255, 0.15);
}

.editable-label:focus {
  color: var(--dynamic-accent);
  border-bottom-color: var(--dynamic-accent);
}

/* Compact side-by-side Time Pickers */
.time-picker {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 2px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 4px 6px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  flex: 1;
  max-width: 200px;
}

.picker-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.picker-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.picker-controls input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: bold;
  text-align: center;
  width: 100%;
  padding: 2px 0;
  outline: none;
  font-variant-numeric: tabular-nums;
}

/* Hide default spin arrows */
.picker-controls input::-webkit-outer-spin-button,
.picker-controls input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.picker-controls input[type=number] {
  -moz-appearance: textfield;
}

.picker-colon {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--text-dim);
  line-height: 1;
}

/* Compact button spinners */
.spin-btn {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  width: 100%;
  max-width: 44px;
  height: 20px;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all var(--transition-fast);
}

.spin-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.spin-btn:active {
  transform: scale(0.9);
}

.cycles-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 4px 6px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  flex: 1;
  max-width: 200px;
}

.cycles-container.disabled {
  opacity: 0.25;
  pointer-events: none;
}

.cycles-container input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: bold;
  text-align: center;
  width: 100%;
  outline: none;
}

.cycles-container .spin-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Control Deck
   -------------------------------------------------------------------------- */
.control-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(8px, 4.5vw, 16px);
  flex-shrink: 0;
  width: 100%;
}

.control-btn {
  background: none;
  border: none;
  outline: none;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  transition: all var(--transition-normal);
}

.primary-btn {
  width: 66px;
  height: 66px;
  background: linear-gradient(135deg, var(--dynamic-accent) 0%, var(--accent-blue) 100%);
  color: #06070a;
  box-shadow: 
    0 6px 20px rgba(0, 242, 254, 0.25),
    inset 0 1px 2px rgba(255, 255, 255, 0.2);
}

body.state-buffer .primary-btn {
  background: linear-gradient(135deg, var(--dynamic-accent) 0%, #d97706 100%);
  box-shadow: 
    0 6px 20px rgba(255, 159, 10, 0.25),
    inset 0 1px 2px rgba(255, 255, 255, 0.2);
}

.primary-btn:hover {
  transform: translateY(-1px) scale(1.03);
}

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

.primary-btn svg {
  width: 26px;
  height: 26px;
}

.secondary-btn {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.secondary-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
  transform: scale(1.03);
}

.secondary-btn:active {
  transform: scale(0.97);
}

.secondary-btn.active {
  color: var(--dynamic-accent) !important;
  background: rgba(255, 255, 255, 0.06) !important;
  border-color: var(--dynamic-accent) !important;
  filter: drop-shadow(0 0 4px var(--dynamic-accent-glow));
}

.secondary-btn svg {
  width: 16px;
  height: 16px;
}

/* --------------------------------------------------------------------------
   Footer Permissions Bar
   -------------------------------------------------------------------------- */
.app-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 38px;
  flex-shrink: 0;
  margin-top: 16px; /* Added spacing from the control deck buttons */
}

.noti-badge {
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid var(--border-color);
  outline: none;
  padding: 6px 12px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.noti-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--text-dim);
}

.noti-badge span:last-child {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.noti-badge.system-active {
  border-color: rgba(0, 242, 254, 0.15);
  background: rgba(0, 242, 254, 0.02);
}
.noti-badge.system-active .noti-dot {
  background-color: var(--accent-cyan);
  box-shadow: 0 0 6px var(--accent-cyan);
}
.noti-badge.system-active span:last-child {
  color: var(--text-primary);
}

.noti-badge.system-warning {
  border-color: rgba(255, 42, 95, 0.15);
  background: rgba(255, 42, 95, 0.02);
}
.noti-badge.system-warning .noti-dot {
  background-color: var(--accent-warning);
}

.noti-badge:hover {
  background: rgba(255, 255, 255, 0.05);
}

.pwa-badge {
  border-color: rgba(0, 242, 254, 0.15) !important;
  background: rgba(0, 242, 254, 0.02) !important;
}

.pwa-badge:hover {
  background: rgba(0, 242, 254, 0.08) !important;
  border-color: rgba(0, 242, 254, 0.3) !important;
}

.pwa-badge span:last-child {
  color: var(--text-primary) !important;
}

.pwa-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent-cyan);
  box-shadow: 0 0 6px var(--accent-cyan);
  animation: pulseGlow 1.5s infinite alternate;
}

/* Keyframes */
@keyframes pulseGlow {
  0% {
    box-shadow: 0 0 4px var(--dynamic-accent);
    opacity: 0.7;
  }
  100% {
    box-shadow: 0 0 12px var(--dynamic-accent);
    opacity: 1;
  }
}

/* Fullscreen / Screen Lock Presentation Overrides */
body.state-screenlock .config-panel,
body.state-screenlock .app-header,
body.state-screenlock .app-footer,
:fullscreen .config-panel,
:fullscreen .app-header,
:fullscreen .app-footer,
:-webkit-full-screen .config-panel,
:-webkit-full-screen .app-header,
:-webkit-full-screen .app-footer {
  display: none !important;
}

body.state-screenlock .app-container,
:fullscreen .app-container,
:-webkit-full-screen .app-container {
  max-height: 100vh;
  height: 100vh;
  height: 100dvh;
  min-height: 0; /* remove min-height constraint in fullscreen to fit screen precisely */
  justify-content: center;
  gap: 30px;
  padding: 30px 20px;
}

body.state-screenlock .clock-display-card,
:fullscreen .clock-display-card,
:-webkit-full-screen .clock-display-card {
  width: min(80vw, 52vh);
  height: min(80vw, 52vh);
  max-width: 440px;
  max-height: 440px;
  flex: 1; /* expand circle to fill the vertical screen space */
}

/* Background overrides in fullscreen */
:fullscreen body,
:-webkit-full-screen body {
  background-color: #030406;
}
