:root {
  color-scheme: dark;
  --phosphor: #8dffa2;
  --phosphor-bright: #c4ffce;
  --phosphor-dim: #4e9b60;
  --ink: #020805;
  --panel: #06110a;
  --line: rgba(141, 255, 162, .28);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--phosphor);
  font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

button,
input { font: inherit; }

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

[hidden] { display: none !important; }

.arcade-shell {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(29, 94, 48, .22), transparent 64%),
    var(--ink);
}

.arcade-library-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: var(--ink);
  pointer-events: none;
  transition: opacity .28s ease;
}

.arcade-library-backdrop::before,
.arcade-library-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.arcade-library-backdrop::before {
  background:
    linear-gradient(90deg, rgba(2, 8, 5, .6), rgba(2, 8, 5, .42)),
    linear-gradient(180deg, rgba(2, 8, 5, .36), rgba(2, 8, 5, .68));
}

.arcade-library-backdrop::after {
  background: repeating-linear-gradient(
    180deg,
    rgba(141, 255, 162, .018) 0,
    rgba(141, 255, 162, .018) 1px,
    rgba(0, 0, 0, .055) 1px,
    rgba(0, 0, 0, .055) 3px
  );
}

.arcade-library-backdrop-image {
  position: absolute;
  inset: -2%;
  z-index: 1;
  width: 104%;
  height: 104%;
  object-fit: cover;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: saturate(.78) contrast(1.12) brightness(.68);
  opacity: 0;
  transform: scale(1.035);
  transition:
    opacity .46s ease,
    transform 1.4s cubic-bezier(.22, 1, .36, 1);
}

.arcade-library-backdrop-image.is-active {
  opacity: .72;
  transform: scale(1.01);
}

.arcade-shell.is-game-active .arcade-library-backdrop {
  opacity: 0;
}

.arcade-status-bar {
  position: relative;
  z-index: 1;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--phosphor-dim);
  font-size: 10px;
  background: rgba(2, 8, 5, .34);
}

.arcade-status-bar strong {
  color: var(--phosphor-bright);
  font-size: 11px;
}

.library-view {
  position: relative;
  z-index: 1;
  height: calc(100% - 34px);
  display: grid;
  grid-template-columns: minmax(250px, 1.08fr) minmax(220px, .92fr);
}

.catalog-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 42px 1fr;
  padding: 12px 10px 12px 14px;
  border-right: 1px solid var(--line);
  background: rgba(2, 8, 5, .34);
}

.catalog-search {
  height: 32px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  background: rgba(141, 255, 162, .035);
}

.catalog-search:focus-within { border-color: rgba(141, 255, 162, .72); }

.catalog-search span {
  position: relative;
  width: 28px;
  height: 100%;
  flex: 0 0 auto;
}

.catalog-search span::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 8px;
  width: 8px;
  height: 8px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}

.catalog-search span::after {
  content: "";
  position: absolute;
  left: 17px;
  top: 17px;
  width: 6px;
  height: 1.5px;
  border-radius: 999px;
  background: currentColor;
  transform: rotate(45deg);
}

.catalog-search input {
  min-width: 0;
  width: 100%;
  height: 100%;
  padding: 0 9px 0 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--phosphor-bright);
  font-size: 11px;
}

.catalog-search input::placeholder { color: rgba(141, 255, 162, .38); }

.game-list {
  min-height: 0;
  overflow-y: auto;
  padding-right: 3px;
  scrollbar-color: rgba(141, 255, 162, .34) transparent;
  scrollbar-width: thin;
}

.game-list-empty {
  margin: 24px 8px;
  color: var(--phosphor-dim);
  font-size: 10px;
  line-height: 1.7;
}

.game-option {
  width: 100%;
  min-height: 34px;
  display: grid;
  grid-template-columns: 40px 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 5px;
  border: 0;
  border-bottom: 1px solid rgba(141, 255, 162, .11);
  color: rgba(141, 255, 162, .68);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: color .13s ease, background-color .13s ease, transform .13s cubic-bezier(.23, 1, .32, 1);
}

.game-option-cover {
  width: 40px;
  height: 30px;
  display: block;
  border: 1px solid rgba(141, 255, 162, .25);
  border-radius: 2px;
  background: #000;
  object-fit: cover;
  image-rendering: pixelated;
  opacity: .78;
  transition: opacity .13s ease, border-color .13s ease, transform .13s cubic-bezier(.23, 1, .32, 1);
}

