:root {
  color-scheme: dark;
  --black: #000;
  --ink: #080600;
  --brown: #2a200f;
  --copper: #ca7f4f;
  --orange: #e46c00;
  --gold: #fcf440;
  --cream: #fcfcd8;
  --red: #e30000;
  --green: #609c00;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
  background: var(--ink);
}

body {
  color: var(--cream);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  background:
    radial-gradient(circle at 50% 0%, rgba(96, 156, 0, 0.13), transparent 36rem),
    repeating-linear-gradient(90deg, rgba(202, 127, 79, 0.025) 0 1px, transparent 1px 5px),
    #080600;
  touch-action: manipulation;
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: var(--cream);
  border: 1px solid rgba(252, 244, 64, 0.46);
  border-radius: 7px;
  background: linear-gradient(#31220c, #110d05);
  box-shadow: inset 0 0 0 1px rgba(202, 127, 79, 0.25), 0 2px 0 #000;
  font: inherit;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  color: var(--gold);
  border-color: var(--gold);
  outline: none;
}

button:active {
  transform: translateY(1px);
  box-shadow: inset 0 0 6px #000;
}

.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 16px 18px 26px;
}

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

.brand {
  display: flex;
  align-items: baseline;
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(31px, 6vw, 52px);
  font-weight: 900;
  line-height: 0.82;
  letter-spacing: -0.09em;
  filter: drop-shadow(2px 3px 0 #000);
}

.brand-h,
.brand-o {
  color: var(--red);
}

.brand-r,
.brand-c {
  color: var(--green);
}

.brand small {
  margin-left: 13px;
  color: var(--gold);
  font: 700 11px/1 ui-monospace, monospace;
  letter-spacing: 0.14em;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.toolbar button {
  min-height: 34px;
  padding: 6px 11px;
  font-size: 12px;
}

.cabinet {
  position: relative;
  padding: 13px 13px 0;
  overflow: hidden;
  border: 1px solid #6f4a25;
  border-radius: 16px;
  background:
    linear-gradient(90deg, rgba(252, 244, 64, 0.06), transparent 12%, transparent 88%, rgba(252, 244, 64, 0.05)),
    repeating-linear-gradient(90deg, #3a2f15 0 3px, #553f1f 3px 5px, #2a200f 5px 8px);
  box-shadow:
    inset 0 0 0 2px #2a200f,
    inset 0 0 0 4px rgba(202, 127, 79, 0.35),
    0 18px 42px rgba(0, 0, 0, 0.62);
}

.cabinet-lights {
  position: absolute;
  top: 4px;
  left: 50%;
  display: flex;
  gap: 9px;
  transform: translateX(-50%);
}

.cabinet-lights i {
  width: 18px;
  height: 6px;
  border-radius: 50%;
  background: #2f4200;
  box-shadow: inset 0 -1px 2px #000, 0 0 5px rgba(96, 156, 0, 0.2);
}

.cabinet-lights i:nth-child(3) {
  background: #706c00;
  box-shadow: 0 0 7px rgba(252, 244, 64, 0.25);
}

.screen-bezel {
  padding: clamp(8px, 1.8vw, 15px);
  border: 1px solid #9f603a;
  border-radius: 11px;
  background: #080500;
  box-shadow: inset 0 0 22px #000, 0 0 0 2px #2a200f;
}

.screen-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 5;
  overflow: hidden;
  border: 1px solid #000;
  border-radius: 4px;
  background: #000;
  box-shadow: 0 0 18px rgba(252, 244, 64, 0.07);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  outline: none;
  touch-action: none;
  user-select: none;
}

.glass {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0.035), transparent 26%, transparent 72%, rgba(255, 255, 255, 0.018)),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.08) 0 1px, transparent 1px 3px);
  mix-blend-mode: screen;
  opacity: 0.42;
}

.cabinet-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 7px 11px;
  color: #bf7a4a;
  font-size: 11px;
}

#status-text {
  color: #b4ac00;
  text-align: right;
}

.mobile-controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 13px 2px 3px;
}

.dpad {
  display: grid;
  grid-template: repeat(2, 48px) / repeat(3, 48px);
  gap: 5px;
}

.dpad button,
.action-button {
  min-width: 48px;
  min-height: 48px;
  font-size: 20px;
  touch-action: none;
}

.dpad [data-control="up"] {
  grid-column: 2;
}

.dpad [data-control="left"] {
  grid-row: 2;
  grid-column: 1;
}

.dpad [data-control="down"] {
  grid-row: 2;
  grid-column: 2;
}

.dpad [data-control="right"] {
  grid-row: 2;
  grid-column: 3;
}

.action-button {
  width: 74px;
  border-color: var(--green);
  color: var(--gold);
  font-size: 15px;
  font-weight: 800;
}

dialog {
  width: min(92vw, 570px);
  color: var(--cream);
  border: 1px solid #9f603a;
  border-radius: 13px;
  background:
    linear-gradient(rgba(42, 32, 15, 0.96), rgba(5, 4, 1, 0.98)),
    #000;
  box-shadow: 0 22px 80px #000;
  font: 14px/1.55 ui-monospace, monospace;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(3px);
}

dialog h2 {
  margin: 0 0 14px;
  color: var(--gold);
}

.dialog-close {
  float: right;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 23px;
}

.help-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  align-items: center;
  gap: 9px 14px;
  margin: 18px 0;
}

kbd {
  min-width: 70px;
  padding: 4px 7px;
  color: var(--gold);
  border: 1px solid #6f4a25;
  border-radius: 4px;
  background: #000;
  text-align: center;
}

.help-note {
  color: #c79f2b;
}

#score-form {
  display: grid;
  gap: 13px;
}

#score-name {
  width: 100%;
  padding: 12px;
  color: var(--gold);
  border: 1px solid #9f603a;
  border-radius: 6px;
  outline: none;
  background: #000;
  font: 800 28px/1 ui-monospace, monospace;
  letter-spacing: 0.45em;
  text-align: center;
  text-transform: uppercase;
}

#score-save {
  min-height: 42px;
}

@media (hover: none), (pointer: coarse), (max-width: 720px) {
  .app-shell {
    padding: 10px 8px 18px;
  }

  .topbar {
    align-items: center;
  }

  .toolbar button {
    padding-inline: 8px;
  }

  .cabinet {
    padding: 10px 8px 0;
  }

  .screen-bezel {
    padding: 5px;
  }

  .mobile-controls {
    display: flex;
  }

  .cabinet-footer {
    font-size: 9px;
  }
}

@media (max-width: 520px) {
  .brand {
    font-size: 32px;
  }

  .brand small,
  #scores-button {
    display: none;
  }

  .toolbar {
    gap: 4px;
  }

  .toolbar button {
    min-height: 31px;
    font-size: 10px;
  }

  .cabinet-footer span:first-child {
    display: none;
  }

  .cabinet-footer {
    justify-content: flex-end;
  }
}

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