/* StudyFlow Timer Page Styles */
/* Using system fonts for performance */
:root {
  --primary-bg: #0f1419;
  --text-color: #e7eaee;
  --accent-color: #64ffda;
  --card-bg: rgba(15, 20, 25, 0.20); /* Ultra transparent for maximum background visibility */
  --btn-bg: #1c232d;
  --btn-hover: #293440;
  --timer-text-size: 5rem;
  --timer-mode-size: 1.5rem;
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* Theme-specific Overrides (set by JS) */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-family);
  background: var(--primary-bg);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background-color 0.5s;
}

/* Background and Particle Containers */
#bg-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  z-index: -1; /* Behind everything */
}

#background-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.9;
  transition: opacity 0.8s ease-in-out;
}

/* Header (Logo and Clock) */
.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.studyflow-logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-color);
}

.flow-link {
  text-decoration: none;
  color: var(--text-color);
  opacity: 0.7;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  padding: 0.25rem;
  border-radius: 6px;
}

.flow-link:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.headphones-icon {
  font-size: 1.2rem;
  animation: pulse-glow 2s infinite;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.clock-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.1rem;
}

/* Stabilize clock layout to avoid CLS from shifting digits */
#perpetual-clock {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  width: 9ch;
  text-align: right;
}

/* Main Timer Card */
.container {
  padding: 2rem 1rem;
  max-width: 90%;
  width: 450px;
}

.timer-card {
  background: var(--card-bg);
  /* glassmorphism: apply a subtle frosted glass effect after initial paint */
  backdrop-filter: none; /* applied later when the page is stable */
  -webkit-backdrop-filter: none; /* Safari prefix; applied later */
  border-radius: 16px;
  padding: 2.5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  position: relative;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.04); /* very subtle border to separate from bg */
}

