:root {
  color-scheme: dark;
  --bg: #05395a;
  --bg-deep: #021d31;
  --surface: rgba(255, 255, 255, 0.12);
  --surface-strong: rgba(255, 255, 255, 0.18);
  --surface-soft: rgba(255, 255, 255, 0.08);
  --accent: #149cff;
  --accent-strong: #54c8ff;
  --accent-soft: rgba(20, 156, 255, 0.28);
  --text: #f7fbff;
  --muted: rgba(235, 247, 255, 0.78);
  --muted-strong: rgba(235, 247, 255, 0.9);
  --shadow: rgba(0, 13, 25, 0.42);
  --button-shadow: rgba(3, 31, 54, 0.45);
  --focus: #ffffff;
  --danger: #ff7474;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --font: ui-rounded, "SF Pro Rounded", "SF Pro Display", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="forest"] {
  --bg: #0a332b;
  --bg-deep: #031d19;
  --surface: rgba(220, 255, 239, 0.12);
  --surface-strong: rgba(220, 255, 239, 0.18);
  --surface-soft: rgba(220, 255, 239, 0.08);
  --accent: #1fd18a;
  --accent-strong: #7ff2bc;
  --accent-soft: rgba(31, 209, 138, 0.26);
  --shadow: rgba(0, 22, 17, 0.5);
  --button-shadow: rgba(0, 32, 24, 0.5);
}

:root[data-theme="sunset"] {
  --bg: #2a183d;
  --bg-deep: #160c25;
  --surface: rgba(255, 232, 210, 0.12);
  --surface-strong: rgba(255, 232, 210, 0.18);
  --surface-soft: rgba(255, 232, 210, 0.08);
  --accent: #ff9b3d;
  --accent-strong: #ffd06b;
  --accent-soft: rgba(255, 155, 61, 0.26);
  --shadow: rgba(14, 6, 23, 0.55);
  --button-shadow: rgba(19, 9, 32, 0.48);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font);
  letter-spacing: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
}

button {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  overflow: hidden;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  transition: background 420ms var(--ease), color 420ms var(--ease);
}

.timer-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr) auto auto auto;
  gap: clamp(12px, 2.1svh, 24px);
  padding:
    calc(18px + var(--safe-top))
    calc(18px + var(--safe-right))
    calc(16px + var(--safe-bottom))
    calc(18px + var(--safe-left));
}

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

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.icon-button,
.round-button,
.play-button,
.pill-button,
.quick-button,
.choice-button {
  background: var(--surface);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 16px 34px var(--button-shadow);
  transition:
    transform 180ms var(--ease),
    background 220ms var(--ease),
    box-shadow 220ms var(--ease),
    opacity 220ms var(--ease);
}

.icon-button {
  width: 58px;
  height: 58px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
}

.icon-button svg,
.round-button svg,
.play-button svg,
.pill-button svg,
.panel-close svg {
  display: block;
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:active,
.round-button:active,
.play-button:active,
.pill-button:active,
.quick-button:active,
.choice-button:active {
  transform: scale(0.96);
}

.remaining-time {
  flex: 1 1 auto;
  text-align: right;
  font-size: clamp(2.35rem, 13vw, 4.35rem);
  font-weight: 850;
  line-height: 1;
  color: var(--text);
  text-shadow: 0 8px 24px var(--shadow);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dial-section {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: clamp(4px, 1.2svh, 18px) 0 clamp(26px, 4svh, 40px);
}

.dial-wrap {
  position: relative;
  width: min(86vw, 510px, 56svh);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 24px 42px rgba(0, 0, 0, 0.18));
}

.dial-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  touch-action: none;
  shape-rendering: geometricPrecision;
  cursor: grab;
}

.dial-svg:active {
  cursor: grabbing;
}

.tick {
  stroke: rgba(255, 255, 255, 0.93);
  stroke-width: 5;
  stroke-linecap: round;
}

.tick.major {
  stroke-width: 12;
}

.minute-label {
  fill: var(--muted-strong);
  font-size: 62px;
  font-weight: 850;
  line-height: 1;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.06);
  stroke-width: 3;
  stroke-linejoin: round;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.dial-hit-zone {
  fill: transparent;
  stroke: transparent;
  pointer-events: all;
}

.wedge {
  fill: var(--accent);
  opacity: 0.96;
  filter: url("#wedgeGlow");
  transition: fill 320ms var(--ease);
}

.wedge-edge {
  stroke: rgba(255, 255, 255, 0.16);
  stroke-width: 2;
  fill: none;
  pointer-events: none;
}

.dial-center-shadow {
  fill: rgba(0, 0, 0, 0.16);
  filter: blur(9px);
}

.center-cap {
  fill: #ffffff;
  filter: url("#handShadow");
}

.center-dot {
  fill: #0f51d8;
  transition: fill 320ms var(--ease);
}

:root[data-theme="forest"] .center-dot {
  fill: #087a52;
}

:root[data-theme="sunset"] .center-dot {
  fill: #d55a20;
}

.drag-thumb {
  fill: rgba(255, 255, 255, 0.9);
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 4;
  filter: url("#thumbGlow");
  opacity: 0.84;
  transition: opacity 160ms var(--ease);
}

.app.dragging .drag-thumb,
.dial-svg:focus-visible .drag-thumb {
  opacity: 1;
}

