/* ============================================================
   LIPOGRAMA — tokens
   ============================================================ */
:root {
  --paper: #ece4d3;
  --paper-dark: #e2d8c1;
  --ink: #221d18;
  --redact: #a32f26;
  --redact-dark: #7f241d;
  --tape: #c9bfa0;
  --pine: #2e5c4e;
  --fade: #6b5f4f;
  --line: #d8cdb2;

  --display: "Special Elite", "Courier New", monospace;
  --serif: "Source Serif 4", Georgia, serif;
  --mono: "IBM Plex Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  min-height: 100%;
}

body {
  font-family: var(--serif);
  position: relative;
  overflow-x: hidden;
}

/* subtle paper grain */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  opacity: 0.05;
  background-image:
    radial-gradient(circle at 20% 30%, #000 0.5px, transparent 0.5px),
    radial-gradient(circle at 60% 70%, #000 0.5px, transparent 0.5px),
    radial-gradient(circle at 80% 20%, #000 0.5px, transparent 0.5px);
  background-size: 3px 3px, 5px 5px, 4px 4px;
}

.stage {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(24px, 5vw, 64px) 20px 64px;
}

:focus-visible {
  outline: 2px solid var(--pine);
  outline-offset: 3px;
}

button { font-family: inherit; }

/* ============================================================
   SCREEN: SETUP
   ============================================================ */
.screen--setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.key-hero {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
}

.key-hero__cap {
  position: relative;
  width: 132px;
  height: 132px;
  background: linear-gradient(180deg, #f4ede0 0%, #ddd0b0 100%);
  border: 2px solid var(--ink);
  border-radius: 14px;
  box-shadow:
    0 6px 0 var(--ink),
    0 10px 18px rgba(34, 29, 24, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-3deg);
}

.key-hero__letter {
  font-family: var(--display);
  font-size: 64px;
  color: var(--ink);
  line-height: 1;
  user-select: none;
}

.key-hero__tape {
  position: absolute;
  left: -18px;
  right: -18px;
  top: 50%;
  height: 30px;
  transform: translateY(-50%) rotate(-8deg);
  background: var(--tape);
  border: 1px solid rgba(34, 29, 24, 0.25);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.key-hero__stamp {
  margin-top: 18px;
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: 0.12em;
  color: var(--redact);
  border: 2px solid var(--redact);
  padding: 4px 14px;
  border-radius: 4px;
  transform: rotate(-4deg);
  opacity: 0.9;
}

.title {
  font-family: var(--display);
  font-size: clamp(30px, 6vw, 42px);
  letter-spacing: 0.08em;
  margin: 0 0 10px;
  color: var(--ink);
}

.subtitle {
  max-width: 460px;
  font-size: 17px;
  line-height: 1.55;
  color: var(--fade);
  margin: 0 0 34px;
}

.difficulty {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-bottom: 30px;
}

.pill {
  background: var(--paper-dark);
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  padding: 10px 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.15s ease, background 0.15s ease;
}

.pill:hover { transform: translateY(-2px); background: #f4ede0; }
.pill:active { transform: translateY(0); }

.pill__label {
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.03em;
}

.pill__hint {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--fade);
}

.pill--perec {
  border-color: var(--redact);
}
.pill--perec .pill__label { color: var(--redact-dark); }

.footnote {
  max-width: 440px;
  font-size: 13px;
  font-style: italic;
  color: var(--fade);
  line-height: 1.5;
}

/* ============================================================
   SCREEN: PLAY
   ============================================================ */
.screen--play { display: flex; flex-direction: column; gap: 20px; }

.hud {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.hud__badge {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border: 2px solid var(--ink);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper-dark);
  position: relative;
}

.hud__badge::after {
  content: "";
  position: absolute;
  left: -6px;
  right: -6px;
  top: 50%;
  height: 10px;
  transform: translateY(-50%) rotate(-8deg);
  background: var(--tape);
  border: 1px solid rgba(34, 29, 24, 0.25);
}

#hud-letter-char {
  font-family: var(--display);
  font-size: 22px;
  position: relative;
  z-index: 2;
}

.hud__stats {
  display: flex;
  gap: 20px;
  margin-right: auto;
}

.stat { display: flex; flex-direction: column; align-items: flex-start; }

.stat__value {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 600;
}

.stat__value--warn { color: var(--redact); }

.stat__label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--fade);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.btn {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.03em;
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  border: 1.5px solid var(--ink);
  background: transparent;
  color: var(--ink);
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }

.btn--ghost:hover { background: var(--ink); color: var(--paper); }

.btn--primary {
  background: var(--pine);
  border-color: var(--pine);
  color: var(--paper);
}
.btn--primary:hover { background: #244a3f; }

.prompt {
  font-size: 16px;
  font-style: italic;
  color: var(--ink);
  margin: 0;
  line-height: 1.5;
}

.prompt__eyebrow {
  font-family: var(--mono);
  font-style: normal;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--redact);
  margin-right: 6px;
}

.page {
  position: relative;
  background: #fbf8f0;
  border: 1px solid var(--line);
  border-radius: 4px;
  min-height: 340px;
  padding: 28px 26px;
  box-shadow: 0 1px 0 var(--line), 0 12px 24px rgba(34, 29, 24, 0.06);
}

.page__lines {
  position: absolute;
  inset: 28px 0 0 0;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 34px,
    var(--line) 34px,
    var(--line) 35px
  );
  pointer-events: none;
}

.editor-wrap {
  position: relative;
  z-index: 1;
  display: grid;
}

.mirror,
.editor {
  grid-area: 1 / 1;
  font-family: var(--serif);
  font-size: 18px;
  line-height: 35px;
  padding: 0;
  margin: 0;
  border: none;
  width: 100%;
  white-space: pre-wrap;
  word-wrap: break-word;
  min-height: 300px;
}

.mirror {
  color: var(--ink);
  pointer-events: none;
}

.editor {
  background: transparent;
  color: transparent;
  caret-color: var(--ink);
  resize: none;
  outline: none;
  overflow: hidden;
  font-family: var(--serif);
}

.editor::placeholder {
  color: var(--fade);
  opacity: 0.6;
}

.mirror .violation {
  color: var(--redact);
  background: rgba(163, 47, 38, 0.14);
  border-radius: 2px;
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

/* screen shake + flash when a forbidden letter is typed */
.stage.shake { animation: shake 0.28s ease; }

@keyframes shake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

.hud__badge.spark {
  animation: spark 0.35s ease;
}

@keyframes spark {
  0%, 100% { box-shadow: none; }
  40% { box-shadow: 0 0 0 6px rgba(163, 47, 38, 0.25); border-color: var(--redact); }
}

/* ============================================================
   SCREEN: RESULT
   ============================================================ */
.screen--result {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: 40px;
}

.result__eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--redact);
  margin-bottom: 10px;
}

.result__title {
  font-family: var(--display);
  font-size: clamp(26px, 5vw, 34px);
  margin: 0 0 30px;
}

.result__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 420px;
  margin-bottom: 22px;
}

.result__cell {
  background: var(--paper-dark);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.result__value {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 600;
}

.result__label {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--fade);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.result__note {
  max-width: 440px;
  font-size: 14px;
  font-style: italic;
  color: var(--fade);
  margin-bottom: 10px;
}

.result__best {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--pine);
  margin: 0 0 26px;
}

.result__actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ============================================================
   Utility
   ============================================================ */
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .stage.shake, .hud__badge.spark { animation: none; }
}

@media (max-width: 480px) {
  .hud { gap: 12px; }
  .hud__stats { gap: 14px; }
  .page { padding: 22px 16px; }
}
