:root {
  color-scheme: light;
  --ink: #2c2c2c;
  --muted: #6d6f70;
  --paper: #ffffff;
  --panel: #ffffff;
  --line: #d3d3d3;
  --red: #ed6767;
  --orange: #eeb75f;
  --yellow: #eceb67;
  --green: #289a48;
  --blue: #adaed7;
  --violet: #713c97;
  --trust: #289a48;
  --shadow: 0 18px 52px rgba(44, 44, 44, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: Poppins, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(241, 241, 241, 0.98)),
    repeating-linear-gradient(90deg, rgba(237, 103, 103, 0.04) 0 1px, transparent 1px 76px);
}

button,
input,
a {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.hidden {
  display: none !important;
}

.topbar,
.game-shell {
  width: min(1220px, calc(100% - 28px));
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 0;
}

.back-link {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  text-decoration: none;
  font-weight: 800;
}

.title-lockup {
  text-align: right;
}

.title-lockup span,
.title-lockup small {
  display: block;
}

.title-lockup span {
  font-weight: 900;
}

.title-lockup small {
  color: var(--muted);
}

.partner-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 8px 22px rgba(44, 44, 44, 0.08);
}

.partner-lockup span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.partner-lockup img {
  display: block;
  width: auto;
  max-width: 128px;
  height: 34px;
  object-fit: contain;
}

.intro-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 28px;
  align-items: center;
  min-height: calc(100vh - 82px);
  padding: 32px 0 56px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--red);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p,
li {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(2.35rem, 7vw, 5.2rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.15;
  letter-spacing: 0;
}

.intro-panel p:not(.eyebrow),
#chapter-copy {
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.6;
}

.preview-note {
  max-width: 720px;
  padding: 12px 14px;
  border-left: 5px solid var(--red);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.origin-card {
  display: grid;
  gap: 12px;
  max-width: 620px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 32px rgba(44, 44, 44, 0.1);
}

.origin-card span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 900;
  text-transform: uppercase;
}

.origin-card div {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.origin-card img {
  display: block;
  width: auto;
  max-width: min(220px, 100%);
  height: 56px;
  object-fit: contain;
}

.town-form,
.panel-card,
.resource-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 36px rgba(23, 33, 38, 0.1);
}

.town-form {
  padding: 20px;
}

.town-form label {
  display: block;
  margin-bottom: 9px;
  font-weight: 900;
}

.town-row {
  display: flex;
  gap: 10px;
}

.town-row input {
  min-width: 0;
  flex: 1;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.town-row button,
.primary-button,
.secondary-button,
.choice-grid button {
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 900;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.town-row button:hover,
.town-row button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible,
.secondary-button:hover,
.secondary-button:focus-visible,
.choice-grid button:hover,
.choice-grid button:focus-visible,
.back-link:hover,
.back-link:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px rgba(23, 33, 38, 0.16);
}

.form-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.play-panel {
  padding-bottom: 32px;
}

.hud {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(360px, 1fr);
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}

.hud h1 {
  font-size: clamp(2.1rem, 5.4vw, 4.4rem);
}

#chapter-copy {
  margin: 12px 0 0;
}

.resource-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.resource-card {
  min-height: 108px;
  padding: 12px;
}

.resource-card span,
.resource-card strong,
.resource-card small {
  display: block;
}

.resource-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.resource-card strong {
  margin-top: 6px;
  font-size: 1.4rem;
}

.resource-card small {
  margin-top: 8px;
  color: var(--muted);
}

.resource-card.future {
  opacity: 0.7;
}

.meter {
  height: 9px;
  overflow: hidden;
  margin-top: 12px;
  border-radius: 999px;
  background: #ece5d9;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--orange), var(--yellow), var(--green), var(--blue), var(--violet));
  transition: width 500ms ease;
}

.trust-card .meter span {
  background: var(--trust);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 18px;
  align-items: start;
}

.diorama-panel {
  min-width: 0;
}

.diorama {
  position: relative;
  width: 100%;
  min-height: 590px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #b6dff1;
  box-shadow: var(--shadow);
}

.sky {
  position: absolute;
  inset: 0 0 54%;
  background: linear-gradient(180deg, #adaed7, #d9daf0);
}

.buildings {
  position: absolute;
  inset: 18% 5% auto;
  display: grid;
  grid-template-columns: 1.2fr 0.95fr 1.05fr 1fr;
  gap: 12px;
  align-items: end;
  height: 24%;
}

.building {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 100%;
  padding: 10px 6px;
  border: 3px solid rgba(23, 33, 38, 0.72);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  color: #223039;
  font-size: clamp(0.72rem, 1.6vw, 0.92rem);
  text-align: center;
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.52) 0 12px, transparent 12px 24px), #eeb75f;
}

.school {
  height: 84%;
  background-color: #ed6767;
}

.shop {
  height: 72%;
  background-color: #93cc86;
}

.library {
  height: 90%;
  background-color: #adaed7;
}

.square {
  position: absolute;
  inset: 39% 6% 23%;
  border: 3px solid rgba(23, 33, 38, 0.2);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.24) 0 1px, transparent 1px 52px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.2) 0 1px, transparent 1px 42px),
    #c9d6a8;
}

.stage {
  position: absolute;
  left: 7%;
  bottom: 18%;
  width: 25%;
  min-width: 118px;
  height: 44%;
  animation: popIn 280ms ease both;
}

.stage-roof {
  position: absolute;
  inset: 0 4% auto;
  height: 42%;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: linear-gradient(90deg, var(--red), var(--orange), var(--yellow), var(--green), var(--blue), var(--violet));
  border: 3px solid rgba(23, 33, 38, 0.72);
  border-bottom: 0;
}

