:root {
  --ink: #2b2118;
  --cream: #fffaf0;
  --sand: #f3e6c8;
  --forest: #2f6f52;
  --leaf: #2f9467;
  --amber: #c8890a;
  --sun: #ffc233;
  --sun-deep: #e09500;
  --sun-ink: #4a2f00;
  --sky: #1468a8;
  --sky-bright: #3fa9f5;
  --coral: #d4536a;
  --panel: rgba(255, 250, 240, 0.94);
  --stage-max: 1280px;
  --font-display: "Fraunces", "Literata", Georgia, "Times New Roman", serif;
  --font-body: "Literata", Georgia, "Times New Roman", serif;
  --bs-body-font-family: var(--font-body);
  --bs-font-sans-serif: var(--font-body);
  --font-scale: 1;
  --hud-h: auto;
  --dialog-h: auto;
}

*,
*::before,
*::after { box-sizing: border-box; }

/* La escala A−/A+ vive en html. No pongas otro font-size en html o anula --font-scale. */
html {
  font-size: calc(1.05rem * var(--font-scale, 1));
}

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font-body);
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 214, 102, 0.55) 0%, transparent 42%),
    radial-gradient(circle at 88% 92%, rgba(120, 220, 255, 0.4) 0%, transparent 45%),
    linear-gradient(165deg, #dff3ff 0%, #eafbe7 46%, #fff3d1 100%);
}

.app-root {
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.game-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: var(--stage-max);
  width: 100%;
  margin: 0 auto;
  padding: max(0.5rem, env(safe-area-inset-top, 0px))
    max(0.5rem, env(safe-area-inset-right, 0px))
    max(0.5rem, env(safe-area-inset-bottom, 0px))
    max(0.5rem, env(safe-area-inset-left, 0px));
  gap: 0.35rem;
  min-height: 0;
  overflow: hidden;
}

#hud {
  flex-shrink: 0;
}

#dialog-panel {
  flex-shrink: 0;
  min-height: 0;
  max-height: min(32dvh, 11rem);
  overflow-y: auto;
}

#dialog-panel:empty {
  display: none;
}

html[data-font-scale-level="4"] #dialog-panel {
  max-height: min(30dvh, 10rem);
}

.stage-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.stage {
  position: relative;
  width: 100%;
  max-height: min(68dvh, 720px);
  aspect-ratio: 16 / 9;
  height: auto;
  margin-inline: auto;
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(42, 36, 28, 0.18);
  background: #cbb89a;
  container-type: size;
  container-name: stage;
  --cast-bottom: 1%;
  --cast-adult-h: 50%;
  --cast-youth-h: 38%;
  --cast-bird-h: 31.2%;
  --cast-adult-w: min(22%, 210px);
}

.screen-root,
.screen {
  position: absolute;
  inset: 0;
}

.screen { display: none; }
.screen.is-active { display: block; }

