:root {
  color-scheme: dark;
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, Helvetica, sans-serif;
  background: #120d0a;
  color: #f7efe2;
  --gold: #f6c445;
  --red: #e63946;
  --blue: #3b7dd8;
  --cream: #f4ebd8;
  --panel: #1c1410;
  --border: #4a3728;
  --muted: #b8a38d;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(ellipse at 50% 15%, rgba(180, 96, 36, 0.28), transparent 62%),
    radial-gradient(ellipse at 18% 85%, rgba(230, 57, 70, 0.14), transparent 48%),
    radial-gradient(ellipse at 82% 80%, rgba(59, 125, 216, 0.14), transparent 48%),
    #120d0a;
}

main {
  height: 100vh;
  height: 100dvh;
  max-width: 1280px;
  margin: auto;
  padding: 16px 24px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 12px;
}

header, footer {
  display: flex;
  justify-content: space-between;
  font: 10px monospace;
  letter-spacing: 2px;
  color: var(--muted);
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--gold); }

.heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0;
}

.eyebrow, .label {
  font: 10px monospace;
  letter-spacing: 2px;
  color: var(--muted);
}

.heading .eyebrow { margin: 0 0 8px; }

h1 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 32px;
  letter-spacing: -0.5px;
  line-height: 0.95;
  margin: 0;
  color: var(--gold);
  text-shadow: 0 2px 18px rgba(230, 57, 70, 0.35);
}

h1 span {
  font-family: monospace;
  font-size: 11px;
  letter-spacing: 4px;
  display: block;
  margin-top: 7px;
  color: var(--cream);
}

.heading-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.arcade-exit {
  font: 600 11px monospace;
  color: #ffb8b8;
  background: rgba(82, 22, 26, 0.65);
  border: 1px solid rgba(230, 57, 70, 0.45);
  padding: 8px 11px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  transition: border-color 0.14s, color 0.14s, background 0.14s, box-shadow 0.14s;
}

.arcade-exit:hover {
  border-color: var(--red);
  background: rgba(120, 28, 34, 0.85);
  color: #ffffff;
  box-shadow: 0 0 14px rgba(230, 57, 70, 0.3);
}

button {
  font: 600 12px monospace;
  color: #f4ebd8;
  background: rgba(38, 28, 22, 0.85);
  border: 1px solid #5e4736;
  padding: 9px 12px;
  cursor: pointer;
  border-radius: 7px;
  touch-action: none;
  transition: border-color 0.14s, color 0.14s, background 0.14s, transform 0.08s, box-shadow 0.14s;
}

button:hover {
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 14px rgba(246, 196, 69, 0.22);
}

button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.machine {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  min-height: 0;
}

.machine > aside {
  flex: 0 0 210px;
  min-width: 0;
}

.hud-left strong {
  display: block;
  font: 700 32px monospace;
  color: var(--gold);
  letter-spacing: -1px;
  text-shadow: 0 0 18px rgba(246, 196, 69, 0.35);
}

aside b {
  font: 700 17px monospace;
  color: var(--cream);
}

.hud-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

#cardsCount { color: var(--red); }
#replays { color: #7be495; }

.card-rack {
  margin-top: 12px;
  padding: 8px 6px;
  background: rgba(18, 32, 62, 0.65);
  border: 1px solid rgba(90, 130, 210, 0.45);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.card-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.card-row span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 24px;
  border-radius: 4px;
  font: 700 11px Georgia, serif;
  background: rgba(25, 22, 20, 0.78);
  color: #7d6d5d;
  border: 1px solid rgba(130, 110, 90, 0.35);
  transition: all 0.2s ease;
}

.card-row span.lit {
  background: linear-gradient(180deg, #fff9e6, #f8d878);
  color: #c81d25;
  border-color: #ffe28a;
  box-shadow: 0 0 10px rgba(255, 212, 96, 0.65);
}

.label { margin: 12px 0 4px; }

.rule {
  height: 1px;
  background: linear-gradient(90deg, rgba(246, 196, 69, 0.45), rgba(74, 55, 40, 0.25));
  margin: 14px 0;
}

#status {
  font: 600 12px monospace;
  color: #ffd97d;
  min-height: 36px;
  margin: 6px 0 10px;
  line-height: 1.4;
}

#start, #play {
  background: linear-gradient(135deg, #f6c445, #e68a1e);
  color: #1f1106;
  border: 0;
  font-weight: 700;
  box-shadow: 0 4px 18px rgba(246, 196, 69, 0.3);
}

#start:hover, #play:hover {
  color: #120802;
  box-shadow: 0 4px 24px rgba(246, 196, 69, 0.5);
}

.hud-left button {
  width: 100%;
  margin-top: 7px;
}

#table {
  position: relative;
  flex: 1 1 auto;
  height: 100%;
  max-width: 680px;
  min-width: 280px;
  min-height: 0;
  aspect-ratio: 560 / 760;
  background: radial-gradient(circle at 50% 32%, #241911, #0f0a07 80%);
  border: 2px solid #7d5b3e;
  border-radius: 24px;
  overflow: hidden;
  box-shadow:
    0 0 0 6px #1c130d,
    0 0 0 8px rgba(246, 196, 69, 0.18),
    0 24px 70px rgba(0, 0, 0, 0.8),
    inset 0 0 36px rgba(0, 0, 0, 0.55);
}

#table.special-lit {
  border-color: var(--red);
  box-shadow:
    0 0 0 6px #2a1012,
    0 0 28px rgba(230, 57, 70, 0.5),
    0 24px 70px rgba(0, 0, 0, 0.8);
}

