:root {
  --bg: #000000;
  --text: #f5f7fb;
  --card: #101216;
  --card-border: rgba(255, 255, 255, 0.08);
  --muted: #a9b1bb;
  --input-bg: #161a20;
  --input-border: rgba(255, 255, 255, 0.12);
  --button-bg: #1f2937;
  --button-text: #f5f7fb;
  --primary: #2563eb;
  --popup-bg: rgba(16, 18, 22, 0.92);
  --popup-border: rgba(255, 255, 255, 0.08);
  --shadow: rgba(0, 0, 0, 0.35);
  
  /* Neon glow variables for Dark Mode - Brighter and slightly wider */
  --card-neon-border: rgba(255, 255, 255, 0.85); /* Brighter white core */
  --card-neon-glow: 0 0 8px rgba(255, 255, 255, 0.5), 0 0 22px rgba(255, 255, 255, 0.2); /* Wider glow radius */
}

body.light-mode {
  --bg: #f4f6f8;
  --text: #111827;
  --card: #ffffff;
  --card-border: rgba(17, 24, 39, 0.08);
  --muted: #5b6472;
  --input-bg: #f7f8fa;
  --input-border: rgba(17, 24, 39, 0.12);
  --button-bg: #e5e7eb;
  --button-text: #111827;
  --primary: #2563eb;
  --popup-bg: rgba(255, 255, 255, 0.92);
  --popup-border: rgba(17, 24, 39, 0.08);
  --shadow: rgba(17, 24, 39, 0.12);
  
  /* Disables the white neon in Light Mode */
  --card-neon-border: rgba(17, 24, 39, 0.12);
  --card-neon-glow: 0 0 0 transparent; 
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Open Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* --- POPUP WINDOW SPECIFIC STYLES --- */
body.popup-mode {
  overflow: hidden;
  display: flex;
  align-items: center; 
  justify-content: center;
  background: var(--bg); 
}

body.popup-mode .container,
body.popup-mode .theme-toggle {
  display: none;
}

body.popup-mode .popup {
  position: static; 
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: none;
  border-radius: 0;
  resize: none;
  box-shadow: none; 
  backdrop-filter: none;
  background: transparent;
  padding: 0; 
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center; 
  cursor: default;
}

body.popup-mode .popup-header {
  position: absolute; 
  top: 8px;
  right: 8px;
  width: auto;
  margin-bottom: 0px; 
}

body.popup-mode #timeDisplay {
  font-family: 'Share Tech Mono', monospace;
  font-size: 44px; 
  letter-spacing: 2px;
  margin: 8px 0 14px; 
}

body.popup-mode .popup-controls button {
  width: 36px;  
  height: 36px;
  font-size: 14px;
}

body.popup-mode .popup::after,
body.popup-mode .resize-hint {
  display: none;
}
/* ------------------------------------ */


.theme-toggle {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 42px;
  height: 22px;
  border-radius: 999px;
  background: #30343a;
  box-shadow: 0 4px 12px var(--shadow);
  display: flex;
  align-items: center;
  padding: 2px;
  cursor: pointer;
  user-select: none;
  z-index: 1000;
  transition: background-color 0.25s ease, box-shadow 0.25s ease;
}

body.light-mode .theme-toggle {
  background: #d6dbe3;
}

.toggle-circle {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  transform: translateX(0);
  transition: transform 0.22s ease, background-color 0.22s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

body.light-mode .toggle-circle {
  transform: translateX(20px);
  background: #ffffff;
}

.container {
  width: min(560px, calc(100% - 32px));
  margin: 92px auto 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.title {
  margin: 0 0 18px;
  font-size: 38px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* MAIN TIMER BODY - Enhanced neon strip */
.card {
  width: 100%;
  background: var(--card);
  border: 1.5px solid var(--card-neon-border); /* Slightly thicker line */
  border-radius: 22px;
  padding: 24px;
  box-shadow: var(--card-neon-glow), 0 16px 38px var(--shadow);
  transition: border 0.3s ease, box-shadow 0.3s ease;
}

.label {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
}

.inputs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label,
.sound-row label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.input-group input,
.sound-row select,
.sound-row input[type="range"] {
  width: 100%;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 12px;
  font-size: 15px;
  outline: none;
}

.input-group input::placeholder {
  color: var(--muted);
}

.input-group input:focus,
.sound-row select:focus {
  border-color: rgba(37, 99, 235, 0.8);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.presets {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.presets button,
#startBtn,
.popup-controls button,
#closePopup {
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s ease, background-color 0.2s ease, opacity 0.2s ease;
}

.presets button:hover,
#startBtn:hover,
.popup-controls button:hover,
#closePopup:hover {
  transform: translateY(-1px);
}

/* Satisfying tactile click state */
.presets button:active,
#startBtn:active,
.popup-controls button:active,
#closePopup:active {
  transform: scale(0.96); 
}

.presets button {
  background: var(--button-bg);
  color: var(--button-text);
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
}

.sound-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
}

.sound-row select {
  appearance: none;
}

.sound-row input[type="range"] {
  padding: 0;
  height: 36px;
}

#startBtn {
  width: 100%;
  margin-top: 18px;
  background: var(--primary);
  color: #fff;
  padding: 13px 16px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

/* Fallback "in-page" popup with neon removed */
.popup {
  position: fixed;
  top: 70px;
  right: 70px;
  width: 160px;
  min-width: 140px;
  min-height: 120px;
  background: var(--popup-bg);
  border: 1px solid var(--popup-border);
  border-radius: 14px;
  padding: 8px;
  resize: both;
  overflow: auto;
  backdrop-filter: blur(6px);
  z-index: 999;
  cursor: default;
}

.popup::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  right: 4px;
  bottom: 4px;
  cursor: se-resize;
}

.hidden {
  display: none;
}

.popup-header {
  display: flex;
  align-items: center;
  justify-content: flex-end; 
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  padding-bottom: 6px;
}

#closePopup {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  line-height: 1;
  padding: 0;
}

/* Base timer styles */
#timeDisplay {
  text-align: center;
  font-weight: 700;
}

/* Non-popup fallback style */
:not(body.popup-mode) #timeDisplay {
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(30px, 6vw, 42px); 
  letter-spacing: 2px;
  margin: 12px 0 16px;
}

.popup-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.popup-controls button {
  border-radius: 12px;
  background: var(--button-bg);
  color: var(--button-text);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Standard fallback button style */
:not(body.popup-mode) .popup-controls button {
  width: 40px;
  height: 40px;
  font-size: 18px;
}

.resize-hint {
  margin-top: 8px;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  opacity: 0.75;
}

.blink {
  color: #ff4d4d;
}

/* Pulsing Pause Animation */
@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.6; }
  100% { opacity: 1; }
}

.pulse-pause {
  animation: pulse 1.5s ease-in-out infinite;
}

@media (max-width: 560px) {
  .container {
    margin-top: 84px;
  }
  .title {
    font-size: 32px;
  }
  .inputs {
    grid-template-columns: 1fr;
  }
  .popup {
    right: 16px;
    top: 92px;
    width: 170px;
  }
}