.game-option-cover.is-official-cover,
.selected-cover.is-official-cover {
  object-fit: contain;
  background: #000;
  image-rendering: auto;
}

.game-option:hover .game-option-cover,
.game-option.is-selected .game-option-cover {
  border-color: rgba(196, 255, 206, .84);
  opacity: 1;
}

.game-option:hover .game-option-cover { transform: scale(1.04); }

.game-option:hover {
  color: var(--phosphor-bright);
  background: rgba(141, 255, 162, .07);
}

.game-option:active { transform: scale(.985); }

.game-option:focus-visible {
  outline: 1px solid var(--phosphor);
  outline-offset: -2px;
}

.game-option.is-selected {
  color: #031007;
  background: var(--phosphor);
  text-shadow: none;
}

.game-option-index { font-size: 9px; opacity: .68; }
.game-option-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.game-option-arrow { font-size: 9px; opacity: 0; }
.game-option.is-selected .game-option-arrow { opacity: 1; }

.cartridge-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 22px 16px;
  text-align: center;
  background: rgba(2, 8, 5, .2);
}

.cartridge-visual {
  position: relative;
  width: 92px;
  height: 106px;
  margin-bottom: 12px;
  border: 2px solid rgba(141, 255, 162, .55);
  border-radius: 5px 5px 13px 5px;
  background: rgba(141, 255, 162, .06);
  box-shadow: inset 0 -10px 0 rgba(141, 255, 162, .04), 0 0 16px rgba(111, 255, 139, .09);
  transition: width .28s cubic-bezier(.23, 1, .32, 1), height .28s cubic-bezier(.23, 1, .32, 1);
}

.cartridge-visual.is-portrait-art {
  width: 108px;
  height: 148px;
  border-radius: 6px 6px 15px 6px;
}

.cartridge-ridge {
  position: absolute;
  left: 9px;
  right: 9px;
  top: 9px;
  height: 17px;
  border: 1px solid rgba(141, 255, 162, .3);
  border-radius: 3px;
  transition: inset .28s cubic-bezier(.23, 1, .32, 1), height .28s cubic-bezier(.23, 1, .32, 1);
}

.cartridge-visual.is-portrait-art .cartridge-ridge {
  left: 24px;
  right: 24px;
  top: 7px;
  height: 7px;
  border-radius: 4px;
}

.cartridge-label {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 35px;
  height: 44px;
  display: block;
  overflow: hidden;
  border: 1px solid rgba(141, 255, 162, .42);
  transition: inset .28s cubic-bezier(.23, 1, .32, 1), height .28s cubic-bezier(.23, 1, .32, 1);
}

.cartridge-visual.is-portrait-art .cartridge-label {
  left: 15px;
  right: 15px;
  top: 20px;
  height: 112px;
  border-radius: 2px;
  background: #000;
}

.cartridge-label::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(0, 8, 3, .82));
  pointer-events: none;
}

.selected-cover {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  image-rendering: pixelated;
}

.cartridge-label b {
  position: absolute;
  z-index: 1;
  left: 4px;
  top: 3px;
  padding: 1px 3px;
  border-radius: 2px;
  background: rgba(0, 8, 3, .78);
  color: var(--phosphor-bright);
  font-size: 10px;
  line-height: 1.15;
}

.cartridge-label i {
  position: absolute;
  z-index: 1;
  left: 2px;
  right: 2px;
  bottom: 2px;
  color: var(--phosphor-bright);
  font-size: 5px;
  font-style: normal;
  text-shadow: 0 1px 2px #000;
}

.cartridge-contacts {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 9px;
  height: 7px;
  background: repeating-linear-gradient(90deg, var(--phosphor-dim) 0 3px, transparent 3px 6px);
  opacity: .58;
}

.cartridge-visual.is-portrait-art .cartridge-contacts {
  left: 18px;
  right: 18px;
  bottom: 5px;
  height: 6px;
}

.cartridge-eyebrow {
  margin: 0 0 5px;
  color: var(--phosphor-dim);
  font-size: 8px;
}

