/* Theme variables */
:root {
  color-scheme: dark;
  --bg: #08090c;
  --surface: #101217;
  --surface-strong: #151922;
  --surface-soft: #1b202a;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text: #f3f5f9;
  --muted: #9ca6b6;
  --subtle: #707a8b;
  --accent: #ff5d62;
  --accent-soft: rgba(255, 93, 98, 0.16);
  --accent-border: rgba(255, 93, 98, 0.46);
  --good: #48d597;
  --warn: #ffd166;
  --page-bg: linear-gradient(135deg, #08090c 0%, #11141b 52%, #08090c 100%);
  --shell-bg: rgba(16, 18, 23, 0.86);
  --titlebar-bg: rgba(255, 255, 255, 0.015);
  --side-bg: rgba(255, 255, 255, 0.025);
  --mode-bg: rgba(255, 255, 255, 0.035);
  --control-bg: rgba(255, 255, 255, 0.055);
  --control-hover-bg: rgba(255, 255, 255, 0.08);
  --pill-bg: rgba(255, 255, 255, 0.04);
  --input-bg: rgba(0, 0, 0, 0.22);
  --panel-bg: rgba(10, 11, 15, 0.36);
  --ring-track: rgba(255, 255, 255, 0.08);
  --dot-bg: rgba(255, 255, 255, 0.14);
  --placeholder: #687284;
  --toggle-bg: rgba(255, 255, 255, 0.1);
  --primary-text: #12080a;
  --logo-shadow: 0 10px 20px rgba(0, 0, 0, 0.24);
  --radius: 8px;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  --progress: 0;
}

/* Light theme overrides */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-strong: #f8f9fc;
  --surface-soft: #eef2f8;
  --border: rgba(17, 19, 26, 0.1);
  --border-strong: rgba(17, 19, 26, 0.18);
  --text: #11131a;
  --muted: #5d6674;
  --subtle: #778191;
  --page-bg: linear-gradient(135deg, #f7f8fb 0%, #e9eef7 52%, #fbfcff 100%);
  --shell-bg: rgba(255, 255, 255, 0.9);
  --titlebar-bg: rgba(255, 255, 255, 0.44);
  --side-bg: rgba(255, 255, 255, 0.38);
  --mode-bg: rgba(17, 19, 26, 0.045);
  --control-bg: rgba(17, 19, 26, 0.055);
  --control-hover-bg: rgba(17, 19, 26, 0.085);
  --pill-bg: rgba(17, 19, 26, 0.045);
  --input-bg: rgba(255, 255, 255, 0.72);
  --panel-bg: rgba(255, 255, 255, 0.58);
  --ring-track: rgba(17, 19, 26, 0.1);
  --dot-bg: rgba(17, 19, 26, 0.18);
  --placeholder: #8a93a3;
  --toggle-bg: rgba(17, 19, 26, 0.12);
  --logo-shadow: 0 10px 20px rgba(17, 19, 26, 0.18);
  --shadow: 0 28px 70px rgba(42, 51, 68, 0.18);
}

/* Base elements */
* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: var(--page-bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* App shell */
.shell {
  width: min(1080px, 100%);
  min-height: min(720px, calc(100vh - 36px));
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--shell-bg);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(28px) saturate(130%);
  backdrop-filter: blur(28px) saturate(130%);
  overflow: hidden;
}

/* Title bar */
.titlebar {
  min-height: 82px;
  display: grid;
  grid-template-columns: 84px 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--titlebar-bg);
}

/* Decorative macOS-style window controls */
.traffic-lights {
  display: flex;
  gap: 8px;
  align-items: center;
}

.light {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.light-close {
  background: #ff5f57;
}

.light-minimize {
  background: #febc2e;
}

.light-maximize {
  background: #28c840;
}

/* App identity */
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  filter: drop-shadow(var(--logo-shadow));
}

.eyebrow,
.metric-label {
  margin: 0;
  color: var(--subtle);
  font-size: 0.76rem;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 2px 0 0;
  font-size: 1.08rem;
  line-height: 1.2;
  font-weight: 680;
}

/* Header actions */
.status-pill {
  margin: 0;
  justify-self: end;
  min-width: 82px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.2;
  text-align: center;
}

.title-actions {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 10px;
  min-width: 0;
}

.theme-button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--control-bg);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 650;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

.theme-button:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: var(--control-hover-bg);
}

.theme-button:active {
  transform: translateY(0);
}

/* Main layout */
.timer-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 336px;
  min-height: calc(min(720px, 100vh - 36px) - 82px);
}

.timer-stage {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  place-items: center;
  gap: 24px;
  min-width: 0;
  padding: 32px clamp(22px, 5vw, 54px);
}

