:root {
  color-scheme: light;
  --bg: #ede9df;
  --surface: #f8f5ed;
  --surface-strong: #fffdf8;
  --ink: #1d211e;
  --ink-soft: #535b54;
  --line: #c8c3b7;
  --line-strong: #8d9189;
  --moss: #334d40;
  --moss-dark: #24372e;
  --rust: #9f4934;
  --focus: #1366d6;
  --shadow: 0 24px 70px rgba(37, 40, 36, 0.1);
  --radius-sm: 10px;
  --radius-md: 18px;
  --radius-lg: 30px;
  --transition: 220ms cubic-bezier(0.2, 0.75, 0.25, 1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

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

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.72), transparent 28rem),
    linear-gradient(rgba(51, 77, 64, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(51, 77, 64, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 56px 56px, 56px 56px, auto;
}

button,
select,
input {
  font: inherit;
}

button,
select,
label {
  -webkit-tap-highlight-color: transparent;
}

button {
  touch-action: manipulation;
}

button:not(:disabled),
select:not(:disabled),
label[for] {
  cursor: pointer;
}

button:focus-visible,
select:focus-visible,
input:focus-visible + .toggle-track,
.kamae-option input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 12px 16px;
  color: white;
  background: var(--moss-dark);
  border-radius: var(--radius-sm);
  transform: translateY(-160%);
  transition: transform var(--transition);
}

.skip-link:focus {
  transform: translateY(0);
}

.page-shell {
  width: min(100% - 32px, 1120px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 0 max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.site-header,
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.site-header {
  min-height: 56px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  font-size: 0.93rem;
  font-weight: 730;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.wordmark-mark {
  width: 26px;
  height: 26px;
  border: 2px solid var(--ink);
  border-radius: 50% 45% 55% 42%;
  transform: rotate(-18deg);
}

.wordmark-mark::after {
  content: "";
  display: block;
  width: 16px;
  height: 2px;
  margin: 10px 0 0 4px;
  background: var(--rust);
  transform: rotate(32deg);
}

.studio-label,
.site-footer,
.keyboard-hint {
  color: var(--ink-soft);
  font-size: 0.78rem;
  letter-spacing: 0.07em;
}

main {
  flex: 1;
}

.setup-view {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(420px, 1.2fr);
  gap: clamp(48px, 8vw, 104px);
  padding: clamp(64px, 10vw, 120px) 0 80px;
  align-items: start;
}

.intro {
  position: sticky;
  top: 32px;
}

.eyebrow {
  margin: 0 0 18px;
  color: var(--rust);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  letter-spacing: -0.045em;
  text-wrap: balance;
}

h1:focus,
h2:focus {
  outline: none;
}

h1 {
  max-width: 8.8ch;
  font-size: clamp(3.25rem, 7vw, 6.5rem);
  line-height: 0.92;
}

.lede {
  max-width: 36rem;
  margin: 32px 0 0;
  color: var(--ink-soft);
  font-size: clamp(1.03rem, 1.6vw, 1.2rem);
  line-height: 1.65;
}

.setup-panel {
  padding: clamp(24px, 4vw, 40px);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid rgba(141, 145, 137, 0.46);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.form-section {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.form-section + .form-section,
.form-section + .form-row,
.form-row + .sound-toggle {
  margin-top: 32px;
}

.settings-row {
  margin-top: 0;
  margin-bottom: 32px;
  padding-bottom: 28px;
  border-bottom: 1px solid rgba(141, 145, 137, 0.32);
}

legend {
  padding: 0;
  font-size: 1rem;
  font-weight: 730;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 8px 0 18px;
}

.helper-text,
.form-error {
  min-height: 1.4em;
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
  line-height: 1.4;
}

.form-error {
  margin-top: 10px;
  color: #8b2e20;
  font-weight: 650;
}

.text-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--line-strong);
  font-size: 0.8rem;
}

.text-button {
  min-height: 44px;
  padding: 0 4px;
  color: var(--moss);
  background: transparent;
  border: 0;
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 4px;
}

.text-button:hover {
  text-decoration-color: currentColor;
}

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

.kamae-option {
  position: relative;
}

.kamae-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.kamae-option span {
  min-height: 52px;
  padding: 13px 14px;
  display: flex;
  align-items: center;
  color: var(--ink-soft);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.25;
  transition: color var(--transition), background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.kamae-option span::before {
  content: "";
  width: 16px;
  height: 16px;
  margin-right: 10px;
  flex: 0 0 auto;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  transition: background var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.kamae-option input:checked + span {
  color: var(--ink);
  background: #f1f2eb;
  border-color: #849389;
  box-shadow: inset 0 0 0 1px rgba(51, 77, 64, 0.14);
}

.kamae-option input:checked + span::before {
  background: var(--moss);
  border-color: var(--moss);
  box-shadow: inset 0 0 0 4px #f1f2eb;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 32px;
}

.compact-section label {
  display: block;
  margin: 8px 0 8px;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.select-wrap {
  position: relative;
}

.select-wrap select {
  width: 100%;
  min-height: 52px;
  padding: 0 44px 0 14px;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  appearance: none;
}

.select-wrap svg {
  position: absolute;
  top: 50%;
  right: 14px;
  width: 20px;
  height: 20px;
  pointer-events: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.75;
  transform: translateY(-50%);
}

.sound-toggle {
  min-height: 72px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(255, 253, 248, 0.62);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.sound-toggle strong,
.sound-toggle small {
  display: block;
}

.sound-toggle strong {
  font-size: 0.88rem;
}

.sound-toggle small {
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 0.76rem;
}

.sound-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-track {
  width: 48px;
  height: 28px;
  padding: 3px;
  flex: 0 0 auto;
  background: var(--line-strong);
  border-radius: 999px;
  transition: background var(--transition);
}

.toggle-track span {
  display: block;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  transition: transform var(--transition);
}

.sound-toggle input:checked + .toggle-track {
  background: var(--moss);
}

.sound-toggle input:checked + .toggle-track span {
  transform: translateX(20px);
}

.primary-button,
.secondary-button,
.icon-button,
.stop-button {
  min-height: 52px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition), border-color var(--transition), opacity var(--transition), transform 120ms ease-out;
}

.primary-button:active,
.secondary-button:active,
.icon-button:active {
  transform: scale(0.98);
}

.primary-button {
  width: 100%;
  margin-top: 24px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #fff;
  background: var(--moss);
  border: 1px solid var(--moss);
  font-weight: 740;
}

.primary-button:hover {
  background: var(--moss-dark);
  border-color: var(--moss-dark);
}

.primary-button svg,
.secondary-button svg,
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.safety-note {
  max-width: 48ch;
  margin: 18px auto 0;
  color: var(--ink-soft);
  font-size: 0.73rem;
  line-height: 1.5;
  text-align: center;
}

.session-view {
  min-height: min(760px, calc(100dvh - 178px));
  padding: clamp(32px, 6vw, 64px) 0 48px;
  display: flex;
  flex-direction: column;
  overflow-x: clip;
}

.session-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.session-status {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.icon-button {
  width: 52px;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line-strong);
}

.icon-button:hover,
.secondary-button:hover {
  background: rgba(255, 255, 255, 0.5);
  border-color: var(--ink-soft);
}

.prompt-stage {
  position: relative;
  min-height: 370px;
  display: grid;
  place-items: center;
  isolation: isolate;
}

.ink-orbit {
  position: absolute;
  z-index: -1;
  width: min(60vw, 430px);
  aspect-ratio: 1;
  border: clamp(18px, 3vw, 30px) solid rgba(51, 77, 64, 0.11);
  border-right-color: rgba(159, 73, 52, 0.34);
  border-bottom-color: transparent;
  border-radius: 48% 55% 52% 43%;
  transform: rotate(var(--orbit-angle, -18deg));
  transition: transform 420ms cubic-bezier(0.2, 0.75, 0.25, 1), border-color 420ms ease;
}

.ink-orbit::after {
  content: "";
  position: absolute;
  inset: 16%;
  border: 1px solid rgba(51, 77, 64, 0.18);
  border-radius: 52% 46% 56% 48%;
}

.prompt-copy {
  max-width: 850px;
  padding: 32px;
  text-align: center;
}

.current-side {
  min-height: 1.5em;
  margin: 0 0 10px;
  color: var(--rust);
  font-size: 0.8rem;
  font-weight: 760;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.prompt-copy h2 {
  font-size: clamp(3.4rem, 10vw, 8.75rem);
  line-height: 0.9;
}

.move-cue {
  margin: 28px 0 0;
  color: var(--ink-soft);
  font-size: clamp(0.95rem, 1.6vw, 1.12rem);
}

.prompt-copy.is-changing {
  animation: prompt-change 280ms ease-out;
}

.progress-block {
  width: min(100%, 720px);
  margin: auto auto 0;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

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

.progress-track {
  height: 5px;
  overflow: hidden;
  background: rgba(141, 145, 137, 0.35);
  border-radius: 999px;
}

.progress-track span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--moss);
  border-radius: inherit;
  transform: scaleX(var(--progress, 1));
  transform-origin: left;
  transition: transform 100ms linear;
}

.session-controls {
  width: min(100%, 720px);
  margin: 28px auto 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.secondary-button {
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line-strong);
  font-weight: 690;
}

.stop-button {
  min-width: 160px;
  margin: 18px auto 0;
  padding: 0 14px;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 5px;
}

.stop-button:hover {
  color: var(--ink);
  text-decoration-color: currentColor;
}

.keyboard-hint {
  margin: 10px auto 0;
  text-align: center;
}

.end-view {
  min-height: min(720px, calc(100dvh - 178px));
  padding: 64px 0;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
}

.end-mark {
  width: 160px;
  height: 160px;
  margin-bottom: 38px;
  border: 20px solid rgba(51, 77, 64, 0.15);
  border-top-color: var(--moss);
  border-right-color: rgba(159, 73, 52, 0.72);
  border-radius: 46% 54% 43% 57%;
  transform: rotate(-28deg);
}

.end-view h2 {
  font-size: clamp(4rem, 10vw, 8rem);
  line-height: 0.95;
}

.end-view > p:not(.eyebrow) {
  margin: 24px 0 0;
  color: var(--ink-soft);
  font-size: 1rem;
}

.end-view strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.end-actions {
  width: min(100%, 440px);
  margin-top: 36px;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
}

.end-actions .primary-button {
  margin-top: 0;
}

.site-footer {
  min-height: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.site-footer p {
  margin: 0;
}

[hidden] {
  display: none !important;
}

@keyframes prompt-change {
  0% { opacity: 0.2; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

@media (max-width: 820px) {
  .setup-view {
    grid-template-columns: 1fr;
    gap: 48px;
    padding-top: 56px;
  }

  .intro {
    position: static;
  }

  h1 {
    max-width: 10ch;
  }

  .prompt-stage {
    min-height: 350px;
  }
}

@media (max-width: 560px) {
  .page-shell {
    width: min(100% - 24px, 1120px);
  }

  .site-header {
    padding-bottom: 16px;
  }

  .studio-label,
  .keyboard-hint {
    display: none;
  }

  .setup-view {
    gap: 36px;
    padding: 40px 0 48px;
  }

  h1 {
    font-size: clamp(3rem, 16vw, 4.5rem);
  }

  .lede {
    margin-top: 24px;
  }

  .setup-panel {
    padding: 22px 16px;
    border-radius: 22px;
  }

  .kamae-grid,
  .form-row,
  .end-actions {
    grid-template-columns: 1fr;
  }

  .kamae-option span {
    min-height: 48px;
  }

  .section-heading {
    align-items: flex-start;
  }

  .session-view {
    min-height: calc(100dvh - 140px);
    padding: 28px 4px 32px;
  }

  .prompt-stage {
    min-height: 330px;
  }

  .prompt-copy {
    padding: 24px 8px;
  }

  .prompt-copy h2 {
    font-size: clamp(3.4rem, 18vw, 5.4rem);
  }

  .ink-orbit {
    width: min(86vw, 350px);
  }

  .site-footer {
    justify-content: center;
    text-align: center;
  }

  .site-footer p:last-child {
    display: none;
  }
}

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