.bg-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.boot-root {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

h1, h2, h3, h4, h5, h6,
.display-font,
.h1, .h2, .h3, .h4, .h5, .h6,
.modal-title,
.offcanvas-title {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.btn {
  font-family: var(--font-display);
  min-height: 44px;
  font-weight: 700;
  border-radius: 999px;
  border-width: 2px;
  padding: 0.5rem 1.2rem;
  box-shadow: 0 4px 0 rgba(43, 33, 24, 0.16);
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 rgba(43, 33, 24, 0.16);
}

.btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(43, 33, 24, 0.16);
}

.btn:focus-visible {
  outline: 4px solid var(--sky-bright);
  outline-offset: 3px;
}

.btn:disabled,
.btn.disabled {
  opacity: 0.55;
  box-shadow: none;
  transform: none;
}

.btn-sm {
  min-height: 40px;
  font-size: 0.95rem;
  padding: 0.35rem 0.85rem;
}

.btn-primary {
  --bs-btn-color: var(--sun-ink);
  --bs-btn-bg: var(--sun);
  --bs-btn-border-color: var(--sun-deep);
  --bs-btn-hover-color: var(--sun-ink);
  --bs-btn-hover-bg: #ffd35c;
  --bs-btn-hover-border-color: var(--sun-deep);
  --bs-btn-active-color: var(--sun-ink);
  --bs-btn-active-bg: var(--sun-deep);
  --bs-btn-active-border-color: var(--sun-deep);
  --bs-btn-disabled-color: var(--sun-ink);
  --bs-btn-disabled-bg: var(--sun);
  --bs-btn-disabled-border-color: var(--sun-deep);
}

.btn-accent {
  background: var(--sun-ink);
  border-color: var(--sun-ink);
  color: var(--sun);
  font-weight: 800;
}

.btn-accent:hover:not(:disabled) {
  background: #6b4a00;
  border-color: #6b4a00;
  color: #ffd35c;
}

.btn-success {
  --bs-btn-color: #08402b;
  --bs-btn-bg: #43b581;
  --bs-btn-border-color: var(--leaf);
  --bs-btn-hover-color: #08402b;
  --bs-btn-hover-bg: #5fd39a;
  --bs-btn-hover-border-color: var(--leaf);
  --bs-btn-active-color: #08402b;
  --bs-btn-active-bg: #43b581;
  --bs-btn-active-border-color: var(--leaf);
  --bs-btn-disabled-color: #08402b;
  --bs-btn-disabled-bg: #43b581;
  --bs-btn-disabled-border-color: var(--leaf);
}

.btn-outline-primary {
  --bs-btn-color: var(--sky);
  --bs-btn-border-color: var(--sky-bright);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--sky);
  --bs-btn-hover-border-color: var(--sky);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #0e568c;
  --bs-btn-active-border-color: #0e568c;
  --bs-btn-disabled-color: var(--sky);
  --bs-btn-disabled-bg: transparent;
  --bs-btn-disabled-border-color: var(--sky-bright);
}

.btn-outline-secondary {
  --bs-btn-color: #5d5142;
  --bs-btn-border-color: #b9ae9c;
  --bs-btn-hover-color: var(--ink);
  --bs-btn-hover-bg: #fff4d6;
  --bs-btn-hover-border-color: #b9ae9c;
  --bs-btn-active-color: var(--ink);
  --bs-btn-active-bg: #ffe9b8;
  --bs-btn-active-border-color: #b9ae9c;
  --bs-btn-disabled-color: #5d5142;
  --bs-btn-disabled-bg: transparent;
  --bs-btn-disabled-border-color: #b9ae9c;
}

.modal-content,
.offcanvas {
  background: var(--cream);
  border: 3px solid rgba(43, 33, 24, 0.14);
  border-radius: 22px;
}

.modal-header,
.offcanvas-header {
  background: linear-gradient(180deg, #fff4d6 0%, #ffe9b8 100%);
  border-bottom: 3px solid rgba(43, 33, 24, 0.1);
}

.modal-title,
.offcanvas-title {
  color: #6b4a00;
}

#howtoModal .howto-dialog {
  width: min(34rem, calc(100vw - 1.25rem));
  max-width: calc(100vw - 1.25rem);
  margin-inline: auto;
}

#howtoModal .howto-card {
  border: 3px solid var(--forest, #2f5d4a);
  border-radius: 1.15rem;
  overflow: hidden;
  background: linear-gradient(180deg, #fffdf8, #f7f3eb);
}

#howtoModal .howto-header {
  align-items: center;
  gap: 0.75rem;
  padding: clamp(0.7rem, 2.5vw, 1rem) clamp(0.85rem, 3vw, 1.15rem);
  background: var(--forest, #2f5d4a);
  color: #fff;
  border-bottom: 0;
}

#howtoModal .howto-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  color: #fff;
  font-size: clamp(1.1rem, 3.2vw, 1.35rem);
}

#howtoModal .howto-title-icon {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
  border-radius: 0.6rem;
  background: rgba(255, 255, 255, 0.16);
  font-size: 1.05rem;
}

#howtoModal .howto-header .btn-close {
  filter: invert(1);
  opacity: 0.9;
}

#howtoModal .howto-body {
  padding: clamp(0.75rem, 2.5vw, 1rem);
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--ink, #2b2118);
}

#howtoModal .howto-lead {
  margin: 0 0 0.75rem;
}

#howtoModal .howto-steps,
#howtoModal .howto-controls {
  list-style: none;
  margin: 0;
  padding: 0;
}

#howtoModal .howto-steps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

#howtoModal .howto-steps li,
#howtoModal .howto-controls li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0;
  padding: 0.55rem 0.6rem;
  border-radius: 0.8rem;
  background: #fff;
  border: 2px solid rgba(47, 93, 74, 0.2);
  line-height: 1.35;
}

