:root {
  color-scheme: light;
  --ink: #1f302c;
  --muted: #65736f;
  --paper: #f7f4ec;
  --panel: rgba(255, 252, 244, 0.82);
  --panel-solid: #fffcf4;
  --line: rgba(34, 55, 50, 0.16);
  --teal: #2d6f68;
  --teal-deep: #174d4a;
  --sage: #8ca685;
  --clay: #bd7458;
  --gold: #d7a24a;
  --leaf: #4f7b4f;
  --shadow: 0 24px 80px rgba(31, 48, 44, 0.16);
  --ring-size: 326.73;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(145deg, rgba(45, 111, 104, 0.16), transparent 34%),
    linear-gradient(335deg, rgba(189, 116, 88, 0.13), transparent 42%),
    var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  padding: clamp(18px, 3vw, 42px);
  gap: clamp(18px, 3vw, 42px);
}

.panel-toolbar {
  grid-column: 1 / -1;
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  width: min(100%, 330px);
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: 0 12px 36px rgba(31, 48, 44, 0.1);
  backdrop-filter: blur(14px);
}

.panel-view-button {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.panel-view-button.active {
  color: #fff;
  background: var(--teal-deep);
}

.app-shell.controls-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.controls-collapsed .session-panel {
  display: none;
}

.app-shell.controls-collapsed .visual-stage {
  grid-column: 1 / -1;
}

.app-shell.visual-collapsed {
  grid-template-columns: minmax(320px, 520px);
  justify-content: center;
}

.app-shell.visual-collapsed .session-panel {
  grid-column: 1 / -1;
  width: min(100%, 520px);
  justify-self: center;
}

.app-shell.visual-collapsed .visual-stage {
  display: none;
}

.session-panel {
  grid-row: 2;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: min(760px, calc(100vh - clamp(36px, 6vw, 84px)));
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-row,
.duration-label,
.action-row,
.duration-marks {
  display: flex;
  align-items: center;
}

.brand-row {
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin: 0;
  color: var(--teal-deep);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(100%, 300px);
  min-width: min(252px, 100%);
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.5);
}

.mode-button {
  min-height: 36px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.mode-button.active {
  color: #fff;
  background: var(--teal);
  box-shadow: 0 8px 20px rgba(45, 111, 104, 0.2);
}

.timer-block {
  position: relative;
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 300px;
  padding: 42px 0;
  text-align: center;
}

.second-pulse {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 58px;
  aspect-ratio: 1;
  border-radius: 8px;
  background: rgba(45, 111, 104, 0.08);
  box-shadow: inset 0 0 0 1px rgba(45, 111, 104, 0.12);
}

.pulse-shape {
  display: block;
  width: 34px;
  aspect-ratio: 1;
  border-radius: 5px;
  opacity: 0.62;
  background: var(--clay);
  box-shadow:
    inset 0 0 0 2px rgba(255, 252, 244, 0.72),
    0 8px 22px rgba(31, 48, 44, 0.12);
}

.app-shell.session-running .pulse-shape {
  animation:
    quarterComplete 4s step-end infinite,
    pulseFade 1s ease-in-out infinite alternate;
}

@keyframes pulseFade {
  from {
    opacity: 0.42;
  }

  to {
    opacity: 1;
  }
}

@keyframes quarterComplete {
  0%,
  24.99% {
    background: conic-gradient(var(--clay) 0 90deg, rgba(45, 111, 104, 0.14) 90deg 360deg);
  }

  25%,
  49.99% {
    background: conic-gradient(var(--clay) 0 180deg, rgba(45, 111, 104, 0.14) 180deg 360deg);
  }

  50%,
  74.99% {
    background: conic-gradient(var(--clay) 0 270deg, rgba(45, 111, 104, 0.14) 270deg 360deg);
  }

  75%,
  100% {
    background: var(--clay);
  }
}

.progress-ring {
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(80vw, 310px);
  aspect-ratio: 1;
  translate: -50% -50%;
  pointer-events: none;
  opacity: 0.58;
}

.progress-ring svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  rotate: -90deg;
}

.progress-ring circle {
  fill: none;
  stroke-width: 4;
}

.ring-track {
  stroke: rgba(45, 111, 104, 0.14);
}

.ring-fill {
  stroke: var(--clay);
  stroke-linecap: round;
  stroke-dasharray: var(--ring-size);
  stroke-dashoffset: var(--ring-size);
  transition: stroke-dashoffset 0.4s ease;
}

.duration-control {
  display: grid;
  gap: 13px;
}

.duration-label {
  justify-content: space-between;
  gap: 18px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

#durationOutput {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 36px;
  margin: 0;
  appearance: none;
  background: transparent;
}

input[type="range"]:disabled {
  cursor: default;
  opacity: 0.56;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--sage), var(--gold));
}

