:root {
  --bg: #f4f1ea;
  --ink: #111;
  --muted: #6b665c;
  --font: "Courier New", Courier, "Liberation Mono", monospace;
  --cursor-size: 64px;

}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow: hidden;
  touch-action: manipulation;
}

main {
  position: relative;
  height: 100dvh;
}

/* ---------- language switcher ---------- */

.lang-switch {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
}

.lang-switch button {
  font: inherit;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 8px 6px;
  cursor: pointer;
}

.lang-switch button[aria-pressed="true"] {
  color: var(--ink);
  font-weight: bold;
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* ---------- screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 64px 16px 24px;
  opacity: 0;
  transition: opacity 0.6s ease;
}

.screen.is-active { display: flex; }
.screen.is-visible { opacity: 1; }

/* ---------- intro / typewriter ---------- */

#intro {
  justify-content: center;
  overflow-y: auto;
  cursor: pointer;
}

.intro-text {
  width: 100%;
  max-width: 680px;
  margin: auto 0;
}

.intro-text h1 {
  font-size: clamp(26px, 6vw, 44px);
  line-height: 1.15;
  margin: 0 0 1em;
  min-height: 1.15em;
}

.intro-p {
  font-size: clamp(16px, 2.4vw, 19px);
  line-height: 1.6;
  margin: 0 0 1.1em;
  white-space: pre-wrap;
}

.intro-p:empty, .intro-text h1:empty { display: none; }

.caret::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.12em;
  background: currentColor;
  animation: blink 0.9s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.hint {
  font-size: 13px;
  color: var(--muted);
  margin: 16px 0 0;
}

/* ---------- game ---------- */

.level-head {
  text-align: center;
  max-width: 680px;
}

.level-count {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.1em;
}

.level-head h2 {
  margin: 6px 0 4px;
  font-size: clamp(22px, 5vw, 34px);
}

.level-head p#level-subtitle {
  margin: 0;
  font-size: clamp(14px, 2.2vw, 17px);
  color: var(--muted);
}

.stage {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 16px;
}

.stage svg {
  width: min(88vw, 100%);
  height: 100%;
  max-height: min(88vw, 70dvh);
  overflow: visible;
  transition: transform 0.5s ease, opacity 0.5s ease;
}

/* the shapes have fill="none"; this makes their whole interior clickable */
.stage svg :is(path, polygon, polyline, rect, circle, ellipse) {
  pointer-events: all;
  vector-effect: non-scaling-stroke;
}

.stage svg.is-entering { opacity: 0; transform: scale(0.92); }
.stage svg.is-hit {
  opacity: 0;
  transition: opacity 1.4s ease-in 0.5s;
}
.stage svg.is-hit :is(path, polygon, rect, circle, ellipse) {
  fill: #1c1815;
  transition: fill 0.12s;
}

/* violent at first, then settling */
.shake { animation: shake 0.9s cubic-bezier(.2,.6,.3,1); }

@keyframes shake {
  0%   { transform: translate(0, 0); }
  4%   { transform: translate(-14px, 9px) rotate(-0.6deg); }
  9%   { transform: translate(12px, -11px) rotate(0.5deg); }
  15%  { transform: translate(-10px, 6px) rotate(-0.3deg); }
  22%  { transform: translate(8px, -5px); }
  30%  { transform: translate(-5px, 4px); }
  40%  { transform: translate(4px, -2px); }
  52%  { transform: translate(-2px, 2px); }
  66%  { transform: translate(1px, -1px); }
  100% { transform: translate(0, 0); }
}

/* ---------- end ---------- */

#end {
  justify-content: center;
  text-align: center;
}

#end h2 { font-size: clamp(24px, 5vw, 38px); margin: 0 0 12px; }
#end p { max-width: 560px; line-height: 1.6; margin: 0 0 28px; }

.btn {
  font: inherit;
  font-size: 16px;
  color: var(--bg);
  background: var(--ink);
  border: 0;
  padding: 12px 22px;
  cursor: pointer;
}

/* ---------- effects layer + custom cursor ---------- */

#fx {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

#fx canvas { display: block; }

#flash {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  background: radial-gradient(circle, #fffdf6 0%, #fff6e0 60%, #ffe9c4 100%);
  opacity: 0;
}

#cursor {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  width: var(--cursor-size);
  height: var(--cursor-size);
  margin: calc(var(--cursor-size) / -2) 0 0 calc(var(--cursor-size) / -2);
  pointer-events: none;
  display: none;
  will-change: transform;
}

body.is-playing, body.is-playing * { cursor: none !important; }
body.is-playing.has-pointer #cursor { display: block; }

@media (prefers-reduced-motion: reduce) {
  .screen, .stage svg { transition: none; }
  .shake { animation: none; }
}
