:root {
  color-scheme: dark;
  --bg: #21170f;
  --panel: #302116;
  --panel-2: #3d2a1c;
  --line: #6b4a31;
  --text: #fff3dc;
  --muted: #d9bd91;
  --accent: #ffd166;
  --accent-2: #9bd67d;
  --danger: #d94f45;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 8%, rgba(255, 184, 108, 0.18), transparent 20rem),
    radial-gradient(circle at 88% 14%, rgba(155, 214, 125, 0.14), transparent 22rem),
    linear-gradient(180deg, #1d140d 0%, #2d1d13 100%);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button {
  font: inherit;
}

.shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 32px);
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(34px, 6vw, 64px);
  line-height: 1;
}

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

.game-logo {
  display: block;
  width: min(520px, 100%);
  height: auto;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

h2 {
  margin-bottom: 10px;
  font-size: 18px;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.stats span,
.meters div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(48, 33, 22, 0.82);
  color: var(--text);
}

.stats span {
  padding: 10px 12px;
  font-weight: 900;
}

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

body[data-screen="start"] .game-layout,
body[data-screen="select"] .game-layout,
body[data-screen="guide"] .game-layout,
body[data-screen="result"] .game-layout {
  grid-template-columns: minmax(0, 720px);
  justify-content: center;
}

body[data-screen="start"] .panel,
body[data-screen="select"] .panel,
body[data-screen="guide"] .panel,
body[data-screen="result"] .panel,
body[data-screen="start"] .touch-pad,
body[data-screen="select"] .touch-pad,
body[data-screen="guide"] .touch-pad,
body[data-screen="result"] .touch-pad {
  display: none;
}

body[data-screen="start"] .stats,
body[data-screen="select"] .stats,
body[data-screen="guide"] .stats,
body[data-screen="result"] .stats {
  display: none;
}

.board-wrap {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #140e09;
  box-shadow: var(--shadow);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 1;
  background: #2b1d13;
}

.message {
  position: absolute;
  inset: auto 18px 18px;
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 209, 102, 0.5);
  border-radius: 8px;
  background: rgba(29, 20, 13, 0.92);
  box-shadow: var(--shadow);
}

.screen-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: clamp(14px, 4vw, 28px);
  background: rgba(20, 14, 9, 0.82);
}

.screen-layer[hidden] {
  display: none;
}

.screen-card {
  display: grid;
  gap: 9px;
  width: min(520px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: clamp(16px, 4vw, 24px);
  border: 1px solid rgba(255, 209, 102, 0.46);
  border-radius: 8px;
  background: rgba(48, 33, 22, 0.96);
  box-shadow: var(--shadow);
}

.screen-card[hidden] {
  display: none;
}

.screen-card h2 {
  margin: 0;
  font-size: clamp(24px, 5vw, 38px);
  line-height: 1;
}

.screen-card p {
  margin-bottom: 0;
  line-height: 1.32;
}

.screen-card ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.4;
}

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

.screen-actions button,
.stage-grid button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #201408;
  font-weight: 900;
  cursor: pointer;
}

.screen-actions button:nth-child(2) {
  background: #f4d7a1;
}

.screen-actions button:nth-child(3) {
  background: var(--accent-2);
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.stage-grid button.locked {
  background: #5a4635;
  color: #b7a085;
}

.message[hidden] {
  display: none;
}

.message strong {
  color: var(--accent);
  font-size: 20px;
}

.message span {
  color: var(--text);
}

.message button {
  display: none;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #201408;
  font-weight: 900;
  cursor: pointer;
}

.message.paused button {
  display: block;
}

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

.panel section {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(48, 33, 22, 0.88);
  box-shadow: var(--shadow);
}

.ad-card {
  display: grid;
  gap: 8px;
}

.ad-card > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.ad-box {
  display: grid;
  place-items: center;
  min-height: 90px;
  border: 1px dashed rgba(217, 189, 145, 0.5);
  border-radius: 8px;
  background: rgba(20, 14, 9, 0.38);
  text-align: center;
}

.ad-box p {
  max-width: 240px;
  margin: 0;
  font-size: 13px;
}

.meters {
  display: grid;
  gap: 8px;
}

.meters div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  min-width: 0;
}

.meters span {
  color: var(--muted);
  font-weight: 800;
}