#howtoModal .howto-step-icon {
  display: grid;
  place-items: center;
  width: 1.85rem;
  height: 1.85rem;
  flex: 0 0 auto;
  border-radius: 0.55rem;
  background: var(--forest, #2f5d4a);
  color: #fff;
  font-size: 0.95rem;
}

#howtoModal .howto-controls-title {
  margin: 0.85rem 0 0.4rem;
  color: var(--forest, #2f5d4a);
  font-size: 1.02rem;
}

#howtoModal .howto-controls {
  display: grid;
  gap: 0.4rem;
}

#howtoModal .howto-controls .howto-step-icon {
  width: 1.65rem;
  height: 1.65rem;
  font-size: 0.82rem;
}

#howtoModal .howto-footer {
  padding: 0.65rem 0.85rem 0.9rem;
  border-top: 0;
  background: transparent;
}

#howtoModal .howto-ready {
  width: 100%;
  min-height: 2.6rem;
  border: 0;
  border-radius: 0.8rem;
  background: var(--forest, #2f5d4a);
  color: #fff;
  font-weight: 800;
}

#howtoModal .howto-ready:hover,
#howtoModal .howto-ready:focus {
  color: #fff;
  filter: brightness(1.06);
}

@media (max-width: 520px) {
  #howtoModal .howto-steps {
    grid-template-columns: 1fr;
  }
}

/* ---- Tablet ---- */
@media (max-width: 991.98px) {
  .stage-wrap {
    align-items: stretch;
  }
  .stage {
    aspect-ratio: auto;
    max-height: none;
    height: 100%;
  }
}

/* ---- Mobile portrait ---- */
@media (max-width: 575.98px) {
  .game-shell {
    padding: max(0.3rem, env(safe-area-inset-top, 0px))
      max(0.3rem, env(safe-area-inset-right, 0px))
      max(0.3rem, env(safe-area-inset-bottom, 0px))
      max(0.3rem, env(safe-area-inset-left, 0px));
    gap: 0.3rem;
  }
  .stage {
    aspect-ratio: auto;
    max-height: none;
    height: 100%;
    border-radius: 0.7rem;
  }
  #dialog-panel {
    max-height: min(34dvh, 12rem);
    overflow: auto;
  }
  .btn-row {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .btn-row .btn {
    width: auto;
    flex: 1 1 auto;
    min-width: 42%;
  }
}

/* ---- Extra-small phones ---- */
@media (max-width: 389px) {
  .game-shell {
    padding: max(0.15rem, env(safe-area-inset-top, 0px))
      max(0.15rem, env(safe-area-inset-right, 0px))
      max(0.15rem, env(safe-area-inset-bottom, 0px))
      max(0.15rem, env(safe-area-inset-left, 0px));
    gap: 0.2rem;
  }
  .stage {
    border-radius: 0.5rem;
  }
  .btn {
    min-height: 42px;
    font-size: 0.92rem;
    padding-inline: 0.75rem;
  }
  .btn-sm {
    min-height: 38px;
    font-size: 0.85rem;
    padding-inline: 0.5rem;
  }
}

/* ---- Mobile / tablet landscape ---- */
@media (max-height: 500px) and (orientation: landscape) {
  .game-shell {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(210px, 0.9fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "hud hud"
      "stage dialog";
    padding: 0.25rem;
    gap: 0.25rem;
    align-content: stretch;
  }
  #hud {
    grid-area: hud;
    flex: none;
    height: auto;
  }
  .stage-wrap {
    grid-area: stage;
    flex: none;
    min-width: 0;
    min-height: 0;
  }
  #dialog-panel {
    grid-area: dialog;
    flex: none;
    min-width: 0;
    max-height: none;
    align-self: stretch;
    overflow: auto;
  }
  .stage {
    aspect-ratio: auto;
    max-height: none;
    height: 100%;
  }
}

/* ---- Tablet landscape (medium height) ---- */
@media (min-height: 501px) and (max-height: 700px) and (orientation: landscape) {
  .game-shell {
    padding: 0.35rem;
    gap: 0.3rem;
  }
  .stage {
    aspect-ratio: auto;
    max-height: none;
    height: 100%;
  }
  #dialog-panel {
    max-height: min(28dvh, 180px);
    overflow: auto;
  }
}

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