.cartridge-pane h1 {
  max-width: 100%;
  margin: 0;
  color: var(--phosphor-bright);
  font-size: 18px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.selected-meta {
  min-height: 14px;
  margin: 6px 0 10px;
  color: var(--phosphor-dim);
  font-size: 8px;
}

.load-game,
.game-toolbar button,
.error-state button {
  border: 1px solid rgba(141, 255, 162, .52);
  border-radius: 3px;
  background: rgba(141, 255, 162, .08);
  color: var(--phosphor-bright);
  cursor: pointer;
  transition: transform .13s cubic-bezier(.23, 1, .32, 1), background-color .13s ease;
}

.load-game {
  min-width: 116px;
  height: 32px;
  padding: 0 17px;
  font-size: 11px;
}

.load-game:hover,
.game-toolbar button:hover,
.error-state button:hover { background: rgba(141, 255, 162, .16); }

.load-game:active,
.game-toolbar button:active,
.error-state button:active { transform: scale(.97); }

.load-game:focus-visible,
.game-toolbar button:focus-visible,
.error-state button:focus-visible { outline: 1px solid var(--phosphor-bright); outline-offset: 2px; }

.key-guide {
  width: min(210px, 100%);
  margin: 12px 0 0;
  border-top: 1px solid var(--line);
}

.key-guide div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 21px;
  border-bottom: 1px solid rgba(141, 255, 162, .12);
  font-size: 8px;
}

.key-guide dt { color: var(--phosphor-dim); }
.key-guide dd { margin: 0; color: var(--phosphor-bright); }

.game-view {
  position: relative;
  z-index: 2;
  height: calc(100% - 34px);
  display: grid;
  grid-template-rows: 36px minmax(0, 1fr) 28px;
  background: var(--ink);
}

.game-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(4, 15, 8, .94);
}

.game-toolbar button {
  height: 24px;
  padding: 0 8px;
  font-size: 8px;
}

.game-toolbar strong {
  min-width: 0;
  overflow: hidden;
  color: var(--phosphor-bright);
  font-size: 10px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-actions { display: flex; gap: 5px; }

.nes-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #000;
}

.nes-stage canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  outline: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.loading-state {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #020805;
  color: var(--phosphor-dim);
  font-size: 9px;
}

.loading-state b {
  color: var(--phosphor-bright);
  font-size: 12px;
  animation: arcade-loading 1.1s steps(2, end) infinite;
}

.game-key-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  border-top: 1px solid var(--line);
  color: var(--phosphor-dim);
  font-size: 8px;
  white-space: nowrap;
}

.game-key-strip b { color: inherit; font-weight: 400; }

.error-state {
  position: absolute;
  inset: 34px 0 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(2, 8, 5, .97);
  text-align: center;
}

.error-state strong { color: var(--phosphor-bright); font-size: 14px; }
.error-state p { max-width: 360px; margin: 9px 0 16px; color: var(--phosphor-dim); font-size: 9px; line-height: 1.6; }
.error-state button { min-height: 30px; padding: 0 14px; font-size: 10px; }

@keyframes arcade-loading {
  0%, 45% { opacity: .5; }
  46%, 100% { opacity: 1; }
}

@media (max-width: 560px) {
  .arcade-status-bar { padding: 0 10px; }
  .library-view { grid-template-columns: minmax(210px, 1fr) minmax(170px, .8fr); }
  .catalog-pane { padding-left: 9px; }
  .cartridge-pane { padding-left: 10px; padding-right: 10px; }
  .cartridge-visual { width: 75px; height: 86px; margin-bottom: 8px; }
  .cartridge-visual.is-portrait-art { width: 88px; height: 124px; }
  .cartridge-label { top: 29px; height: 34px; }
  .cartridge-visual.is-portrait-art .cartridge-ridge { left: 20px; right: 20px; top: 6px; height: 6px; }
  .cartridge-visual.is-portrait-art .cartridge-label { left: 12px; right: 12px; top: 17px; height: 92px; }
  .cartridge-label b { font-size: 9px; }
  .cartridge-contacts { bottom: 7px; }
  .cartridge-visual.is-portrait-art .cartridge-contacts { left: 15px; right: 15px; bottom: 4px; height: 5px; }
  .cartridge-pane h1 { font-size: 15px; }
  .key-guide { margin-top: 8px; }
  .key-guide div { min-height: 18px; }
  .game-key-strip { gap: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
