:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  color: #193c35;
  background: #e8c4a0;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: wait; opacity: .55; }
button:focus-visible { outline: 3px solid #15685a; outline-offset: 4px; }

.game {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #e8c4a0;
  overscroll-behavior: none;
}

.scene {
  position: absolute;
  inset: 0;
  direction: ltr;
  pointer-events: none;
}

.artwork, .art-layer {
  position: absolute;
  inset: 0;
}

.artwork { transform: rotate(var(--rotation, 0deg)); }

.backdrop, .train, .counter-orbit {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.backdrop {
  width: 150vmax;
  aspect-ratio: 1;
  background: var(--art) center / cover;
  filter: blur(42px) saturate(.92);
}

.train {
  width: min(113vw, 113vh);
  height: min(113vw, 113vh);
  background: var(--foreground-art, var(--art)) center / contain no-repeat;
}

.counter-orbit {
  display: grid;
  justify-items: center;
  align-items: start;
  width: min(82vw, 82vh);
  aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(var(--rotation, 0deg));
}

#countdown {
  margin-top: -0.12em;
  display: grid;
  place-items: center;
  width: 1.25em;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #faffee;
  color: #17573c;
  font-size: clamp(3.8rem, 14vmin, 7rem);
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 5px 0 #17573c45, 0 0 0 4px #b6f6b8;
}

.frame {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border: clamp(9px, 2.6vmin, 16px) solid var(--frame, transparent);
  box-shadow: inset 0 0 0 2px #fff4;
  opacity: 0;
  transition: border-color .15s ease;
}

[data-state] .frame { opacity: 1; }
[data-state="far"] { --frame: #ff5061; }
[data-state="close"] { --frame: #ffcf38; }
[data-state="ready"] { --frame: #34d77e; }

.intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 18px 18px max(18px, env(safe-area-inset-bottom));
  overflow: auto;
}

.card {
  width: min(100%, 390px);
  padding: 19px clamp(15px, 6vw, 28px) 13px;
  border: 1px solid #fff9;
  border-radius: 27px;
  background: #fff9ea;
  text-align: center;
  box-shadow: 0 15px 55px #40281729;
}

h1 {
  margin: 0;
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  font-size: clamp(2.1rem, 9vw, 3.1rem);
  line-height: 1;
  font-weight: 950;
  letter-spacing: -.065em;
}

.card p { margin: 10px 0 15px; font-size: 1rem; }
.card h2 { margin: 0; font-size: 2rem; line-height: 1.15; }

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 14px;
  padding: 4px;
  border-radius: 15px;
  background: #eee6d4;
}

.modes button {
  min-height: 44px;
  border: 0;
  border-radius: 11px;
  color: #193c35;
  background: transparent;
  font-weight: 750;
}

.modes [aria-pressed="true"] {
  background: #fffdf4;
  box-shadow: 0 1px 3px #40281726;
}

.primary {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  background: #20594c;
  color: #fff;
  font-size: 1.18rem;
  font-weight: 750;
}

.secondary {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: #3d5e53;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.card .message { margin: 0 0 5px; font-size: .9rem; }

.game-bar {
  position: absolute;
  inset: max(23px, calc(env(safe-area-inset-top) + 10px))
    max(23px, env(safe-area-inset-right)) auto max(23px, env(safe-area-inset-left));
  display: flex;
  align-items: start;
  gap: 8px;
}

.action-hud { display: flex; gap: 8px; margin-inline-start: auto; }

.stat, .change-mode {
  border: 0;
  border-radius: 14px;
  background: #fffaed;
  color: #193c35;
  box-shadow: 0 3px 9px #34271b30;
}

.change-mode { min-height: 44px; padding: 0 12px; font-weight: 700; }

.stat {
  display: grid;
  justify-items: center;
  min-width: 54px;
  padding: 5px 10px;
  font-size: .8rem;
}

.stat [role="timer"], .stat output {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  line-height: 1.15;
}

#clock[data-urgent] { color: #a72330; }

.controls, .hold-phone {
  position: absolute;
  bottom: max(21px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
}

.controls { display: flex; gap: 14px; }
.controls button, .hold-phone {
  border: 0;
  border-radius: 100px;
  background: #fffaed;
  color: #193c35;
  box-shadow: 0 3px 9px #34271b30;
}

.controls button { width: 60px; height: 60px; font-size: 2rem; touch-action: manipulation; }
.hold-phone { margin: 0; padding: 10px 18px; white-space: nowrap; font-weight: 700; }

@media (orientation: landscape) and (min-width: 680px) {
  .game:has(.intro:not([hidden])) .scene { right: 32%; }
  .intro { align-items: safe center; justify-items: start; padding-inline: max(18px, env(safe-area-inset-right)); }
  .card { width: min(40vw, 390px); }
  h1 { font-size: clamp(1.75rem, 4.3vw, 2.5rem); }
}

@media (max-height: 400px) {
  .intro {
    padding-block: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-bottom));
  }

  .card { padding-block: 12px 8px; }
  .modes { margin-top: 9px; }
  .card p { margin-block: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .frame { transition: none; }
}
