:root {
  --navy: #0c2340;
  --navy-soft: #173c66;
  --emerald: #0d5c3a;
  --emerald-bright: #13754d;
  --amber: #a84408;
  --cream: #faf5eb;
  --surface: #ffffff;
  --ink: #10213a;
  --muted: #405774;
  --border: rgba(12, 35, 64, 0.14);
  --border-strong: rgba(12, 35, 64, 0.28);
  --ring-track: #d9e2e8;
  --timer-face: #0c2340;
  --timer-label: #c4d8e9;
  --timer-muted: #d8e8f4;
  --shadow: 0 24px 65px -34px rgba(12, 35, 64, 0.38);
  --radius-lg: 28px;
  --radius-md: 16px;
  --font-display: "Outfit", sans-serif;
  --font-body: "Inter", sans-serif;
  --transition-fast: 180ms ease;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  min-width: 0;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 16%, rgba(19, 117, 77, 0.14), transparent 24rem),
    radial-gradient(circle at 88% 86%, rgba(180, 83, 9, 0.11), transparent 26rem),
    var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}

button, input { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: inherit; }

:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: -5rem;
  left: 1rem;
  z-index: 20;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  background: var(--navy);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  transition: top var(--transition-fast);
}
.skip-link:focus { top: 1rem; }

.background-orb {
  position: fixed;
  z-index: -1;
  width: 24rem;
  height: 24rem;
  border-radius: 50%;
  filter: blur(72px);
  opacity: 0.2;
  pointer-events: none;
}
.orb-one { top: -12rem; left: -11rem; background: #4eae7c; }
.orb-two { right: -11rem; bottom: -13rem; background: #df9c53; }

.app-shell {
  width: min(100% - 2rem, 1120px);
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.app-header {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--navy);
  text-decoration: none;
}
.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--navy), var(--emerald));
  color: #fff;
  box-shadow: 0 8px 18px rgba(12, 35, 64, 0.2);
}
.brand-mark svg { width: 27px; height: 27px; }
.brand strong, .brand small { display: block; }
.brand strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.035em;
  line-height: 1.1;
}
.brand small {
  margin-top: 0.18rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.back-link {
  min-height: 44px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  text-underline-offset: 3px;
}
.back-link:hover { color: var(--navy); }
.back-link-compact { display: none; }

.timer-layout {
  flex: 1;
  display: grid;
  align-items: center;
  gap: clamp(2rem, 5vw, 4.5rem);
  padding: clamp(2rem, 6vw, 5.5rem) 0;
}

.timer-intro { min-width: 0; }
.eyebrow {
  margin: 0 0 0.65rem;
  color: var(--emerald);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
}
h1, legend { font-family: var(--font-display); }
h1 {
  max-width: 10ch;
  margin: 0;
  color: var(--navy);
  font-size: clamp(2.55rem, 6vw, 4.65rem);
  font-weight: 800;
  letter-spacing: -0.05em;
  line-height: 0.98;
  text-wrap: balance;
}
.timer-intro > p:not(.eyebrow) {
  max-width: 34rem;
  margin: 1.25rem 0 0;
  color: var(--muted);
  font-size: 1.03rem;
}

.feature-list {
  display: grid;
  gap: 0.7rem;
  margin: 1.6rem 0 0;
  padding: 0;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
  list-style: none;
}
.feature-list li { display: flex; align-items: center; gap: 0.6rem; }
.feature-list svg { width: 20px; height: 20px; flex: 0 0 auto; color: var(--emerald); }

.timer-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1.15rem, 3vw, 2rem);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: var(--shadow);
}

.timer-progress {
  width: min(100%, 400px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin: 0 auto;
  padding: clamp(0.65rem, 2.5vw, 0.9rem);
  border-radius: 50%;
  background: conic-gradient(from -90deg, var(--emerald) calc(var(--progress) * 1turn), var(--ring-track) 0);
  box-shadow: inset 0 0 0 1px rgba(12, 35, 64, 0.1), 0 16px 36px -25px rgba(12, 35, 64, 0.52);
}
.timer-progress.is-finished { background: conic-gradient(from -90deg, var(--amber) 0, var(--amber) 1turn); }
.timer-face {
  width: 100%;
  height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  border-radius: 50%;
  padding: 1.4rem;
  background: radial-gradient(circle at 30% 22%, var(--navy-soft), var(--timer-face) 68%);
  color: #fff;
  text-align: center;
}
.timer-label {
  margin: 0;
  color: var(--timer-label);
  font-size: clamp(0.64rem, 1.8vw, 0.76rem);
  font-weight: 800;
  letter-spacing: 0.14em;
}
.timer-display {
  display: block;
  margin: 0.3rem 0;
  color: #fff;
  font-family: var(--font-display);
  font-size: clamp(3.35rem, 13vw, 6.45rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.07em;
  line-height: 0.95;
}
.timer-state {
  min-height: 1.5rem;
  max-width: 15rem;
  margin: 0;
  color: var(--timer-muted);
  font-size: clamp(0.78rem, 2vw, 0.9rem);
}

.controls-section { margin-top: 1.4rem; }
.presets { margin: 0; padding: 0; border: 0; }
legend, .custom-time label {
  display: block;
  margin: 0 0 0.55rem;
  color: var(--navy);
  font-size: 1rem;
  font-weight: 700;
}
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}
.preset-button, .set-button, .start-button, .reset-button, .sound-button {
  min-height: 48px;
  border: 1px solid transparent;
  font-weight: 800;
  transition: transform var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), color var(--transition-fast);
}
.preset-button {
  border-color: var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--navy);
  font-size: 0.9rem;
}
.preset-button:hover, .preset-button.is-selected {
  border-color: var(--emerald);
  background: color-mix(in srgb, var(--emerald) 11%, var(--surface));
  color: var(--emerald);
}
.preset-button.is-selected { box-shadow: inset 0 0 0 1px var(--emerald); }

