:root {
  color-scheme: dark;
  --ink: #f6f2ff;
  --muted: #a8a0bc;
  --panel: rgba(18, 15, 29, 0.88);
  --line: rgba(255, 255, 255, 0.12);
  --violet: #9e72ff;
  --cyan: #45e2ff;
  --red: #ff5b72;
  font-family: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #07060d;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 4%, rgba(101, 64, 196, 0.22), transparent 38rem),
    radial-gradient(circle at 84% 88%, rgba(38, 174, 210, 0.11), transparent 32rem),
    linear-gradient(145deg, #0b0912 0%, #05050a 74%);
}

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

button {
  font: inherit;
}

.arcade {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 4vw, 2.25rem);
  letter-spacing: -0.05em;
}

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

.tool-button,
.language-button,
.pill-button,
.primary-button,
.danger-button,
.close-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.tool-button {
  padding: 0 12px;
  font-size: 0.72rem;
}

.language-switcher {
  display: grid;
  grid-template-columns: repeat(2, 32px);
  overflow: hidden;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.language-button {
  min-height: 36px;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  font-size: 0.66rem;
  font-weight: 800;
}

.language-button + .language-button {
  border-left: 1px solid var(--line);
}

.language-button[aria-pressed="true"] {
  color: #080710;
  background: var(--cyan);
}

button:hover {
  border-color: rgba(158, 114, 255, 0.68);
  background: rgba(158, 114, 255, 0.12);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
.language-button:focus-visible,
canvas:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.cabinet {
  overflow: hidden;
  padding: clamp(10px, 2vw, 18px);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(35, 30, 51, 0.95), rgba(12, 10, 19, 0.98));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5), inset 0 1px rgba(255, 255, 255, 0.08);
}

.screen-frame {
  padding: clamp(7px, 1.6vw, 13px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: #030306;
  box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.9), 0 0 38px rgba(105, 71, 217, 0.13);
}

.screen-glass {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 8 / 5;
  background: #000;
  border-radius: 5px;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  cursor: default;
}

.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.12;
  background: repeating-linear-gradient(to bottom, transparent 0 3px, rgba(0, 0, 0, 0.34) 3px 4px);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 10px;
  max-width: calc(100% - 24px);
  padding: 5px 9px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: #fff;
  background: rgba(3, 3, 7, 0.82);
  font-size: clamp(0.48rem, 1.6vw, 0.72rem);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 5px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.statusbar {
  display: grid;
  grid-template-columns: 1.35fr repeat(4, 1fr);
  gap: 1px;
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--line);
}

.statusbar span {
  min-width: 0;
  padding: 9px 11px;
  background: rgba(8, 7, 13, 0.93);
}

.statusbar small,
.statusbar strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.statusbar small {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.statusbar strong {
  color: #fff;
  font-size: 0.76rem;
}

.controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 18px;
}

.dpad {
  display: grid;
  grid-template: repeat(3, 52px) / repeat(3, 52px);
  gap: 4px;
}

.control {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
  font-size: 1rem;
  touch-action: manipulation;
  user-select: none;
}

.control.up { grid-area: 1 / 2; }
.control.left { grid-area: 2 / 1; }
.control.center { grid-area: 2 / 2; color: var(--cyan); }
.control.right { grid-area: 2 / 3; }
.control.down { grid-area: 3 / 2; }

.quick-actions {
  display: grid;
  gap: 10px;
}

.pill-button {
  min-width: 138px;
  padding: 0 14px;
  font-size: 0.7rem;
}

.key-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.8;
  text-align: center;
}

kbd {
  padding: 2px 5px;
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-bottom-color: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  color: #e9e4f8;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1);
}

dialog {
  width: min(700px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  color: var(--ink);
  background: #12101b;
  box-shadow: 0 30px 120px #000;
}

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

.dialog-heading,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.dialog-heading h2 {
  margin-bottom: 0;
}

.close-button {
  width: 40px;
  padding: 0;
  font-size: 1.4rem;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 22px 0;
}

.help-grid section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
}

.help-grid h3 {
  margin-bottom: 7px;
  color: var(--cyan);
  font-size: 0.78rem;
}

.help-grid p {
  margin-bottom: 0;
  color: #c4bed2;
  font-family: system-ui, sans-serif;
  font-size: 0.86rem;
  line-height: 1.55;
}

.primary-button,
.danger-button {
  padding: 0 16px;
  font-size: 0.72rem;
}

.primary-button {
  color: #080710;
  border-color: var(--cyan);
  background: var(--cyan);
  font-weight: 800;
}

.danger-button {
  color: #ff9cab;
  border-color: rgba(255, 91, 114, 0.35);
}

@media (hover: none), (pointer: coarse) {
  .controls {
    display: flex;
  }

  .key-hint {
    display: none;
  }
}

@media (max-width: 700px) {
  .arcade {
    padding-top: 14px;
  }

  .topbar {
    align-items: center;
  }

  #help-button,
  #fullscreen-button {
    width: 38px;
    overflow: hidden;
    padding: 0 10px;
    white-space: nowrap;
  }

  .statusbar {
    grid-template-columns: repeat(4, 1fr);
  }

  .statusbar span:first-child {
    display: none;
  }

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

@media (max-width: 430px) {
  .topbar {
    gap: 8px;
  }

  .tool-button {
    width: 38px !important;
    overflow: hidden;
    padding: 0 10px;
    white-space: nowrap;
  }

  .controls {
    gap: 12px;
  }

  .dpad {
    grid-template: repeat(3, 46px) / repeat(3, 46px);
  }

  .pill-button {
    min-width: 112px;
    padding: 0 8px;
    font-size: 0.62rem;
  }

  .statusbar span {
    padding: 7px;
  }

  dialog {
    padding: 17px;
  }

  .dialog-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }
}

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