/* Mode tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(480px, 100%);
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--mode-bg);
}

.mode-tab {
  min-height: 42px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.1;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.mode-tab.is-active {
  background: var(--surface-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}

/* Timer ring */
.ring-wrap {
  position: relative;
  width: min(410px, 82vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.progress-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  filter: drop-shadow(0 26px 52px rgba(0, 0, 0, 0.28));
}

.ring-track,
.ring-progress {
  fill: none;
  stroke-width: 11;
}

.ring-track {
  stroke: var(--ring-track);
}

.ring-progress {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: calc(1 - var(--progress));
  transition: stroke-dashoffset 220ms linear, stroke 220ms ease;
}

.time-readout {
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
}

.time-readout p,
.time-readout span {
  margin: 0;
  color: var(--muted);
}

.time-readout p {
  font-size: 0.95rem;
  font-weight: 650;
}

.time-readout strong {
  font-variant-numeric: tabular-nums;
  font-size: clamp(4rem, 12vw, 6.7rem);
  line-height: 0.95;
  font-weight: 760;
}

.time-readout span {
  font-size: 0.92rem;
}

/* Timer controls and cycle dots */
.controls {
  display: grid;
  grid-template-columns: minmax(118px, 1fr) minmax(96px, 0.7fr) minmax(96px, 0.7fr);
  gap: 10px;
  width: min(430px, 100%);
}

.control-button,
.utility-button {
  min-height: 46px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--control-bg);
  color: var(--text);
  font-weight: 650;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

.control-button:hover,
.utility-button:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: var(--control-hover-bg);
}

.control-button:active,
.utility-button:active {
  transform: translateY(0);
}

.control-button.primary {
  border-color: var(--accent-border);
  background: var(--accent);
  color: var(--primary-text);
}

.session-row {
  display: flex;
  gap: 9px;
  align-items: center;
  justify-content: center;
  min-height: 20px;
}

.cycle-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--dot-bg);
  transition: transform 160ms ease, background 160ms ease;
}

.cycle-dot.is-done {
  background: var(--accent);
}

.cycle-dot.is-current {
  background: var(--text);
  transform: scale(1.2);
}

/* Side panel */
.side-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  min-width: 0;
  padding: 16px 22px;
  border-left: 1px solid var(--border);
  background: var(--side-bg);
}

.task-field {
  display: grid;
  gap: 8px;
}

/* Form fields */
.task-field span,
.setting-row label,
.toggle-row span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.task-field input,
.setting-row input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
}

.task-field input {
  padding: 0 12px;
}

.task-field input::placeholder {
  color: var(--placeholder);
}

/* Panels and settings */
.panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-bg);
}

.panel strong {
  display: block;
  margin-top: 4px;
  font-size: 1.06rem;
  line-height: 1.25;
}

.settings {
  gap: 10px;
}

.setting-row {
  display: grid;
  grid-template-columns: 1fr 78px;
  gap: 12px;
  align-items: center;
}

.setting-row input {
  padding: 0 8px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Toggle switches */
.preferences {
  gap: 12px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 34px;
}

.toggle-row input {
  appearance: none;
  width: 44px;
  height: 26px;
  position: relative;
  flex: 0 0 auto;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--toggle-bg);
  transition: background 160ms ease, border-color 160ms ease;
}

.toggle-row input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #f6f8fb;
  transition: transform 160ms ease;
}

.toggle-row input:checked {
  border-color: var(--accent-border);
  background: var(--accent);
}

.toggle-row input:checked::after {
  transform: translateX(18px);
}

/* Utility buttons */
.utility-button {
  width: 100%;
}

.utility-button.subtle {
  min-height: 42px;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
}

.utility-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.utility-button:disabled:hover {
  transform: none;
  border-color: var(--border);
  background: var(--control-bg);
}

.utility-button.subtle:disabled:hover {
  background: transparent;
}

/* Mode and running states */
body[data-mode="short"] {
  --accent: #48d597;
  --accent-soft: rgba(72, 213, 151, 0.16);
  --accent-border: rgba(72, 213, 151, 0.46);
}

body[data-mode="long"] {
  --accent: #7aa7ff;
  --accent-soft: rgba(122, 167, 255, 0.16);
  --accent-border: rgba(122, 167, 255, 0.46);
}

body.is-running .shell {
  border-color: var(--accent-border);
}

body.is-running .status-pill {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

/* Tablet and narrow desktop layout */
@media (max-width: 860px) {
  body {
    align-items: start;
    padding: 0;
  }

  .shell {
    min-height: 100vh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .titlebar {
    grid-template-columns: 1fr auto;
  }

  .traffic-lights {
    display: none;
  }

  .timer-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .timer-stage {
    min-height: 560px;
    padding: 24px 18px;
  }

  .side-panel {
    border-top: 1px solid var(--border);
    border-left: 0;
    padding: 20px 18px 28px;
  }
}

/* Phone layout */
@media (max-width: 520px) {
  .titlebar {
    gap: 12px;
    padding: 16px;
  }

  .brand-mark {
    display: none;
  }

  .status-pill {
    min-width: 72px;
    padding: 7px 8px;
  }

  .mode-tab {
    min-height: 40px;
    font-size: 0.82rem;
  }

  .timer-stage {
    min-height: 510px;
    gap: 18px;
  }

  .ring-wrap {
    width: min(330px, 90vw);
  }

  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .control-button.primary {
    grid-column: span 2;
  }
}

/* Respect users who prefer less animation */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
