:root {
  color-scheme: dark;
  --bg: #090c0f;
  --bg-soft: #0d1115;
  --surface: #12171c;
  --surface-hover: #171d23;
  --line: #2b3239;
  --line-strong: #3a434c;
  --text: #f4f5f2;
  --muted: #929aa2;
  --accent: #d7f52c;
  --accent-strong: #e5ff4f;
  --danger: #ff756d;
  --radius: 14px;
  --header-height: 82px;
  font-family: Inter, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 35% 40%, rgba(41, 53, 48, 0.16), transparent 35%),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(215, 245, 44, 0.34);
  outline-offset: 3px;
}

.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(24px, 3.5vw, 56px);
  border-bottom: 1px solid var(--line);
}

.brand-title {
  margin: 0;
  line-height: 1;
}

.brand {
  color: var(--text);
  font-size: clamp(18px, 1.7vw, 25px);
  font-weight: 850;
  letter-spacing: -0.045em;
  text-decoration: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 28px;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #c7cbd0;
  font-size: 14px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(215, 245, 44, 0.08);
}

.connection-status.is-offline .status-dot {
  background: #ffbf47;
  box-shadow: 0 0 0 4px rgba(255, 191, 71, 0.08);
}

.header-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 0 8px 28px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-left: 1px solid var(--line-strong);
  font-size: 14px;
}

.header-button svg {
  width: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  min-height: calc(100vh - var(--header-height));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 0;
  overflow-x: clip;
  transition: grid-template-columns 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

.app-shell.settings-open {
  grid-template-columns: minmax(0, 2fr) minmax(340px, 0.9fr);
}

.timer-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(38px, 5vh, 68px) clamp(28px, 5vw, 76px) 24px;
}

.timer-stage {
  position: relative;
  min-height: 440px;
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  isolation: isolate;
}

.timer-orbit {
  position: absolute;
  width: min(69vh, 610px);
  max-width: 90%;
  overflow: visible;
  transform: rotate(-90deg);
  z-index: -1;
}

.orbit-track,
.orbit-progress {
  fill: none;
  stroke-width: 2;
}

.orbit-track {
  stroke: var(--line);
  stroke-dasharray: 2 9;
}

.orbit-progress {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 1683.9;
  stroke-dashoffset: 1683.9;
  filter: drop-shadow(0 0 5px rgba(215, 245, 44, 0.28));
  transition: stroke-dashoffset 0.5s linear;
}

.timer-readout {
  text-align: center;
}

.amount {
  color: var(--accent);
  font-size: clamp(70px, 10vw, 156px);
  font-weight: 760;
  line-height: 0.92;
  letter-spacing: -0.075em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.timer-readout p {
  margin: 24px 0 28px;
  color: #b4bac0;
  font-size: clamp(15px, 1.3vw, 20px);
}

.elapsed {
  display: block;
  font-size: clamp(42px, 5.1vw, 74px);
  line-height: 1;
  letter-spacing: 0.035em;
  font-variant-numeric: tabular-nums;
}

.timer-state {
  display: block;
  margin-top: 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.16em;
}

.timer-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1.35fr) 1fr 1fr;
  gap: 14px;
}

