:root {
  --page: #ebe5dc;
  --paper: #f5f0e7;
  --paper-2: #fbf8f2;
  --board: #707070;
  --board-deep: #2f2f2f;
  --frame: #979797;
  --ink: #242424;
  --muted: #666666;
  --accent: #854632;
  --plum: #43163b;
  --olive: #9ec96b;
  --line: #c26758;
  --shadow: 0 28px 60px rgba(32, 32, 32, 0.12);
  --radius-xl: 34px;
  --radius-lg: 24px;
  --radius-md: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Trebuchet MS", "Gill Sans", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(158, 201, 107, 0.18), transparent 26%),
    radial-gradient(circle at bottom right, rgba(133, 70, 50, 0.12), transparent 24%),
    linear-gradient(180deg, #f8f5ef 0%, var(--page) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.14;
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.16) 1px, transparent 1px);
  background-size: 34px 34px;
}

.page-shell {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.asset-bank {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.panel {
  width: min(100%, 1120px);
  background: rgba(245, 240, 231, 0.92);
  border: 1px solid rgba(36, 36, 36, 0.08);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.panel--start {
  padding: 26px;
  display: grid;
  gap: 22px;
}

.panel--game {
  width: min(100%, 1240px);
  padding: 18px;
  height: min(calc(100svh - 48px), 1080px);
}

.start-copy {
  display: grid;
  gap: 10px;
}

.brand-logo {
  width: min(420px, 100%);
  display: block;
  mix-blend-mode: multiply;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
.modal__card h2,
.game-over h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0.02em;
}

h1 {
  font-size: clamp(2.8rem, 6vw, 4.1rem);
  line-height: 0.96;
}

.lede,
.mini-note,
.modal__intro,
.modal__list,
.game-over p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

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

.start-card {
  background: var(--paper-2);
  border-radius: 28px;
  border: 1px solid rgba(36, 36, 36, 0.08);
  box-shadow: 0 18px 36px rgba(46, 46, 46, 0.08);
}

.start-card--form {
  padding: 22px;
  display: grid;
  gap: 16px;
  align-content: start;
}

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

.field span,
.stat-chip__label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field input {
  width: 100%;
  padding: 15px 16px;
  border: 1px solid rgba(36, 36, 36, 0.12);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  outline: none;
}

.field input:focus {
  border-color: rgba(133, 70, 50, 0.6);
  box-shadow: 0 0 0 4px rgba(133, 70, 50, 0.14);
}

.highscore-preview {
  margin: 0;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--plum);
  font-weight: 800;
}

.start-actions {
  display: flex;
  gap: 12px;
}

.primary-button,
.icon-button {
  border: none;
  cursor: pointer;
  font: inherit;
}

.primary-button {
  flex: 1;
  padding: 15px 18px;
  color: #fffdf9;
  font-weight: 800;
  letter-spacing: 0.04em;
  border-radius: 999px;
  background: linear-gradient(180deg, #a95b42 0%, var(--accent) 100%);
  box-shadow: 0 14px 26px rgba(133, 70, 50, 0.24);
}

.icon-button {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #ffffff;
  color: var(--plum);
  font-size: 1.3rem;
  font-weight: 800;
  box-shadow: 0 10px 18px rgba(36, 36, 36, 0.1);
}

.start-card--preview {
  padding: 18px;
}

.mock-board {
  position: relative;
  height: 100%;
  min-height: 320px;
  padding: 18px;
  border-radius: 26px;
  background: linear-gradient(180deg, #787878 0%, #696969 100%);
  overflow: hidden;
}

.mock-board::before,
.mock-board::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.12);
  filter: blur(2px);
}

.mock-board::before {
  width: 160px;
  height: 52px;
  border-radius: 999px;
  top: 20px;
  left: 22px;
}

.mock-board::after {
  width: 180px;
  height: 58px;
  border-radius: 999px;
  top: 64px;
  right: 28px;
}

.mock-board__badge,
.mock-board__preview {
  position: absolute;
  z-index: 2;
  background: #f8f4ee;
  border-radius: 18px;
  box-shadow: 0 12px 20px rgba(20, 20, 20, 0.12);
}

.mock-board__badge {
  top: 18px;
  right: 18px;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mock-board__preview {
  top: 58px;
  right: 18px;
  width: 94px;
  height: 94px;
  display: grid;
  place-items: center;
}

.mock-board__preview img,
.mock-board__item {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.mock-board__playfield {
  position: relative;
  z-index: 1;
  height: 100%;
  border-radius: 22px;
  overflow: hidden;
}

.mock-board__line {
  position: absolute;
  left: 52px;
  right: 52px;
  top: 112px;
  border-top: 4px dashed var(--line);
}

.mock-board__item {
  position: absolute;
}

.mock-board__item--one {
  left: 76px;
  bottom: 78px;
}

.mock-board__item--two {
  left: 128px;
  bottom: 72px;
}

.mock-board__item--three {
  right: 88px;
  bottom: 84px;
}

.mock-board__bin {
  position: absolute;
  inset: 52px 42px 18px;
  border-radius: 22px 22px 34px 34px;
  background: #3a3a3a;
  border: 16px solid #8e8e8e;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.mock-board__label {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: min(70%, 260px);
  padding: 16px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
  color: #ece6d6;
  text-align: center;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.game-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
  height: 100%;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto;
  gap: 14px;
}

.hud-stack {
  display: grid;
  gap: 12px;
}

.stat-chip,
.fact-banner {
  background: var(--paper-2);
  border: 1px solid rgba(36, 36, 36, 0.08);
  border-radius: 22px;
  box-shadow: 0 14px 24px rgba(46, 46, 46, 0.08);
}

.stat-chip {
  padding: 14px 16px;
  display: grid;
  gap: 6px;
}

.stat-chip strong {
  font-size: 1.22rem;
}

.stat-chip--next {
  justify-items: center;
  text-align: center;
}

.stat-chip--next img {
  width: 82px;
  height: 82px;
  object-fit: contain;
}

.fact-banner {
  padding: 12px 14px;
  color: var(--plum);
  font-size: 0.95rem;
  line-height: 1.45;
  transition: opacity 180ms ease, transform 180ms ease;
}

.fact-banner.is-fading {
  opacity: 0.72;
  transform: translateY(-1px);
}

.play-column {
  min-width: 0;
  min-height: 0;
}

.canvas-frame {
  position: relative;
  background: linear-gradient(180deg, #818181 0%, #707070 100%);
  border-radius: 34px;
  padding: 14px;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
}

.canvas-frame::before,
.canvas-frame::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.canvas-frame::before {
  width: 180px;
  height: 56px;
  top: 26px;
  left: 28px;
}

.canvas-frame::after {
  width: 210px;
  height: 62px;
  top: 40px;
  right: 34px;
}

#p5-holder {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  height: 100%;
}

#p5-holder canvas {
  display: block;
  width: auto !important;
  height: auto !important;
  max-width: 100% !important;
  max-height: calc(100svh - 124px) !important;
  border-radius: 26px;
}

.game-over {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: min(92%, 360px);
  display: grid;
  gap: 8px;
  justify-items: center;
  text-align: center;
  padding: 24px 22px;
  border-radius: 26px;
  background: rgba(248, 244, 238, 0.98);
  border: 1px solid rgba(36, 36, 36, 0.08);
  box-shadow: 0 24px 44px rgba(20, 20, 20, 0.18);
}

.game-over__eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(32, 32, 32, 0.42);
  backdrop-filter: blur(8px);
}

.modal__card {
  position: relative;
  width: min(100%, 1060px);
  max-height: min(90svh, 880px);
  overflow: auto;
  padding: 26px 24px 24px;
  border-radius: 30px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.modal__close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.modal__list {
  margin: 16px 0 0;
  padding-left: 22px;
}

.sequence-board {
  margin-top: 22px;
  padding: 20px;
  border-radius: 24px;
  background: var(--paper-2);
  border: 1px solid rgba(36, 36, 36, 0.08);
}

.sequence-board h3 {
  margin: 0 0 16px;
  color: var(--plum);
  font-size: 1.08rem;
}

.merge-sequence {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.merge-tile {
  width: 88px;
  min-height: 98px;
  padding: 10px 8px;
  border-radius: 18px;
  background: #ffffff;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 8px;
  text-align: center;
  box-shadow: 0 10px 18px rgba(46, 46, 46, 0.08);
}

.merge-tile img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.merge-tile span {
  font-size: 0.78rem;
  line-height: 1.15;
  color: var(--muted);
  font-weight: 700;
}

.sequence-arrow {
  color: var(--plum);
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1;
}

.is-hidden {
  display: none !important;
}

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

  .panel--start,
  .panel--game {
    padding: 18px;
  }

  .panel--game {
    height: auto;
  }

  .sidebar {
    grid-template-rows: auto auto;
  }

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

  .stat-chip--next {
    grid-column: span 2;
  }

  #p5-holder canvas {
    width: 100% !important;
    max-height: calc(74svh) !important;
  }
}

@media (max-width: 640px) {
  .page-shell {
    padding: 12px 8px 18px;
  }

  .panel--start,
  .panel--game {
    padding: 14px;
  }

  .start-card--preview {
    padding: 12px;
  }

  .mock-board {
    min-height: 280px;
  }

  .mock-board__preview {
    width: 80px;
    height: 80px;
  }

  .mock-board__preview img,
  .mock-board__item {
    width: 52px;
    height: 52px;
  }

  .start-actions {
    flex-wrap: wrap;
  }

  .icon-button {
    width: 50px;
    height: 50px;
  }

  .hud-stack {
    grid-template-columns: 1fr;
  }

  .stat-chip--next {
    grid-column: auto;
  }

  .merge-sequence {
    gap: 8px;
  }

  .merge-tile {
    width: 80px;
    min-height: 92px;
  }
}
