:root {
  color-scheme: dark;
  font-family: "Courier New", monospace;
  background: #17141f;
  color: #f2edf7;
}

* {
  box-sizing: border-box;
}

body {
  height: 100vh;
  margin: 0;
  display: flex;
  gap: 24px;
  padding: 24px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 30%, #3a304b 0, transparent 44%),
    linear-gradient(145deg, #17141f, #0c0a10);
}

main {
  height: calc(100vh - 48px);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 6px;
}

.debug-panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid #51485e;
  border-radius: 16px;
  background: #26222c;
}

.debug-panel.hidden {
  display: none;
}

.debug-panel h2 {
  margin: 0 0 6px 0;
  font-size: 14px;
  color: #c8bfe0;
}

.debug-status {
  font-size: 12px;
  color: #92879e;
  margin-bottom: 8px;
}

.debug-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.debug-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #92879e;
}

#dump-raster {
  width: 60px;
  padding: 6px 8px;
  border: 1px solid #776c83;
  border-radius: 6px;
  background: #302a38;
  color: inherit;
  font: inherit;
}

#vic-dump {
  width: 100%;
  resize: vertical;
  min-height: 120px;
  max-height: 50vh;
  overflow: auto;
  font-size: 11px;
  line-height: 1.3;
  padding: 10px;
  border: 1px solid #51485e;
  border-radius: 9px;
  background: #17141f;
  color: #c8bfe0;
  user-select: text;
}

.game-panel {
  width: 320px;
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  padding: 18px;
  border: 1px solid #51485e;
  border-radius: 24px;
  background: linear-gradient(155deg, #403947, #26222c);
  box-shadow: 0 28px 80px #0009, inset 0 1px #ffffff16;
  height: calc(100vh - 48px);
  overflow: hidden;
}

.panel-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #51485e;
}

.game-panel-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.source-toggle {
  display: flex;
  gap: 6px;
}

.source-toggle button {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid #5b506b;
  border-radius: 8px;
  background: #302a38;
  color: #c8bfe0;
  cursor: pointer;
}

.source-toggle button:hover {
  background: #4a3f58;
}

.source-toggle button.active {
  background: #6a5c7d;
  border-color: #a893cf;
  color: #f2edf7;
}

#game-list .ia-result {
  padding: 10px;
  border-bottom: 1px solid #322b3a;
  cursor: default;
}

#game-list .ia-result:hover,
#game-list .ia-result:focus {
  background: transparent;
}

.ia-result-title {
  font-weight: bold;
  font-size: 13px;
  color: #f2edf7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ia-result-meta {
  font-size: 11px;
  color: #92879e;
  margin: 2px 0 8px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ia-list-files {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.ia-files {
  margin-top: 8px;
  padding: 8px;
  background: #1c1824;
  border: 1px solid #3f374a;
  border-radius: 8px;
}

.ia-files.hidden {
  display: none;
}

.ia-files ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ia-files li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid #2e2735;
}

.ia-files li:last-child {
  border-bottom: none;
}

.ia-file-name {
  flex: 1;
  font-family: "Courier New", monospace;
  font-size: 12px;
  color: #d8d0e3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ia-file-size {
  font-size: 11px;
  color: #92879e;
  white-space: nowrap;
}

.ia-file-load {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
}

#game-search {
  border: 1px solid #776c83;
  border-radius: 9px;
  padding: 9px 12px;
  background: #302a38;
  color: inherit;
  font: inherit;
  outline: none;
}

#game-search:focus {
  border-color: #a893cf;
}

#game-count {
  color: #92879e;
  font-size: 12px;
  text-align: right;
}

.alphabet-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}

.alphabet-bar button {
  min-width: 28px;
  padding: 4px 6px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid #5b506b;
  background: #302a38;
  color: #c8bfe0;
  cursor: pointer;
}

.alphabet-bar button:hover {
  background: #4a3f58;
}

.alphabet-bar button.active {
  background: #6a5c7d;
  border-color: #a893cf;
  color: #f2edf7;
}

#game-list {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid #51485e;
}

#game-list li {
  padding: 6px 10px;
  border-bottom: 1px solid #322b3a;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#game-list li:hover,
#game-list li:focus {
  background: #4a3f58;
  outline: none;
}