/* Apply blur after the page is stable to reduce initial paint cost */
/* Apply blur (standard + vendor prefixed) once the page is ready */
body.ready .timer-card {
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Ticking state - breathing glow that uses the accent color */
.timer-card.is-ticking {
  box-shadow: 0 10px 40px rgba(0,0,0,0.55), 0 0 18px rgba(100,255,218,0.12);
  animation: ticking-glow 1.8s ease-in-out infinite;
}

@keyframes ticking-glow {
  0% { box-shadow: 0 10px 30px rgba(0,0,0,0.5), 0 0 6px rgba(100,255,218,0.06); }
  50% { box-shadow: 0 12px 46px rgba(0,0,0,0.6), 0 0 22px rgba(100,255,218,0.18); }
  100% { box-shadow: 0 10px 30px rgba(0,0,0,0.5), 0 0 6px rgba(100,255,218,0.06); }
}

/* Respect prefers-reduced-motion: disable the glowing animation */
@media (prefers-reduced-motion: reduce) {
  .timer-card.is-ticking { animation: none !important; }
}

/* Opt-out class: when body has .no-ticking-glow, the glow is disabled */
/* Support applying the opt-out class to either html or body for early-preference read */
html.no-ticking-glow .timer-card.is-ticking,
body.no-ticking-glow .timer-card.is-ticking {
  animation: none !important;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

/* Utility Icons */
.card-icon {
  position: absolute;
  top: 1.5rem;
  cursor: pointer;
  width: 24px;
  height: 24px;
  fill: var(--text-color);
  transition: fill 0.2s, transform 0.1s;
}

.card-icon:hover {
  fill: var(--accent-color);
  transform: scale(1.05);
}

.calendar-icon { right: 1.5rem; }
.settings-icon { right: 4.5rem; }

.back-btn {
  position: absolute;
  top: 1.2rem;
  left: 1.5rem;
  background: #8b4513; /* Wooden style color */
  color: #fff;
  padding: 0.3rem 0.8rem;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  border: 2px solid #5a2e0a;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.4);
  transition: background 0.2s, transform 0.1s;
}

.back-btn:hover {
  background: #9d5220;
}

/* Timer Content */
.timer-mode {
  font-size: var(--timer-mode-size);
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--accent-color);
  text-transform: uppercase;
  transition: color 0.3s ease;
}

/* Seasonal Timer Mode Colors */
.summer-theme .timer-mode {
  color: #22c55e; /* Green for summer */
}

.autumn-theme .timer-mode {
  color: #d97706; /* Burnt orange/brown for autumn */
}

.winter-theme .timer-mode {
  color: #60a5fa; /* Light blue for winter */
}

.timer-display {
  font-size: var(--timer-text-size);
  font-weight: 700;
  margin: 0.5rem 0 1.5rem;
  letter-spacing: 0.1rem;
}

.timer-controls {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
}

.control-btn {
  background: var(--btn-bg);
  color: var(--text-color);
  border: none;
  padding: 1rem 2rem;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.control-btn:hover {
  background: var(--btn-hover);
  transform: translateY(-2px);
}

.control-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.session-info {
  margin-top: 1.5rem;
  font-size: 0.95rem;
  color: #e0e0e0; /* Brighter for 20% opacity background */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); /* Add shadow for readability */
}

.session-counter {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: #f0f0f0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.control-btn {
  cursor: pointer;
  margin: 0 0.75rem;
  transition: all 0.2s ease;
  outline: none;
}

/* Cartoon/Anime Wood Style Buttons */
.wood-btn {
  background: linear-gradient(145deg, #8b5a3c, #6b4226);
  border: 3px solid #5d3a21;
  border-radius: 25px;
  padding: 12px 24px;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  font-size: 16px;
  font-weight: bold;
  color: #fff2e6;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
  box-shadow: 
    0 6px 0 #4a2c17,
    0 8px 15px rgba(0, 0, 0, 0.4),
    inset 0 2px 0 rgba(255, 255, 255, 0.2);
  position: relative;
}

.wood-btn::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  right: 2px;
  bottom: 8px;
  background: linear-gradient(145deg, #a0674a, #8b5a3c);
  border-radius: 22px;
  z-index: -1;
}

.wood-btn:hover {
  transform: translateY(-3px);
  box-shadow: 
    0 8px 0 #4a2c17,
    0 12px 20px rgba(0, 0, 0, 0.5),
    inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

.wood-btn:active {
  transform: translateY(2px);
  box-shadow: 
    0 2px 0 #4a2c17,
    0 4px 8px rgba(0, 0, 0, 0.3),
    inset 0 2px 0 rgba(255, 255, 255, 0.2);
}

.wood-btn:disabled {
  background: linear-gradient(145deg, #6b5a5a, #5a4949);
  border-color: #4a3939;
  color: #bbb;
  cursor: not-allowed;
  transform: none;
  box-shadow: 
    0 3px 0 #3d2d2d,
    0 5px 10px rgba(0, 0, 0, 0.2);
}

.wood-btn:disabled::before {
  background: linear-gradient(145deg, #7a6969, #6b5a5a);
}

/* Loading Indicator */
#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--primary-bg);
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--accent-color);
  font-size: 1.5rem;
  z-index: 100;
  transition: opacity 0.5s;
}

/* Settings Modal (Placeholder) */
.settings-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  padding: 2rem;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  z-index: 20;
  max-width: 400px;
  width: 90%;
  display: none;
}

.settings-modal.show { display: block; }

.settings-modal h2 { margin-bottom: 1.5rem; font-size: 1.8rem; }

.setting-group {
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.setting-group label {
  font-size: 1rem;
  margin-right: 1rem;
}

.setting-group select {
  background: var(--btn-bg);
  color: var(--text-color);
  border: 1px solid var(--btn-hover);
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
}

.settings-close-btn {
  margin-top: 1.5rem;
  background: var(--accent-color);
  color: var(--primary-bg);
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: opacity 0.2s;
}

.settings-close-btn:hover { opacity: 0.8; }

/* Save button styling — more prominent and consistent */
.settings-save-btn {
  margin-top: 1.5rem;
  background: linear-gradient(90deg, #64ffda, #4bd3b0);
  color: #071019;
  padding: 0.6rem 1.1rem;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(75, 211, 176, 0.18), inset 0 1px 0 rgba(255,255,255,0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s;
  margin-right: 0.5rem;
}
.settings-save-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(75, 211, 176, 0.22);
}
.settings-save-btn:active {
  transform: translateY(0px);
  box-shadow: 0 4px 12px rgba(75, 211, 176, 0.16);
}

/* Settings modal action row */
.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

/* Make Close button match subdued style */
.settings-close-btn {
  margin-top: 0;
  background: transparent;
  color: var(--text-color);
  padding: 0.5rem 0.9rem;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.12s, transform 0.08s;
}
.settings-close-btn:hover { background: rgba(255,255,255,0.02); transform: translateY(-1px); }

/* Improve focus outlines for accessibility */
.settings-save-btn:focus, .settings-close-btn:focus {
  outline: 3px solid rgba(100,255,218,0.16);
  outline-offset: 2px;
}


/* Responsive Mobile Adaptations */
@media (max-width: 768px) {
  :root {
    --timer-text-size: 4rem;
    --timer-mode-size: 1.2rem;
  }
  .header {
    padding: 0.75rem 1rem;
  }
  .studyflow-logo {
    font-size: 1.2rem;
  }
  .clock-container {
    font-size: 0.9rem;
  }
  .timer-card {
    padding: 2rem 1.5rem;
  }
  .timer-controls {
    flex-direction: column;
    gap: 0.75rem;
  }
  .control-btn {
    width: 100%;
    padding: 0.8rem 1rem;
  }
  .back-btn {
    top: 0.75rem;
    left: 0.75rem;
  }
  .calendar-icon { right: 0.75rem; }
  .settings-icon { right: 3.5rem; }
}

/* ------------------------- */
/* micro-animations (low-jank) */
/* ------------------------- */

:root {
  --accent: 217 100% 60%;
  --accent-2: 280 85% 60%;
  --card-bg: hsla(0 0% 100% / .08);
  --ring: hsl(var(--accent));
}

/* Ambient gradient layer — prefers-reduced-motion aware */
@media (prefers-reduced-motion:no-preference) {
  .ambient-gradient::before{
    content:""; position:fixed; inset:-20%;
    background: radial-gradient(60% 60% at 30% 20%, hsl(var(--accent)/.20), transparent 60%),
                radial-gradient(60% 60% at 70% 80%, hsl(var(--accent-2)/.18), transparent 60%);
    animation: drift 18s ease-in-out infinite alternate;
    pointer-events:none; z-index:0; filter: blur(40px);
  }
  @keyframes drift { to { transform: translate3d(2%, -2%, 0) scale(1.03); } }
}

/* Breathing focus ring for primary buttons */
.button-primary{ position:relative; isolation:isolate; box-shadow: 0 8px 24px -12px hsl(var(--accent)/.5); }
@media (prefers-reduced-motion:no-preference){
  .button-primary::after{
    content:""; position:absolute; inset:-2px; border-radius:inherit; z-index:-1;
    background: conic-gradient(from 0deg, hsl(var(--accent)/.0), hsl(var(--accent)/.55), hsl(var(--accent)/.0) 70%);
    filter: blur(8px); opacity:0; transition:opacity .2s ease;
    animation: spin 6s linear infinite paused;
  }
  .button-primary:hover::after, .button-primary:focus-visible::after { opacity:1; animation-play-state: running; }
  @keyframes spin { to { transform: rotate(360deg); } }
}

/* Timer progress ring (CSS-driven) */
.timer-ring{
  --p: 0; width:160px; aspect-ratio:1/1; border-radius:50%;
  background:
    radial-gradient(closest-side, var(--card-bg) 78%, transparent 80% 100%),
    conic-gradient(hsl(var(--accent)) calc(var(--p)*1turn), hsl(0 0% 100% / .12) 0);
  transition: background .2s linear;
}

/* Tick shimmer on the clock */
@media (prefers-reduced-motion:no-preference){
  .tick-shimmer{ position:relative; }
  .tick-shimmer::after{
    content:""; position:absolute; inset:0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.18), transparent);
    transform: translateX(-120%); pointer-events:none;
  }
  .tick-shimmer.is-ticking::after{ animation: sweep .6s ease; }
  @keyframes sweep { to { transform: translateX(120%); } }
}

/* Confetti burst (12 particles) */
.confetti{ position:fixed; inset:0; pointer-events:none; z-index:9999; }
.confetti i{ position:absolute; width:6px; height:10px; opacity:0; transform:translateY(-20px) rotate(0); }
@media (prefers-reduced-motion:no-preference){
  .confetti i{ animation: drop 900ms ease-out forwards; }
  @keyframes drop { 10%{ opacity:1; } 100%{ transform: translateY(100vh) rotate(540deg); opacity:0; } }
}

/* Background parallax only after ready */
body.ready #background-image{ transition: transform .2s ease; will-change: transform; }

/* Hover lift for cards */
.sf-card{ transform: translate3d(0,0,0); transition: transform .18s ease, box-shadow .18s ease; }
.sf-card:hover{ transform: translateY(-2px); box-shadow: 0 10px 30px -20px hsl(var(--accent)/.6); }
