/* ==========================================================================
   FocusMinute — Style Foundation
   ========================================================================== */

/* --- Custom Properties --------------------------------------------------- */

:root {
  /* Accent */
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.10);
  --accent-ring: rgba(99, 102, 241, 0.35);

  /* Light theme */
  --bg: #f8f8fb;
  --bg-surface: #ffffff;
  --text: #1e1e2e;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --shadow: rgba(0, 0, 0, 0.06);
  --timer-ring-bg: #e8e8ee;
  --timer-ring-progress: var(--accent);

  /* Sizing */
  --timer-size: 280px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #111118;
  --bg-surface: #1a1a24;
  --text: #e4e4ef;
  --text-secondary: #9ca3af;
  --border: #2a2a3a;
  --shadow: rgba(0, 0, 0, 0.3);
  --timer-ring-bg: #2a2a3a;
  --accent-soft: rgba(99, 102, 241, 0.14);
}

/* --- Reset / Base -------------------------------------------------------- */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* --- Focus indicators ---------------------------------------------------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* --- Reduced motion ------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   Header
   ========================================================================== */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 24px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  margin-right: auto;
}

.header__title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.header__icon {
  flex-shrink: 0;
}

/* --- Theme toggle -------------------------------------------------------- */

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  transition: background var(--transition), transform var(--transition);
}

.theme-toggle:hover {
  background: var(--accent-ring);
}

.theme-toggle:active {
  transform: scale(0.92);
}

/* Show/hide icons */
[data-theme="light"] .theme-toggle__icon--sun  { display: none; }
[data-theme="light"] .theme-toggle__icon--moon { display: block; }
[data-theme="dark"]  .theme-toggle__icon--sun  { display: block; }
[data-theme="dark"]  .theme-toggle__icon--moon { display: none; }

/* ==========================================================================
   Main
   ========================================================================== */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 24px 40px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* ==========================================================================
   Mode Selector
   ========================================================================== */

.modes {
  display: flex;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 36px;
  box-shadow: 0 1px 3px var(--shadow);
}

.modes__btn {
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.modes__btn:hover {
  color: var(--text);
}

.modes__btn--active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-ring);
}

.modes__btn--active:hover {
  background: var(--accent-hover);
  color: #fff;
}

/* ==========================================================================
   Timer
   ========================================================================== */

.timer {
  position: relative;
  width: var(--timer-size);
  height: var(--timer-size);
  margin-bottom: 32px;
}

.timer__ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer__ring-bg {
  fill: none;
  stroke: var(--timer-ring-bg);
  stroke-width: 6;
}

.timer__ring-progress {
  fill: none;
  stroke: var(--timer-ring-progress);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 565.48;   /* 2 * π * 90 */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.4s ease;
}

.timer__display {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.timer__time {
  font-size: 3.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--text);
}

.timer__label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ==========================================================================
   Controls
   ========================================================================== */

.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.controls__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}

.controls__btn:active {
  transform: scale(0.96);
}

/* Start / Pause */
.controls__btn--start {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-ring);
}

.controls__btn--start:hover {
  background: var(--accent-hover);
}

/* Running state label swap */
.controls__btn--start[data-running="true"] svg {
  display: none;
}

.controls__btn--start[data-running="true"]::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 16px;
  border-left: 4px solid currentColor;
  border-right: 4px solid currentColor;
}

/* Reset */
.controls__btn--reset {
  background: var(--accent-soft);
  color: var(--accent);
}

.controls__btn--reset:hover {
  background: var(--accent-ring);
}

/* ==========================================================================
   Session Counter
   ========================================================================== */

.session-counter {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 40px;
}

/* ==========================================================================
   Session Info
   ========================================================================== */

.session-info {
  text-align: center;
}

.session-info__title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
}

.session-info__dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

.session-info__dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--timer-ring-bg);
  transition: background var(--transition), transform var(--transition);
}

.session-info__dot--done {
  background: var(--accent);
  transform: scale(1.1);
}

.session-info__message {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
  text-align: center;
  padding: 20px 24px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  opacity: 0.7;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* ==========================================================================
   Break-mode accent overrides
   ========================================================================== */

[data-active-mode="short"] {
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-soft: rgba(16, 185, 129, 0.10);
  --accent-ring: rgba(16, 185, 129, 0.30);
  --timer-ring-progress: #10b981;
}

[data-active-mode="long"] {
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.10);
  --accent-ring: rgba(59, 130, 246, 0.30);
  --timer-ring-progress: #3b82f6;
}

/* Keep dark overrides for accent-soft */
[data-theme="dark"][data-active-mode="short"] {
  --accent-soft: rgba(16, 185, 129, 0.14);
}

[data-theme="dark"][data-active-mode="long"] {
  --accent-soft: rgba(59, 130, 246, 0.14);
}

/* ==========================================================================
   Running pulse
   ========================================================================== */

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 4px 14px var(--accent-ring); }
  50%      { box-shadow: 0 4px 24px var(--accent-ring), 0 0 0 6px var(--accent-soft); }
}

.controls__btn--start[data-running="true"] {
  animation: pulse-glow 2s ease-in-out infinite;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

/* Tablet */
@media (max-width: 768px) {
  :root {
    --timer-size: 240px;
  }

  .timer__time {
    font-size: 3rem;
  }

  .modes__btn {
    padding: 7px 14px;
    font-size: 0.82rem;
  }

  .main {
    padding-top: 4px;
  }
}

/* Mobile */
@media (max-width: 480px) {
  :root {
    --timer-size: 210px;
  }

  .header {
    padding: 12px 16px;
  }

  .main {
    padding: 4px 16px 32px;
  }

  .timer__time {
    font-size: 2.6rem;
  }

  .timer__label {
    font-size: 0.78rem;
  }

  .modes {
    margin-bottom: 28px;
  }

  .modes__btn {
    padding: 6px 12px;
    font-size: 0.78rem;
  }

  .controls__btn {
    padding: 10px 22px;
    font-size: 0.88rem;
  }

  .footer {
    padding: 16px;
  }
}

/* ---------- Added: icon button ---------- */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  transition: background var(--transition), transform var(--transition);
}

.icon-btn:hover {
  background: var(--accent-ring);
}

.icon-btn:active {
  transform: scale(0.92);
}

/* ---------- Added: settings modal ---------- */
.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal__panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px var(--shadow);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal__header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.modal__body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: auto;
}

.modal__footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.settings-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-fieldset legend {
  padding: 0 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}

.settings-row input[type="number"] {
  width: 80px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  text-align: center;
}

.settings-row input[type="number"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.settings-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.settings-status {
  margin: 0;
  min-height: 1.2rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.settings-status.is-error {
  color: #dc2626;
}

[data-theme="dark"] .settings-status.is-error {
  color: #f87171;
}

/* btn styles for modal footer */
.btn {
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition);
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--ghost {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn--ghost:hover {
  background: var(--accent-ring);
}
