* {
  box-sizing: border-box;
}

:root {
  --ink: #1b120d;
  --paper: #f1dfb5;
  --paper-dark: #d2b476;
  --rust: #8d2b1f;
  --rust-dark: #641b13;
  --gold: #d7a943;
  --cream: #fff2cf;
  --wood: #3a2117;
  --wood-2: #24140f;
  --muted: #bba57e;
}

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

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.05), transparent 34rem),
    linear-gradient(#25160f, #120b08);
  color: var(--cream);
}

button {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.topbar,
.leaderboard-card,
.hud,
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar {
  gap: 16px;
  margin-bottom: 14px;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.6rem);
  letter-spacing: 0.02em;
}

h2 {
  margin-bottom: 10px;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--gold);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.game-card,
.leaderboard-card {
  border: 1px solid rgba(241,223,181,0.25);
  background: rgba(51, 29, 19, 0.84);
  box-shadow: 0 22px 60px rgba(0,0,0,0.32);
}

.game-card {
  overflow: hidden;
  border-radius: 18px;
}

.hud {
  gap: 8px;
  padding: 12px;
  background: linear-gradient(180deg, #4b2b1c, #2f1a12);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.hud div {
  min-width: 0;
  flex: 1;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(0,0,0,0.16);
}

.hud span,
.hud strong {
  display: block;
}

.hud span {
  color: var(--muted);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.hud strong {
  margin-top: 2px;
  font-size: 1rem;
}

.canvas-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #21140f;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  cursor: crosshair;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 9, 6, 0.68);
  backdrop-filter: blur(3px);
}

.hidden {
  display: none !important;
}

.panel {
  width: min(620px, 94%);
  padding: clamp(20px, 4vw, 36px);
  border: 2px solid var(--paper-dark);
  border-radius: 16px;
  color: var(--ink);
  background:
    linear-gradient(rgba(255,255,255,0.16), rgba(255,255,255,0)),
    var(--paper);
  box-shadow: 0 24px 70px rgba(0,0,0,0.48);
  text-align: center;
}

.panel h2 {
  font-size: clamp(1.7rem, 4vw, 2.6rem);
}

.panel p:not(.eyebrow) {
  line-height: 1.55;
}

.primary,
.secondary,
.upgrade-btn,
.close-btn {
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.primary {
  min-width: 160px;
  padding: 12px 18px;
  color: #fff5dc;
  background: linear-gradient(var(--rust), var(--rust-dark));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
  font-weight: 800;
}

.primary:hover,
.primary:focus-visible {
  filter: brightness(1.12);
}

.secondary {
  padding: 10px 14px;
  color: var(--cream);
  background: transparent;
  border: 1px solid rgba(241,223,181,0.38);
}

.secondary:hover,
.secondary:focus-visible {
  background: rgba(255,255,255,0.07);
}

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

.upgrade-btn {
  min-height: 118px;
  padding: 12px;
  background: #fff7df;
  border: 1px solid #c79d55;
  color: var(--ink);
}

.upgrade-btn:hover:not(:disabled),
.upgrade-btn:focus-visible:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 7px 18px rgba(80, 45, 20, 0.16);
}

.upgrade-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.upgrade-btn span,
.upgrade-btn small,
.upgrade-btn strong {
  display: block;
}

.upgrade-btn span {
  font-size: 1.05rem;
  font-weight: 800;
}

.upgrade-btn small {
  margin: 7px 0;
}

.upgrade-btn strong {
  color: var(--rust);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.78rem;
}

.status-row {
  gap: 14px;
  padding: 11px 14px;
  background: #21130e;
  color: var(--muted);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.82rem;
}

.status-row p {
  margin: 0;
}

.legend {
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--rust);
}

.leaderboard-card {
  gap: 20px;
  margin-top: 16px;
  padding: 18px;
  border-radius: 16px;
}

.leaderboard-card h2 {
  margin-bottom: 0;
}

#mis-leaderboard {
  flex: 1;
  min-width: 220px;
}

dialog {
  width: min(600px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 16px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 28px 90px rgba(0,0,0,0.65);
}

dialog::backdrop {
  background: rgba(0,0,0,0.7);
}

.dialog-inner {
  position: relative;
  padding: 28px;
  line-height: 1.55;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 38px;
  height: 38px;
  background: rgba(0,0,0,0.08);
  color: var(--ink);
  font-size: 1.5rem;
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 12px, 1180px);
    padding-top: 10px;
  }

  .topbar {
    align-items: flex-end;
  }

  .hud {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .hud div:nth-child(4),
  .hud div:nth-child(5) {
    grid-column: span 1;
  }

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

  .upgrade-btn {
    min-height: 86px;
  }

  .panel {
    max-height: 92%;
    overflow: auto;
  }

  .status-row,
  .leaderboard-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .legend {
    white-space: normal;
  }
}