.stage-deck {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  height: 62%;
  place-items: center;
  border: 3px solid rgba(23, 33, 38, 0.72);
  border-radius: 0 0 8px 8px;
  background: #5b463a;
  color: #fff;
  font-weight: 900;
}

.dance-floor {
  position: absolute;
  left: 36%;
  right: 23%;
  bottom: 14%;
  height: 54%;
  border: 2px dashed rgba(23, 33, 38, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
}

.tent {
  position: absolute;
  display: grid;
  place-items: end center;
  width: 18%;
  min-width: 78px;
  height: 38%;
  padding-bottom: 8px;
  border: 2px solid rgba(23, 33, 38, 0.5);
  border-radius: 8px 8px 4px 4px;
  background: linear-gradient(135deg, #fff 0 33%, #efc84b 33% 66%, #fff 66%);
  font-size: 0.82rem;
  font-weight: 900;
}

.tent-a {
  right: 4%;
  bottom: 48%;
}

.tent-b {
  right: 7%;
  bottom: 7%;
  background: linear-gradient(135deg, #fff 0 33%, #65ad74 33% 66%, #fff 66%);
}

.table {
  position: absolute;
  width: 8%;
  min-width: 34px;
  height: 14%;
  border: 2px solid rgba(23, 33, 38, 0.45);
  border-radius: 8px;
  background: #f8efe0;
}

.table-a {
  left: 39%;
  top: 18%;
}

.table-b {
  left: 57%;
  top: 20%;
}

.parade-street {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 24%;
  background:
    repeating-linear-gradient(90deg, transparent 0 38px, rgba(255, 255, 255, 0.14) 38px 40px),
    #7f776c;
}

.route-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  background: repeating-linear-gradient(90deg, #f8efe0 0 34px, transparent 34px 62px);
}

.walker-lane {
  position: absolute;
  inset: 0;
}

.person {
  position: absolute;
  bottom: 32px;
  left: -52px;
  width: 26px;
  height: 48px;
  border-radius: 14px 14px 6px 6px;
  background: var(--shirt, #276f9c);
  border: 2px solid rgba(23, 33, 38, 0.6);
  animation: walkBy var(--duration, 9s) linear forwards;
}

.person::before {
  content: "";
  position: absolute;
  top: -18px;
  left: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(23, 33, 38, 0.55);
  background: var(--skin, #c98d61);
}

.person.dancer {
  animation: joinDance 900ms ease forwards, danceBob 620ms ease-in-out 900ms infinite alternate;
  z-index: 3;
}

.control-panel {
  display: grid;
  gap: 14px;
}

.panel-card {
  padding: 16px;
}

.step-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 16px;
  padding-left: 20px;
  color: var(--muted);
}

.step-list li {
  line-height: 1.42;
}

.step-list li.current {
  color: var(--ink);
  font-weight: 900;
}

.step-list li.done {
  color: var(--trust);
  font-weight: 900;
}

.primary-button,
.secondary-button {
  width: 100%;
}

.primary-button:disabled {
  opacity: 0.62;
  cursor: default;
  transform: none;
}

.secondary-button {
  background: #fff;
  color: var(--ink);
}

.footer-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.footer-actions button,
.modal-close,
.support-links a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
}

.footer-actions button:first-child,
.support-links a:first-child {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.info-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(44, 44, 44, 0.62);
}

.modal-panel {
  position: relative;
  width: min(720px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  overflow: auto;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-panel h2 {
  max-width: 620px;
  font-size: clamp(1.5rem, 4vw, 2.4rem);
}

.modal-panel p {
  color: var(--muted);
  line-height: 1.64;
}

.modal-close {
  float: right;
  margin-left: 14px;
}

.support-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 18px 0;
}

.modal-note {
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
}

.choice-grid {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.choice-grid button {
  justify-content: center;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.choice-grid button.selected {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.organizer-card {
  border-color: rgba(31, 122, 105, 0.48);
}

.organizer-card p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.58;
}

.safety-footer {
  width: min(1220px, calc(100% - 28px));
  margin: 0 auto;
  padding: 0 0 28px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.safety-footer p {
  margin: 0;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes walkBy {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(calc(100vw + 170px));
  }
}

@keyframes joinDance {
  to {
    left: var(--dance-left, 52%);
    bottom: var(--dance-bottom, 210px);
  }
}

@keyframes danceBob {
  from {
    transform: translateY(0) rotate(-2deg);
  }
  to {
    transform: translateY(-8px) rotate(2deg);
  }
}

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

@media (max-width: 980px) {
  .intro-panel,
  .hud,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .resource-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .title-lockup {
    text-align: left;
  }

  .partner-lockup {
    align-items: flex-start;
    flex-direction: column;
    width: 100%;
  }

  .partner-lockup img {
    max-width: 190px;
  }

  .modal-panel {
    padding: 18px;
  }

  .modal-close {
    float: none;
    width: 100%;
    margin: 0 0 14px;
  }

  .footer-actions button,
  .support-links a {
    width: 100%;
  }

  h1 {
    font-size: 2.35rem;
  }

  .town-row {
    flex-direction: column;
  }

  .resource-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .diorama {
    min-height: 520px;
  }

  .buildings {
    inset-inline: 3%;
    gap: 6px;
  }

  .building {
    padding-inline: 3px;
    font-size: 0.68rem;
  }

  .square {
    inset: 37% 3% 25%;
  }

  .stage {
    left: 5%;
    min-width: 96px;
  }

  .dance-floor {
    left: 33%;
    right: 18%;
  }

  .tent {
    min-width: 62px;
    font-size: 0.72rem;
  }
}

@media (max-width: 390px) {
  .resource-grid {
    grid-template-columns: 1fr;
  }

  .diorama {
    min-height: 500px;
  }
}
