/* Shared foundation. Each theme file sets the custom properties used here and
   lays out its own screens. */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
html {
  background: var(--page-bg, #0b0b12);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  overscroll-behavior: none;
  font-family: var(--font-body, system-ui, sans-serif);
  color: var(--ink, #fff);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled, [aria-disabled="true"] { cursor: default; }
img { -webkit-user-drag: none; user-select: none; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 3px solid var(--focus, #5CE0FF); outline-offset: 2px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- app frame: always the visible area, phone-width column -------- */
#app {
  position: fixed;
  top: var(--app-top, 0px);
  left: 50%;
  width: min(100%, 480px);
  height: var(--app-h, 100dvh);
  transform: translateX(-50%);
  overflow: hidden;
  background: var(--bg, #000);
  user-select: none;
  -webkit-user-select: none;
}
@media (min-width: 520px) {
  #app { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 30px 80px rgba(0, 0, 0, 0.5); }
}
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.screen.home { overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; }
input { user-select: text; -webkit-user-select: text; }
.fatal { color: #fff; font: 600 18px system-ui, sans-serif; padding: 40px 24px; text-align: center; }

/* ---------- home: photo, nickname -------------------------------------------- */
.photo { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 38% 28%; }
.nick { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.nick-input, .guess-input {
  font-size: 18px; /* ≥16px: iPhone does not zoom on focus */
  width: 100%;
  min-width: 0;
  outline: none;
}
.nick-error { min-height: 0; font: 800 14px var(--font-body); color: var(--error, #FF6B6B); }
.nick-error:empty { display: none; }
.nick-input[aria-invalid="true"] { animation: wtp-shake 0.4s; }

/* ---------- game: stage, silhouette ------------------------------------------ */
.game { touch-action: manipulation; }
.stage { position: relative; flex: 1 1 auto; min-height: 140px; overflow: hidden; isolation: isolate; }
.sprite-wrap {
  position: absolute;
  inset: var(--sprite-inset, 10% 12% 14%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
}
.sprite {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  filter: brightness(0) var(--silhouette-filter, );
  transition: filter 0.35s ease, opacity 0.25s ease;
  pointer-events: none;
  -webkit-touch-callout: none;
  animation: var(--sprite-idle, none);
}
.sprite.is-loading { opacity: 0; }
/* once revealed, the Pokémon moves up so the name banner never covers it */
.sprite-wrap { transition: top 0.35s ease, bottom 0.35s ease; }
.stage.is-revealed .sprite-wrap { top: var(--reveal-sprite-top, 6%); bottom: var(--reveal-sprite-bottom, 36%); }
.sprite.is-revealed { filter: none; animation: wtp-pop 0.5s cubic-bezier(.2, 1.6, .4, 1); }
.stage.is-missing .sprite-wrap::after {
  content: '?';
  font: 400 120px/1 var(--font-display, sans-serif);
  color: var(--missing-ink, #111);
}
.stage.is-missing .sprite { display: none; }
.stage.is-revealing:not(.is-revealed) .sprite { animation: wtp-pulse 0.42s ease-in-out 1; }
.stage.is-flash::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  background: #fff;
  pointer-events: none;
  animation: wtp-flash 0.5s ease-out forwards;
}

/* ---------- reveal banner ------------------------------------------------------ */
.reveal {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "kicker next" "name next" "types next";
  align-items: center;
  column-gap: 10px;
  padding: 8px 10px 10px 14px;
  background: var(--reveal-bg, #fff);
  color: var(--reveal-ink, #111);
  border: var(--reveal-border, 3px solid #111);
  border-radius: var(--reveal-radius, 14px);
  box-shadow: var(--reveal-shadow, 0 5px 0 #111);
  animation: wtp-slide-up 0.35s cubic-bezier(.2, 1.3, .5, 1);
}
.reveal-kicker { grid-area: kicker; font: 800 12px var(--font-body); letter-spacing: 1px; text-transform: uppercase; opacity: 0.75; }
.reveal-name {
  grid-area: name;
  font-family: var(--font-display);
  font-size: clamp(22px, 7.2vw, 32px);
  line-height: 1.05;
  overflow-wrap: anywhere;
}
.reveal-types { grid-area: types; display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.reveal-next {
  grid-area: next;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 52px;
  padding: 0 16px;
  font: var(--next-font, 400 22px var(--font-display));
  background: var(--btn-primary-bg, #E8342E);
  color: var(--btn-primary-ink, #fff);
  border: var(--btn-border, 3px solid #111);
  border-radius: var(--btn-radius, 12px);
  box-shadow: var(--btn-shadow, 0 4px 0 #111);
}
.reveal-next svg { font-size: 0.8em; }
.stage.is-lost .reveal { --reveal-bg: var(--reveal-lost-bg, #2b2b2b); --reveal-ink: #fff; }

/* ---------- letter slots ------------------------------------------------------- */
.slots {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: var(--slot-gap, 5px);
  width: 100%;
}
.slot {
  flex: 0 1 var(--slot-w, 34px);
  width: var(--slot-w, 34px);
  min-width: 0;
  height: var(--slot-h, 42px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-slot, var(--font-display));
  font-size: var(--slot-fs, 24px);
  line-height: 1;
  background: var(--slot-bg, transparent);
  color: var(--slot-ink, inherit);
  border: var(--slot-border, 0);
  border-bottom: var(--slot-underline, var(--slot-border, 0));
  border-radius: var(--slot-radius, 6px);
}
.slot.is-open {
  background: var(--slot-open-bg, var(--slot-bg));
  color: var(--slot-open-ink, inherit);
  border: var(--slot-open-border, var(--slot-border, 0));
}
.slot.is-fixed {
  flex: 0 0 auto;
  width: auto;
  min-width: 6px;
  background: none;
  border: 0;
  color: var(--slot-fixed-ink, inherit);
}
.slot.is-popping { animation: wtp-pop 0.5s cubic-bezier(.2, 1.6, .4, 1); }
.slots.is-long { --slot-w: var(--slot-w-long, 29px); --slot-fs: var(--slot-fs-long, 20px); --slot-gap: 3px; }

/* ---------- clues (hint result) ------------------------------------------------ */
.clues {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 8px;
  animation: wtp-pop 0.45s cubic-bezier(.2, 1.4, .4, 1);
}
.clues-label { font: 800 12px var(--font-body); letter-spacing: 1.5px; opacity: 0.8; }
.clue-gen, .clue-types { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  font: 800 13px/1.5 var(--font-body);
  letter-spacing: 0.5px;
  border: var(--chip-border, 2px solid rgba(0, 0, 0, 0.6));
  border-radius: var(--chip-radius, 8px);
  white-space: nowrap;
}
.chip-type { background: var(--tc); color: var(--ti); }
.chip-gen { background: var(--chip-gen-bg, #fff); color: var(--chip-gen-ink, #111); }
.chip-region { font-weight: 600; opacity: 0.8; }

/* ---------- lives -------------------------------------------------------------- */
.lives { display: inline-flex; align-items: center; gap: var(--life-gap, 6px); }
.life { display: inline-flex; font-size: var(--life-size, 26px); line-height: 0; transition: opacity 0.3s, filter 0.3s, transform 0.3s; }
.life.is-lost { opacity: var(--life-lost-opacity, 0.25); filter: grayscale(1); transform: scale(0.85); }
.life.is-popping { animation: wtp-lifepop 0.6s ease-out; }

/* ---------- icon buttons ---------------------------------------------------------- */
.icon-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 8px;
  font-size: 22px;
  background: var(--icon-btn-bg, transparent);
  color: var(--icon-btn-ink, currentColor);
  border: var(--icon-btn-border, 0);
  border-radius: var(--icon-btn-radius, 12px);
}
.sound-btn .when-off { display: none; }
.sound-btn.is-off .when-on { display: none; }
.sound-btn.is-off .when-off { display: inline-flex; }
.when-on, .when-off { display: inline-flex; }

/* ---------- guess form ------------------------------------------------------------ */
.guess-form { display: flex; gap: 8px; width: 100%; }
.guess-form.is-shaking { animation: wtp-shake 0.4s; }
.guess-input:disabled { opacity: 0.7; }
[data-role="hint"].is-empty { opacity: 0.45; }

/* ---------- feedback -------------------------------------------------------------- */
.feedback {
  position: absolute;
  left: 50%;
  top: var(--feedback-top, 46%);
  z-index: 8;
  max-width: calc(100% - 32px);
  padding: 8px 16px;
  border-radius: 999px;
  background: #263238;
  color: #fff;
  font: 800 15px/1.2 var(--font-body);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s, transform 0.2s;
}
.feedback.is-visible { opacity: 1; transform: translate(-50%, 0); }
.feedback[data-tone="bad"] { background: #C62828; }
.feedback[data-tone="good"] { background: #2E7D32; }
.kb-open .feedback { top: 8px; }

/* ---------- sheets (theme picker, hall of fame, game over) --------------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(5, 4, 15, 0.6);
  opacity: 0;
  transition: opacity 0.2s;
}
.sheet-backdrop.is-open { opacity: 1; }
.sheet {
  position: relative;
  width: min(100%, 480px);
  max-height: min(88vh, 88dvh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
  background: var(--sheet-bg, #FFFDF4);
  color: var(--sheet-ink, #140C34);
  border-top: var(--sheet-border, 4px solid #140C34);
  border-radius: var(--sheet-radius, 26px) var(--sheet-radius, 26px) 0 0;
  font-family: var(--font-body);
  transform: translateY(40px);
  transition: transform 0.25s cubic-bezier(.2, 1.2, .4, 1);
  outline: none;
}
.sheet-backdrop.is-open .sheet { transform: none; }
.sheet-grip { width: 48px; height: 5px; margin: 0 auto 10px; border-radius: 3px; background: var(--sheet-line, #C9CFDE); }
.sheet-close {
  position: absolute; top: 14px; right: 14px;
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; border-radius: 50%;
  background: transparent; border: 2px solid var(--sheet-line, #C9CFDE); color: var(--sheet-ink);
}
.sheet-title {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 52px 12px 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 28px;
  line-height: 1.05;
}
.sheet-text { font-size: 16px; line-height: 1.45; margin-bottom: 16px; }
.sheet-note { font-size: 13px; font-weight: 700; color: var(--sheet-muted, #6A7390); text-align: center; margin: 4px 0 10px; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.sheet-actions--grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.sheet-actions--grid .sheet-btn--primary { grid-column: 1 / -1; }
.sheet-actions--grid .sheet-btn:not(.sheet-btn--primary) { flex-direction: column; gap: 2px; min-height: 64px; font-size: 14px; padding: 6px 4px; text-align: center; line-height: 1.1; }
.sheet-btn {
  min-height: 50px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 14px;
  font: 800 16px var(--font-body);
  background: var(--sheet-btn-bg, transparent);
  color: var(--sheet-ink);
  border: 2px solid var(--sheet-line, #C9CFDE);
  border-radius: var(--btn-radius, 12px);
}
.sheet-btn svg { font-size: 20px; }
.sheet-btn--primary {
  min-height: 58px;
  font: var(--sheet-primary-font, 400 24px var(--font-display));
  background: var(--btn-primary-bg, #E8342E);
  color: var(--btn-primary-ink, #fff);
  border: var(--btn-border, 3px solid #111);
  box-shadow: var(--btn-shadow, 0 4px 0 #111);
}

/* theme picker */
.tp-list { display: flex; flex-direction: column; gap: 10px; }
.tp-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 10px;
  text-align: left;
  background: var(--sheet-item-bg, #fff);
  border: 2px solid var(--sheet-line, #C9CFDE);
  border-radius: 16px;
}
.tp-item.is-current { border: 3px solid var(--sheet-ink); box-shadow: 0 4px 0 var(--sheet-ink); }
.tp-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tp-name { display: flex; align-items: center; gap: 6px; font-size: 20px; line-height: 1.1; }
.tp-tag { font: 700 13px var(--font-body); color: var(--sheet-muted, #5A5478); }
.tp-default { font: 900 10px var(--font-body); letter-spacing: 1px; padding: 1px 6px; border-radius: 6px; background: #FFB800; color: #140C34; }
.tp-check {
  width: 28px; height: 28px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; font-size: 16px;
  background: var(--sheet-ink); color: var(--sheet-bg);
  visibility: hidden;
}
.tp-item.is-current .tp-check { visibility: visible; }
.tp-name--arena { font-family: 'Barlow Condensed', sans-serif; font-weight: 800; text-transform: uppercase; color: #140C34; }
.tp-name--burst { font-family: 'Luckiest Guy', cursive; color: #0A2560; }
.tp-name--comic { font-family: 'Bangers', cursive; letter-spacing: 1px; text-transform: uppercase; color: #111; font-size: 22px; }
.tp-name--forest { font-family: 'Lilita One', cursive; color: #1C3A1E; }
.tp-name--arcade { font-family: 'Titan One', cursive; color: #2A0B3D; }
.tp-preview { position: relative; width: 64px; height: 64px; flex-shrink: 0; border-radius: 12px; overflow: hidden; }
.tp-preview i { position: absolute; display: block; }
.tp-preview--arena { background: #140C34; border: 2px solid #3B2E6E; }
.tp-preview--arena i:nth-child(1) { left: 18px; top: -4px; width: 28px; height: 70px; background: rgba(255, 236, 170, 0.45); clip-path: polygon(40% 0, 60% 0, 100% 100%, 0 100%); }
.tp-preview--arena i:nth-child(2) { left: 8px; right: 8px; bottom: 8px; height: 12px; border-radius: 50%; border: 2px solid #FFB800; }
.tp-preview--burst { border: 2px solid #0A2560; background: repeating-conic-gradient(from 0deg, #FFD23F 0deg 15deg, #FFB800 15deg 30deg); }
.tp-preview--burst i:nth-child(1) { left: 18px; top: 14px; width: 28px; height: 34px; border-radius: 50% 50% 40% 40%; background: #111; }
.tp-preview--comic { border: 3px solid #111; background-color: #FFF8E7; background-image: radial-gradient(#E0217A 2px, transparent 2.4px); background-size: 9px 9px; }
.tp-preview--comic i:nth-child(1) { left: 10px; top: 20px; padding: 0 4px; background: #FFE14D; border: 2px solid #111; font: 400 18px/1.1 'Bangers', cursive; }
.tp-preview--comic i:nth-child(1)::after { content: 'POW'; color: #111; }
.tp-preview--forest { background: #3E7A3A; border: 2px solid #1C3A1E; }
.tp-preview--forest i:nth-child(1), .tp-preview--forest i:nth-child(2) { top: 15px; width: 26px; height: 26px; border-radius: 50%; border: 4px solid #1C3A1E; background: #B9E08E; }
.tp-preview--forest i:nth-child(1) { left: 7px; }
.tp-preview--forest i:nth-child(2) { left: 27px; }
.tp-preview--arcade { background: #2A0B3D; }
.tp-preview--arcade i:nth-child(1) { left: 14px; top: 9px; width: 36px; height: 36px; border-radius: 50%; background: repeating-linear-gradient(180deg, #FFB347 0 5px, #FF5E7E 5px 8px); }
.tp-preview--arcade i:nth-child(2) { left: 0; right: 0; bottom: 0; height: 22px; background-color: #2A0B3D; background-image: linear-gradient(#FF4FA3 1px, transparent 1px); background-size: 100% 6px; }

/* hall of fame */
.hof-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.hof-row {
  display: grid;
  grid-template-columns: 34px 1fr auto 48px;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 4px 12px;
  border-radius: 12px;
  background: var(--sheet-item-bg, #fff);
  border: 2px solid var(--sheet-line, #C9CFDE);
  font-weight: 800;
}
.hof-row:nth-child(1) .hof-rank { background: #FFC93C; color: #2a1d00; }
.hof-row:nth-child(2) .hof-rank { background: #D5DAE3; color: #1b2230; }
.hof-row:nth-child(3) .hof-rank { background: #E3A774; color: #2b1300; }
.hof-rank { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; border-radius: 50%; font-size: 14px; }
.hof-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.hof-hints { display: inline-flex; align-items: center; gap: 2px; font-size: 13px; color: var(--sheet-muted); }
.hof-score { text-align: right; font-family: var(--font-display); font-size: 24px; }
.hof-row.is-me { border-color: var(--sheet-ink); box-shadow: 0 3px 0 var(--sheet-ink); }

/* game over */
.go-head { text-align: center; }
.go-title { justify-content: center; margin: 4px 0 4px; font-size: 34px; }
.go-was { font-size: 16px; }
.go-score { display: flex; flex-direction: column; align-items: center; margin: 10px 0 6px; }
.go-score-num { font-family: var(--font-display); font-size: 72px; line-height: 1; color: var(--go-accent, #E8342E); }
.go-score-label { font: 800 14px var(--font-body); letter-spacing: 1px; text-transform: uppercase; color: var(--sheet-muted); }
.go-meta { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; font-size: 15px; margin-bottom: 6px; }
.go-new { color: var(--go-accent, #E8342E); }
.go-save { text-align: center; font: 700 13px var(--font-body); color: var(--sheet-muted); margin-bottom: 8px; }

/* toast + confetti */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 80;
  max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 14px;
  background: #111; color: #fff; font: 700 15px system-ui, sans-serif;
  transform: translate(-50%, 20px); opacity: 0; transition: 0.25s;
}
.toast.is-in { transform: translate(-50%, 0); opacity: 1; }
#confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 60; pointer-events: none; }

/* ---------- keyboard open: give the space to the silhouette and the input ------ */
.kb-open .game .stage { min-height: 110px; }
.kb-open .game [data-role="hint"] { min-height: 40px; }

/* ---------- animations ---------------------------------------------------------- */
@keyframes wtp-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }
@keyframes wtp-pulse { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes wtp-flash { 0% { opacity: 0; } 18% { opacity: 1; } 100% { opacity: 0; } }
@keyframes wtp-pop { 0% { transform: scale(0.6); } 100% { transform: scale(1); } }
@keyframes wtp-slide-up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes wtp-lifepop { 0% { transform: scale(1); } 30% { transform: scale(1.5); } 100% { transform: scale(0.85); } }

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