input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--sage), var(--gold));
}

input[type="range"]::-webkit-slider-thumb {
  width: 24px;
  height: 24px;
  margin-top: -8px;
  border: 4px solid var(--panel-solid);
  border-radius: 50%;
  appearance: none;
  background: var(--teal-deep);
  box-shadow: 0 8px 22px rgba(31, 48, 44, 0.22);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 4px solid var(--panel-solid);
  border-radius: 50%;
  background: var(--teal-deep);
  box-shadow: 0 8px 22px rgba(31, 48, 44, 0.22);
}

.duration-marks {
  justify-content: space-between;
  color: rgba(31, 48, 44, 0.56);
  font-size: 0.76rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.action-row {
  gap: 12px;
  margin-top: 34px;
}

.primary-action,
.ghost-action {
  min-height: 54px;
  border-radius: 999px;
  font-weight: 800;
}

.primary-action {
  flex: 1 1 auto;
  color: #fff;
  background: var(--teal-deep);
  box-shadow: 0 16px 32px rgba(23, 77, 74, 0.24);
}

.ghost-action {
  flex: 0 0 110px;
  color: var(--teal-deep);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.54);
}

.primary-action:hover,
.primary-action:focus-visible {
  background: #103f3d;
}

.ghost-action:hover,
.ghost-action:focus-visible,
.mode-button:focus-visible,
.panel-view-button:focus-visible,
input[type="range"]:focus-visible {
  outline: 3px solid rgba(45, 111, 104, 0.22);
  outline-offset: 3px;
}

.visual-stage {
  grid-row: 2;
  position: relative;
  min-height: min(760px, calc(100vh - clamp(36px, 6vw, 84px)));
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 252, 244, 0.48), rgba(255, 252, 244, 0.08)),
    #dce8df;
  box-shadow: inset 0 0 0 1px rgba(34, 55, 50, 0.13);
  isolation: isolate;
}

#meditationCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.visual-stage::after {
  position: absolute;
  inset: auto 0 0;
  height: 32%;
  content: "";
  background: linear-gradient(0deg, rgba(31, 48, 44, 0.18), transparent);
  pointer-events: none;
  z-index: 1;
}

.ambient-text {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  color: rgba(255, 252, 244, 0.78);
  font-size: clamp(2.4rem, 8vw, 7rem);
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
  pointer-events: none;
}

.ambient-text span {
  position: absolute;
  opacity: 0;
  animation: breatheWord 12s ease-in-out infinite;
  text-shadow: 0 10px 42px rgba(31, 48, 44, 0.22);
}

.ambient-text span + span {
  animation-delay: 6s;
}

@keyframes breatheWord {
  0%,
  100% {
    opacity: 0;
    scale: 0.94;
  }

  18%,
  45% {
    opacity: 0.9;
    scale: 1;
  }

  62% {
    opacity: 0;
    scale: 1.05;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .app-shell.visual-collapsed {
    grid-template-columns: 1fr;
  }

  .session-panel,
  .visual-stage {
    min-height: auto;
  }

  .session-panel {
    gap: 34px;
  }

  .visual-stage {
    min-height: 48vh;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 14px;
    gap: 14px;
  }

  .session-panel {
    padding: 18px;
  }

  .brand-row {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-switch {
    width: 100%;
  }

  .action-row {
    flex-direction: column;
  }

  .primary-action,
  .ghost-action {
    width: 100%;
    flex-basis: auto;
  }

  .timer-block {
    padding: 30px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ambient-text span {
    animation: none;
  }

  .ambient-text span:first-child {
    opacity: 0.82;
  }
}