.meters strong {
  color: var(--accent);
}

.house-card {
  display: grid;
  gap: 12px;
}

.house-card.build-flash {
  animation: buildFlash 0.9s ease;
}

@keyframes buildFlash {
  0% {
    box-shadow: 0 0 0 rgba(255, 209, 102, 0);
  }
  35% {
    box-shadow: 0 0 36px rgba(255, 209, 102, 0.55);
  }
  100% {
    box-shadow: var(--shadow);
  }
}

.house-preview {
  position: relative;
  min-height: 154px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(244, 215, 161, 0.08), transparent),
    #21170f;
  overflow: hidden;
}

.house-preview::before {
  content: "";
  position: absolute;
  inset: auto 18px 18px;
  height: 20px;
  border-radius: 999px;
  background: #5b3924;
}

.house-part {
  position: absolute;
  opacity: 0.18;
  transform: scale(0.96);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.house-part.built {
  opacity: 1;
  transform: scale(1);
}

.part-foundation {
  left: 44px;
  bottom: 32px;
  width: 132px;
  height: 18px;
  border-radius: 6px;
  background: #a56b3b;
}

.part-door {
  left: 92px;
  bottom: 50px;
  width: 34px;
  height: 46px;
  border-radius: 16px 16px 4px 4px;
  background: #8a4f2b;
}

.part-storage {
  left: 48px;
  bottom: 52px;
  width: 42px;
  height: 36px;
  border-radius: 8px;
  background: #c47b3d;
}

.part-roof {
  left: 38px;
  bottom: 90px;
  width: 148px;
  height: 46px;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: #69b86f;
}

.part-lamp {
  left: 136px;
  bottom: 58px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #f8e16c;
  box-shadow: 0 0 16px rgba(248, 225, 108, 0.8);
}

.part-pantry {
  left: 130px;
  bottom: 52px;
  width: 42px;
  height: 36px;
  border-radius: 8px;
  background: #a7a9ad;
}

.part-window {
  left: 66px;
  bottom: 64px;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: #4aa3c7;
}

.part-garden {
  right: 42px;
  bottom: 36px;
  width: 46px;
  height: 20px;
  border-radius: 50%;
  background: #69b86f;
}

.part-star {
  right: 58px;
  top: 34px;
  width: 24px;
  height: 24px;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 39% 35%);
  background: #f8e16c;
}

.part-finish {
  left: 22px;
  top: 22px;
  width: 36px;
  height: 36px;
  border: 4px solid #ffd166;
  border-radius: 50%;
}

.build-bar {
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #21170f;
  overflow: hidden;
}

.build-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffd166, #9bd67d);
  transition: width 0.2s ease;
}

.house-card p {
  margin: 0;
}

.buttons {
  display: grid;
  gap: 10px;
}

.buttons button,
.touch-pad button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #201408;
  font-weight: 900;
  cursor: pointer;
}

.buttons button:nth-child(2) {
  background: #f4d7a1;
}

.buttons button:nth-child(3) {
  background: #c9a56c;
}

.buttons button:nth-child(4) {
  background: var(--accent-2);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.touch-pad {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 14px;
}

@media (max-width: 900px) {
  .topbar,
  .game-layout {
    grid-template-columns: 1fr;
  }

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

  .stats {
    justify-content: start;
    width: 100%;
  }

  .panel {
    grid-template-columns: 1fr;
  }

  .touch-pad {
    display: grid;
  }
}

@media (max-width: 520px) {
  .shell {
    width: 100vw;
    max-width: 390px;
    margin: 0;
    padding: 12px;
  }

  h1 {
    font-size: clamp(32px, 9vw, 42px);
  }

  .board-wrap,
  .panel section {
    min-width: 0;
  }

  .board-wrap {
    width: 100%;
    max-width: 100%;
  }

  .stats span {
    flex: none;
    min-width: 0;
    padding: 10px 6px;
    text-align: center;
    font-size: 15px;
  }

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

  .touch-pad {
    grid-template-columns: 1fr 1fr;
  }

  .screen-layer {
    padding: 12px;
  }

  .screen-card {
    gap: 8px;
    padding: 12px;
  }

  .screen-actions {
    grid-template-columns: 1fr;
  }

  .stage-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
  }

  .stage-grid button {
    min-height: 38px;
    font-size: 13px;
  }
}