.quick-row {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.quick-button {
  height: 48px;
  border-radius: 16px;
  color: var(--text);
  font-size: clamp(0.92rem, 3.8vw, 1.05rem);
  font-weight: 800;
  white-space: nowrap;
}

.transport {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  gap: clamp(18px, 7vw, 46px);
  padding: 2px 0 clamp(4px, 1.2svh, 8px);
}

.round-button {
  width: clamp(60px, 18vw, 76px);
  height: clamp(60px, 18vw, 76px);
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: rgba(238, 247, 255, 0.68);
}

.round-button svg {
  width: 34px;
  height: 34px;
  fill: currentColor;
  stroke: none;
}

.play-button {
  width: clamp(112px, 31vw, 138px);
  height: clamp(112px, 31vw, 138px);
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: rgba(247, 251, 255, 0.82);
  background: color-mix(in srgb, var(--surface) 72%, var(--accent-soft));
  box-shadow:
    inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent),
    0 24px 46px var(--button-shadow);
}

.play-button svg {
  width: 64px;
  height: 64px;
  fill: currentColor;
  stroke: none;
  transform: translateX(3px);
}

.play-button .pause-icon {
  display: none;
  transform: translateX(0);
}

.app.running .play-button .play-icon {
  display: none;
}

.app.running .play-button .pause-icon {
  display: block;
}

.bottom-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: center;
  padding-top: clamp(8px, 1.2svh, 16px);
}

.pill-button {
  height: clamp(58px, 12vw, 68px);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 8px;
  padding: 0 14px;
  border-radius: 999px;
  text-align: left;
  color: var(--muted-strong);
  overflow: hidden;
}

.pill-button svg {
  grid-row: 1 / 3;
  width: 25px;
  height: 25px;
  stroke-width: 2.9;
}

.pill-title {
  min-width: 0;
  font-size: clamp(0.9rem, 3.35vw, 1.12rem);
  font-weight: 850;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill-state {
  min-width: 0;
  margin-top: 3px;
  color: rgba(235, 247, 255, 0.62);
  font-size: 0.72rem;
  font-weight: 750;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  align-items: end;
  padding: 18px calc(18px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(18px + var(--safe-left));
  background: rgba(0, 8, 15, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms var(--ease);
}

.panel-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

.settings-panel {
  width: min(100%, 540px);
  margin: 0 auto;
  padding: 16px;
  border-radius: 28px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 76%, #111 24%);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  transform: translateY(18px) scale(0.98);
  transition: transform 240ms var(--ease);
}

.panel-backdrop.open .settings-panel {
  transform: translateY(0) scale(1);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-title {
  margin: 0;
  font-size: 1.16rem;
  font-weight: 850;
  line-height: 1.1;
  color: var(--text);
}

.panel-close {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.choice-button {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  border-radius: 18px;
  padding: 10px 14px;
  color: var(--text);
  text-align: left;
}

.choice-button[aria-pressed="true"] {
  background: var(--surface-strong);
  box-shadow:
    inset 0 0 0 2px var(--accent),
    0 16px 34px var(--button-shadow);
  background: color-mix(in srgb, var(--accent) 32%, var(--surface));
  box-shadow:
    inset 0 0 0 2px color-mix(in srgb, var(--accent-strong) 70%, transparent),
    0 16px 34px var(--button-shadow);
}

.choice-main {
  display: block;
  min-width: 0;
  font-size: 1rem;
  font-weight: 850;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.choice-sub {
  display: block;
  margin-top: 2px;
  color: rgba(235, 247, 255, 0.66);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.choice-swatch {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.22);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-bottom));
  z-index: 20;
  max-width: calc(100vw - 36px);
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.48);
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 800;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.app.complete .dial-wrap {
  animation: completionPulse 960ms var(--ease);
}

@keyframes completionPulse {
  0% { transform: scale(1); filter: drop-shadow(0 24px 42px rgba(0, 0, 0, 0.18)); }
  34% { transform: scale(1.025); filter: drop-shadow(0 0 34px var(--accent-soft)); }
  100% { transform: scale(1); filter: drop-shadow(0 24px 42px rgba(0, 0, 0, 0.18)); }
}

@media (hover: hover) {
  .icon-button:hover,
  .round-button:hover,
  .play-button:hover,
  .pill-button:hover,
  .quick-button:hover,
  .choice-button:hover {
    background: var(--surface-strong);
  }
}

@media (max-width: 380px) {
  .timer-shell {
    padding-left: calc(12px + var(--safe-left));
    padding-right: calc(12px + var(--safe-right));
    gap: 10px;
  }

  .top-actions {
    gap: 8px;
  }

  .icon-button {
    width: 52px;
    height: 52px;
  }

  .bottom-actions {
    gap: 8px;
  }

  .pill-button {
    padding: 0 12px;
    column-gap: 8px;
  }

  .pill-button svg {
    width: 22px;
    height: 22px;
  }
}

@media (max-height: 720px) {
  .timer-shell {
    grid-template-rows: auto minmax(250px, 1fr) auto auto auto;
    gap: 9px;
  }

  .topbar {
    min-height: 62px;
  }

  .dial-wrap {
    width: min(84vw, 450px, 51svh);
  }

  .play-button {
    width: 96px;
    height: 96px;
  }

  .play-button svg {
    width: 54px;
    height: 54px;
  }

  .round-button {
    width: 56px;
    height: 56px;
  }

  .quick-button {
    height: 44px;
  }
}

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