#table canvas.gl-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

#table canvas.hud-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 42%, rgba(36, 22, 14, 0.90), rgba(16, 10, 7, 0.94));
  backdrop-filter: blur(4px);
}

#overlay p {
  font: 700 11px monospace;
  letter-spacing: 3px;
  color: var(--gold);
  margin: 0;
}

#overlay h2 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 42px;
  line-height: 1.04;
  letter-spacing: -1px;
  margin: 14px 0 12px;
  color: #fff6e6;
  text-shadow: 0 2px 24px rgba(230, 57, 70, 0.45);
}

#overlay span {
  font-size: 13px;
  line-height: 1.5;
  color: #d6c5b0;
  max-width: 340px;
  margin: 2px 12px 22px;
}

#overlay #play {
  padding: 13px 26px;
  font-size: 13px;
  letter-spacing: 0.5px;
}

.instructions .heart-mark {
  font-size: 34px;
  color: var(--red);
  line-height: 1;
  text-shadow: 0 0 16px rgba(230, 57, 70, 0.45);
}

.instructions .label { margin-top: 8px; }
.instructions h2 { font-family: Georgia, serif; font-size: 23px; letter-spacing: -0.5px; margin: 6px 0 10px; line-height: 1.08; color: var(--cream); }
.instructions p { font-size: 11.5px; line-height: 1.58; color: #c7b6a2; margin: 4px 0; }
.instructions strong { display: inline; font-family: inherit; font-size: 11.5px; font-weight: 700; color: #fff5e6; letter-spacing: 0; text-shadow: none; }
.instructions em { color: var(--gold); font-style: normal; font-weight: 600; }
.instructions .rule { margin: 11px 0; }
.instructions #restart { width: 100%; margin-top: 10px; }

kbd {
  font: 700 10px monospace;
  border: 1px solid #6b533e;
  background: rgba(34, 24, 18, 0.9);
  color: #f5ebd8;
  padding: 2px 5px;
  border-radius: 4px;
}

.touch {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 0;
}

.touch button {
  min-width: 108px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #32241b, #201610);
  user-select: none;
  -webkit-user-select: none;
}

.touch button.active {
  background: var(--gold);
  color: #1c1005;
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(246, 196, 69, 0.45);
}

footer { margin: 0; font-size: 9px; }

@media (max-width: 960px) {
  main { padding: 14px 18px; gap: 10px; }
  .machine { gap: 18px; }
  .machine > aside { flex-basis: 172px; }
  .instructions { display: none; }
}

@media (max-width: 580px) {
  main {
    padding: 10px 12px;
    gap: 8px;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }
  header { font-size: 8px; }
  header > span { display: none; }
  .heading .eyebrow { font-size: 7px; margin-bottom: 4px; }
  h1 { font-size: 22px; }
  h1 span { font-size: 9px; margin-top: 4px; }
  .heading button, .arcade-exit { padding: 7px 9px; font-size: 10px; }
  .machine { flex-direction: column; gap: 8px; }
  .machine > aside.hud-left {
    flex: 0 0 auto;
    width: 100%;
    display: grid;
    grid-template-columns: 1.1fr 1.1fr 1fr;
    gap: 4px 10px;
    align-items: center;
  }
  .hud-left .label { margin: 0; font-size: 8px; letter-spacing: 1px; }
  .hud-left strong { font-size: 19px; }
  .hud-left b { font-size: 14px; }
  .hud-left .hud-row { grid-column: 3; grid-row: 1 / 3; gap: 8px; }
  .hud-left .card-rack, .hud-left .rule, .hud-left .status-label, #status, #start, #pause { display: none; }
  #table {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: auto;
    flex: 1 1 auto;
    border-radius: 18px;
  }
  .touch { gap: 6px; }
  .touch button { min-width: 0; flex: 1; padding: 12px 6px; min-height: 44px; font-size: 11px; }
  footer { display: none; }
  #overlay h2 { font-size: clamp(24px, 6vh, 38px); margin: 10px 0; }
  #overlay span { font-size: 11px; margin-bottom: 16px; }
}

@media (min-width: 581px) {
  main {
    position: relative;
    padding: 8px 24px;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 10px;
  }
  main > header, main > footer { display: none; }
  .heading {
    position: absolute;
    top: 14px;
    left: 24px;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    width: 205px;
  }
  .heading .eyebrow { display: none; }
  .heading h1 { font-size: 22px; }
  .heading h1 span { font-size: 9.5px; margin-top: 4px; letter-spacing: 3px; }
  .heading button, .arcade-exit { padding: 6px 9px; font-size: 10px; }
  .machine { grid-row: 1; align-items: center; }
  .machine > aside.hud-left { padding-top: 118px; }
  .touch { grid-row: 2; }
}

@media (min-width: 581px) and (max-height: 740px) {
  main { gap: 8px; padding: 8px 20px; }
  .instructions .heart-mark, .instructions h2, .instructions > .label { display: none; }
  .machine > aside .label { margin: 8px 0 3px; }
  .machine > aside .rule { margin: 8px 0; }
  .machine > aside.hud-left strong { font-size: 24px; }
  #status { margin: 4px 0 8px; min-height: 24px; }
  .hud-left button { padding: 7px 10px; }
}

@media (min-width: 581px) and (max-height: 600px) {
  .heading { top: 10px; left: auto; right: 20px; width: auto; }
  .heading > div { display: none; }
  .machine > aside.hud-left { padding-top: 0; }
}