.custom-time { margin-top: 1rem; }
.custom-time-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.6rem; }
#custom-minutes {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  background: var(--surface);
  color: var(--ink);
}
#custom-minutes:focus { outline: none; border-color: var(--emerald); box-shadow: 0 0 0 3px color-mix(in srgb, var(--emerald) 18%, transparent); }
#custom-minutes[aria-invalid="true"] { border-color: #a84408; }
.set-button {
  padding: 0.7rem 1rem;
  border-radius: 12px;
  background: var(--navy);
  color: #fff;
  white-space: nowrap;
}
.set-button:hover { background: var(--navy-soft); }
.custom-help, .custom-message { min-height: 1.25rem; margin: 0.45rem 0 0; font-size: 0.79rem; }
.custom-help { color: var(--muted); }
.custom-message { color: #913b08; font-weight: 700; }

.primary-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.6rem; margin-top: 1.3rem; }
.start-button, .reset-button, .sound-button { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; }
.start-button {
  border-radius: 14px;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, var(--emerald), var(--emerald-bright));
  box-shadow: 0 12px 22px -14px rgba(13, 92, 58, 0.72);
  color: #fff;
}
.start-button:hover { transform: translateY(-2px); box-shadow: 0 16px 25px -14px rgba(13, 92, 58, 0.78); }
.start-button.is-running { background: linear-gradient(135deg, var(--navy), var(--navy-soft)); }
.start-button.is-running .play-icon, .pause-icon { display: none; }
.start-button.is-running .pause-icon { display: block; }
.reset-button {
  border-color: var(--border-strong);
  border-radius: 14px;
  padding: 0.75rem 0.95rem;
  background: var(--surface);
  color: var(--navy);
}
.reset-button:hover, .sound-button:hover { border-color: var(--emerald); background: color-mix(in srgb, var(--emerald) 8%, var(--surface)); }
.button-icon { width: 20px; height: 20px; flex: 0 0 auto; }

.sound-button {
  width: 100%;
  min-height: 44px;
  margin-top: 0.9rem;
  border-color: var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 0.86rem;
}
.sound-button .sound-on-icon { display: none; }
.sound-button.is-on { border-color: color-mix(in srgb, var(--emerald) 50%, var(--border)); color: var(--emerald); }
.sound-button.is-on .sound-on-icon { display: block; }
.sound-button.is-on .sound-off-icon { display: none; }

.preset-button:active, .set-button:active, .start-button:active, .reset-button:active, .sound-button:active { transform: translateY(1px); }

.app-footer {
  padding: 1.5rem 0 2rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.84rem;
  text-align: center;
}
.app-footer p { margin: 0 0 0.35rem; }
.app-footer nav { line-height: 1.9; }
.app-footer a { color: var(--navy); font-weight: 700; text-underline-offset: 2px; }
.app-footer span { margin: 0 0.18rem; color: #94a3b8; }

@media (min-width: 900px) {
  .timer-layout { grid-template-columns: minmax(0, 0.85fr) minmax(390px, 1.15fr); }
}

@media (max-width: 560px) {
  .app-shell { width: min(100% - 1.25rem, 1120px); }
  .app-header { min-height: 74px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 11px; }
  .brand strong { font-size: 0.91rem; }
  .brand small { font-size: 0.62rem; }
  .back-link { font-size: 0.78rem; }
  .timer-layout { padding: 1.5rem 0 2.5rem; }
  .timer-card { padding: 1rem; border-radius: 22px; }
  .timer-face { padding: 1rem; }
  .custom-time-row { grid-template-columns: 1fr; }
  .set-button { width: 100%; }
}

@media (max-width: 430px) {
  .app-header { gap: 0.55rem; }
  .back-link-full { display: none; }
  .back-link-compact { display: inline; }
}

@media (max-width: 370px) {
  .brand { gap: 0.5rem; }
  .brand strong { font-size: 0.81rem; }
  .back-link { font-size: 0.7rem; }
  .timer-display { font-size: 3.05rem; }
  .preset-button { font-size: 0.82rem; }
}

@media (max-height: 580px) and (orientation: landscape) {
  .app-header { min-height: 64px; }
  .timer-layout { align-items: start; padding: 1.5rem 0 2rem; }
  .timer-progress { width: min(100%, 300px); }
  .feature-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

:root[data-theme="dark"] {
  --cream: #08172a;
  --surface: #102841;
  --ink: #f4f7fb;
  --muted: #c3d1df;
  --border: rgba(216, 234, 248, 0.18);
  --border-strong: rgba(216, 234, 248, 0.35);
  --ring-track: #29435e;
  --timer-face: #0a1d33;
  --timer-label: #c4d8e9;
  --timer-muted: #d8e8f4;
  --shadow: 0 24px 65px -34px rgba(0, 0, 0, 0.66);
}
:root[data-theme="dark"] .brand,
:root[data-theme="dark"] h1,
:root[data-theme="dark"] legend,
:root[data-theme="dark"] .custom-time label,
:root[data-theme="dark"] .back-link:hover,
:root[data-theme="dark"] .preset-button,
:root[data-theme="dark"] .reset-button { color: #f4f7fb; }
:root[data-theme="dark"] .preset-button:hover,
:root[data-theme="dark"] .preset-button.is-selected,
:root[data-theme="dark"] .reset-button:hover,
:root[data-theme="dark"] .sound-button:hover { background: rgba(19, 117, 77, 0.22); }
:root[data-theme="dark"] #custom-minutes { color-scheme: dark; }

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