#game-list .more {
  color: #92879e;
  text-align: center;
  cursor: default;
}

main {
  flex: 1;
  min-width: 0;
  height: calc(100vh - 48px);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 12px 0;
}

header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 5vw, 48px);
  letter-spacing: -0.06em;
}

.eyebrow {
  margin-bottom: 6px;
  color: #b4a6c8;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.status {
  padding: 8px 12px;
  border: 1px solid #5b506b;
  border-radius: 999px;
  color: #cdc3d9;
  font-size: 12px;
}

.status.ready {
  border-color: #84d888;
  color: #a9efac;
}

#status-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

#status-link:hover {
  text-decoration: underline;
}

.machine {
  padding: clamp(14px, 3vw, 28px);
  border: 1px solid #51485e;
  border-radius: 24px;
  background: linear-gradient(155deg, #403947, #26222c);
  box-shadow: 0 28px 80px #0009, inset 0 1px #ffffff16;
}

.screen-shell {
  position: relative;
  overflow: hidden;
  padding: clamp(10px, 2vw, 20px);
  border-radius: 18px;
  background: #09070c;
  box-shadow: inset 0 0 36px #000;
}

canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  aspect-ratio: 384 / 272;
  outline: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

canvas:focus-visible {
  box-shadow: 0 0 0 2px #a893cf;
}

.screen-glow {
  position: absolute;
  inset: 10%;
  background: #7566c5;
  filter: blur(60px);
  opacity: 0.24;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 14px;
  flex-wrap: wrap;
}

#debug-toggle {
  margin-left: auto;
}

#joy1-toggle,
#joy2-toggle {
  min-width: 70px;
  padding: 9px 12px;
  text-align: center;
}

#joy1-toggle:not(.active),
#joy2-toggle:not(.active) {
  opacity: 0.55;
}

#joy1-toggle.active,
#joy2-toggle.active {
  background: #6a5c7d;
  border-color: #a893cf;
  color: #f2edf7;
}

button,
.file-button {
  border: 1px solid #776c83;
  border-radius: 9px;
  padding: 9px 16px;
  background: #302a38;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

button:hover,
.file-button:hover {
  background: #443b4f;
}

.file-button input {
  display: none;
}

#renderer {
  margin-left: auto;
  color: #a99fb5;
  font-size: 12px;
}

.hint {
  margin-top: 14px;
  color: #92879e;
  font-size: 12px;
  text-align: center;
}

.sid-panel {
  width: 320px;
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  padding: 18px;
  border: 1px solid #51485e;
  border-radius: 24px;
  background: linear-gradient(155deg, #403947, #26222c);
  box-shadow: 0 28px 80px #0009, inset 0 1px #ffffff16;
  height: calc(100vh - 48px);
  overflow: hidden;
}

.sid-panel h2 {
  margin: 0 0 12px 0;
  font-size: 16px;
  color: #c8bfe0;
}

.sid-panel-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.sid-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

#sid-search {
  flex: 1;
  border: 1px solid #776c83;
  border-radius: 9px;
  padding: 9px 12px;
  background: #302a38;
  color: inherit;
  font: inherit;
  outline: none;
}

#sid-search:focus {
  border-color: #a893cf;
}

#sid-search-btn {
  padding: 9px 14px;
}

#sid-count {
  color: #92879e;
  font-size: 12px;
  text-align: right;
}

#sid-list {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid #51485e;
}

#sid-list li {
  padding: 6px 10px;
  border-bottom: 1px solid #322b3a;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#sid-list li:hover,
#sid-list li:focus {
  background: #4a3f58;
  outline: none;
}

#sid-list .more {
  color: #92879e;
  text-align: center;
  cursor: default;
}

@media (max-width: 800px) {
  body {
    flex-direction: column;
    height: auto;
    overflow: auto;
    padding: 12px;
  }

  .game-panel,
  .sid-panel {
    width: 100%;
    flex: 0 0 auto;
    max-width: none;
    height: 260px;
  }

  main {
    height: auto;
    overflow: visible;
  }

  #renderer {
    margin-left: 0;
  }
}

@media (max-width: 560px) {
  header {
    align-items: start;
    flex-direction: column;
  }

  .status {
    align-self: start;
  }
}