.control-button {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 22px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  font-size: 16px;
  font-weight: 650;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.control-button svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.control-button:not(:disabled):hover {
  background: var(--surface-hover);
  border-color: #59636d;
}

.control-button:not(:disabled):active {
  transform: translateY(1px);
}

.control-button:disabled {
  color: #5f676f;
  border-color: #252b31;
  cursor: not-allowed;
}

.control-primary {
  color: #0b0e10;
  background: var(--accent);
  border-color: var(--accent);
}

.control-primary:not(:disabled):hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.persistence-note {
  margin: 30px 0 0;
  padding-top: 21px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.55;
}

.settings-panel {
  height: 0;
  min-width: 0;
  padding: 0 clamp(28px, 4vw, 58px);
  background: rgba(10, 13, 16, 0.68);
  border-left: 0 solid var(--line);
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transform: translateX(24px);
  visibility: hidden;
  transition:
    opacity 180ms ease,
    transform 320ms cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 320ms;
}

.settings-open .settings-panel {
  height: auto;
  padding-top: clamp(38px, 6vh, 72px);
  padding-bottom: clamp(38px, 6vh, 72px);
  border-left-width: 1px;
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
  visibility: visible;
  transition-delay: 80ms, 0s, 0s;
}

.settings-panel form {
  max-width: 480px;
  margin: 0 auto;
}

.field-group + .field-group {
  margin-top: 38px;
}

.field-group label {
  display: block;
  margin-bottom: 12px;
  font-size: 15px;
  font-weight: 700;
}

.field-group > p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.input-shell,
.stepper,
select {
  width: 100%;
  min-height: 62px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
}

.input-shell {
  display: flex;
  align-items: center;
}

.input-shell:focus-within,
.stepper:focus-within,
select:focus {
  border-color: var(--accent);
}

.input-shell input,
.stepper input {
  min-width: 0;
  height: 60px;
  flex: 1;
  padding: 0 16px;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.input-suffix {
  padding-right: 16px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.stepper {
  display: grid;
  grid-template-columns: 1fr 62px 62px;
  overflow: hidden;
}

.stepper input {
  width: 100%;
  appearance: textfield;
}

.stepper input::-webkit-inner-spin-button {
  appearance: none;
}

.stepper button {
  color: var(--text);
  background: transparent;
  border: 0;
  border-left: 1px solid var(--line);
  font-size: 28px;
}

.stepper button:hover {
  background: var(--surface-hover);
}

select {
  padding: 0 46px 0 16px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 22px) 27px,
    calc(100% - 16px) 27px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  font-size: 19px;
}

.calculation-details {
  margin-top: 34px;
  padding: 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.calculation-details summary {
  color: #c7cbd0;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 20px;
}

.details-grid label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.details-grid input {
  width: 100%;
  height: 46px;
  margin-top: 7px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.formula {
  margin-top: 28px;
}

.formula p,
.formula span {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.formula strong {
  display: block;
  margin: 8px 0;
  color: var(--text);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}

.install-prompt {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  width: min(440px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 16px;
  padding: 18px;
  color: var(--text);
  background: #171c20;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
}

.install-prompt[hidden] {
  display: none;
}

.install-prompt strong,
.install-prompt span {
  display: block;
}

.install-prompt span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.install-prompt button {
  padding: 10px 14px;
  color: #0b0e10;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  font-weight: 750;
}

.install-prompt .install-close {
  padding: 5px;
  color: var(--muted);
  background: transparent;
  font-size: 22px;
}

.metrika-pixel {
  position: absolute;
  left: -9999px;
}

@media (max-width: 980px) {
  :root {
    --header-height: 70px;
  }

  .app-shell {
    display: block;
    overflow: visible;
    transition: none;
  }

  .timer-panel {
    min-height: calc(100vh - var(--header-height));
  }

  .settings-panel {
    height: auto;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-top: 1px solid var(--line);
    border-left: 0;
    opacity: 0;
    transform: translateY(-18px);
    transition:
      max-height 420ms cubic-bezier(0.22, 1, 0.36, 1),
      padding 320ms ease,
      opacity 180ms ease,
      transform 320ms cubic-bezier(0.22, 1, 0.36, 1),
      visibility 0s linear 420ms;
  }

  .settings-open .settings-panel {
    max-height: 1600px;
    padding-top: clamp(38px, 6vh, 72px);
    padding-bottom: clamp(38px, 6vh, 72px);
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0s;
  }

  .settings-panel form {
    max-width: 640px;
  }

  .header-button {
    padding-left: 18px;
  }
}

@media (max-width: 620px) {
  .app-header {
    padding: 0 18px;
  }

  .brand {
    font-size: 21px;
  }

  .connection-status {
    font-size: 12px;
  }

  .header-actions {
    gap: 14px;
  }

  .header-button {
    padding-left: 14px;
  }

  .header-button span {
    display: none;
  }

  .timer-panel {
    min-height: auto;
    padding: 32px 18px 22px;
  }

  .timer-stage {
    min-height: 390px;
  }

  .timer-orbit {
    width: 380px;
    max-width: 112%;
  }

  .amount {
    font-size: clamp(60px, 19vw, 92px);
  }

  .timer-readout p {
    max-width: 260px;
    margin: 18px auto 24px;
    font-size: 14px;
    line-height: 1.45;
  }

  .elapsed {
    font-size: 43px;
  }

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

  .control-button {
    min-height: 64px;
  }

  .control-primary {
    grid-column: 1 / -1;
  }

  .persistence-note {
    margin-top: 22px;
  }

  .settings-panel {
    padding-right: 18px;
    padding-left: 18px;
  }

  .settings-open .settings-panel {
    padding-top: 38px;
    padding-bottom: 54px;
  }

  .field-group + .field-group {
    margin-top: 30px;
  }

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

  .install-prompt {
    right: 16px;
    bottom: 16px;
    grid-template-columns: 1fr auto;
  }

  .install-prompt .install-close {
    position: absolute;
    top: 5px;
    right: 5px;
  }
}

@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;
  }
}
