:root {
  /* Primitive palette */
  --p-petrol: oklch(0.210 0.027 199.5);
  --p-petrol-light: oklch(0.255 0.036 199.5);
  --p-paper: oklch(0.956 0.011 84.6);
  --p-teal: oklch(0.753 0.123 181.5);
  --p-coral: oklch(0.757 0.147 32.7);
  --p-muted: oklch(0.76 0.025 84.6);

  /* Semantic palette */
  --surface: var(--p-petrol);
  --surface-raised: var(--p-petrol-light);
  --text: var(--p-paper);
  --text-muted: var(--p-muted);
  --accent: var(--p-teal);
  --accent-warm: var(--p-coral);
  --line: oklch(0.956 0.011 84.6 / 0.28);

  /* Component tokens */
  --control-height: 44px;
  --page-gutter: clamp(16px, 3vw, 48px);
  --z-canvas: 0;
  --z-content: 2;
  --z-letter: 4;
  --z-ui: 10;
  --z-cursor: 20;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; min-height: 100%; overflow: hidden; }
html { background: var(--surface); }
body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(ellipse at 52% 42%, var(--surface-raised), var(--surface) 72%);
  color: var(--text);
  font-family: "Helvetica Neue", "Nimbus Sans", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
::selection { color: var(--text); background: var(--accent); }
button { font: inherit; }
button, [role="button"] { cursor: pointer; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 5px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: fixed;
  z-index: 30;
  top: 8px;
  left: 8px;
  padding: 8px 16px;
  color: var(--surface);
  background: var(--text);
  transform: translateY(-160%);
  transition: transform 180ms ease-out;
}
.skip-link:focus { transform: translateY(0); }

#bg, #fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-canvas);
  pointer-events: none;
}
#fx { z-index: 3; }

.topbar {
  position: fixed;
  z-index: var(--z-ui);
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  min-height: 80px;
  padding: 16px var(--page-gutter);
  padding-top: max(16px, env(safe-area-inset-top));
  font-family: "Courier New", monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  line-height: 1.2;
}
.wordmark { display: flex; align-items: center; font-weight: 700; white-space: nowrap; }
.wordmark .initials, .wordmark .wordmark-label { color: var(--text); }
.wordmark .divider { margin: 0 10px; color: var(--text-muted); }
.status { display: flex; align-items: center; gap: 9px; color: var(--text-muted); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.controls { display: flex; justify-content: flex-end; gap: 8px; }
.control {
  min-height: var(--control-height);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: transparent;
  font-family: "Courier New", monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  transition: color 160ms ease-out, background-color 160ms ease-out, border-color 160ms ease-out, transform 160ms ease-out;
}
.control span { color: var(--text-muted); }
.control:hover, .control:active { color: var(--surface); background: var(--text); border-color: var(--text); }
.control:hover span, .control:active span { color: var(--surface); }
.control:active { transform: scale(0.96); }
.control[aria-pressed="true"] { border-color: var(--accent); }
.control[aria-pressed="true"] span { color: var(--text); }

.intro {
  position: fixed;
  z-index: var(--z-content);
  top: clamp(108px, 15vh, 160px);
  left: var(--page-gutter);
  max-width: 28ch;
  color: var(--text-muted);
  font-size: clamp(15px, 1.25vw, 19px);
  line-height: 1.5;
  pointer-events: none;
}
.lunar-readout {
  position: fixed;
  z-index: var(--z-content);
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  width: 170px;
  color: var(--text-muted);
  font-family: "Courier New", monospace;
  font-size: 12px;
  line-height: 1.45;
  letter-spacing: 0.08em;
  text-align: center;
  pointer-events: none;
}
.lunar-readout span { white-space: nowrap; }
.moon-phase { color: var(--text); font-size: 12px; }
.moon-details { color: var(--accent); }
.moon-date { opacity: 0.78; }
#stage { position: fixed; inset: 0; z-index: var(--z-letter); }
.letter {
  position: fixed;
  top: 0;
  left: 0;
  display: block;
  border: 0;
  color: var(--text);
  background: transparent;
  font-family: "Helvetica Neue", "Nimbus Sans", Arial, sans-serif;
  font-weight: 300;
  line-height: 0.8;
  letter-spacing: -0.06em;
  text-align: center;
  white-space: pre;
  will-change: transform;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: color 160ms ease-out, opacity 160ms ease-out;
}
.letter:hover { color: var(--text-muted); }
.letter.grabbing { z-index: 6; color: var(--accent); cursor: grabbing; }
.letter:focus-visible { color: var(--accent); outline-offset: 8px; }
.side-note {
  position: fixed;
  z-index: var(--z-content);
  right: var(--page-gutter);
  top: 44%;
  color: var(--text-muted);
  font-family: "Courier New", monospace;
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.12em;
  text-align: right;
  writing-mode: vertical-rl;
  pointer-events: none;
}

.bottombar {
  position: fixed;
  z-index: var(--z-ui);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 20px var(--page-gutter);
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.hint { display: flex; flex-direction: column; gap: 2px; }
.hint-primary, .keyboard-hint {
  font-family: "Courier New", monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
}
.hint-secondary { color: var(--text-muted); font-size: 14px; }
.keyboard-hint { color: var(--text-muted); font-size: 10px; }
.keyboard-hint span { margin: 0 6px; }

#cursor {
  position: fixed;
  z-index: var(--z-cursor);
  top: 0;
  left: 0;
  width: 34px;
  height: 34px;
  border: 1px solid var(--text);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: difference;
  will-change: transform;
  transition: width 160ms ease-out, height 160ms ease-out, opacity 160ms ease-out;
}
#cursor.visible { opacity: 1; }
#cursor.active { width: 52px; height: 52px; background: var(--text); }
.noscript {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  padding: 12px 20px;
  color: var(--surface);
  background: var(--text);
}

@media (pointer: fine) {
  body, .letter, button, [role="button"] { cursor: none; }
}
@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr auto; gap: 12px; min-height: 72px; }
  .status { display: none; }
  .wordmark { font-size: 10px; }
  .wordmark .divider { margin: 0 5px; }
  .control { padding: 0 11px; font-size: 10px; }
  .intro { top: 104px; font-size: 15px; }
  .side-note { display: none; }
  .lunar-readout { width: 170px; font-size: 12px; }
  .moon-phase { font-size: 12px; }
  .keyboard-hint { display: none; }
  .bottombar { padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  .hint-primary { font-size: 11px; }
  .hint-secondary { font-size: 13px; }
}
@media (max-width: 420px) {
  .wordmark { line-height: 1.25; }
  .wordmark .divider, .wordmark .wordmark-label { display: none; }
  .controls { gap: 6px; }
  .control { padding: 0 10px; }
}
@media (max-height: 620px) {
  .intro { display: none; }
  .topbar { min-height: 60px; padding-top: 8px; }
  .bottombar { padding-bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  #cursor { display: none; }
  body, .letter, button, [role="button"] { cursor: auto; }
}
