/* Genie Jam: an 8-bit look. Chunky framed boxes, hard drop shadows, a small palette in the spirit of
   the console's own colors, and Genie Jam's own pixel font (src/app/fonts). */

@font-face {
  font-family: 'Genie Jam 8';
  src: url('fonts/genie-jam-8.woff') format('woff'), url('fonts/genie-jam-8.ttf') format('truetype');
  font-display: swap;
}

:root {
  --black: #000;
  --ink: #0d0d0d;
  --white: #fcfcfc;
  --gray: #bcbcbc;
  --gray-dark: #5c5c5c;
  --gray-deep: #3c3c3c;
  --yellow: #f8b800;
  --red: #f83800;
  --blue: #0000bc;
  --blue-light: #3cbcfc;
  --green: #58d854;
  --pixel: 'Genie Jam 8', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --bar-h: 76px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--black);
  color: var(--white);
  font-family: var(--pixel);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: none;
}
/* The bar takes the height it needs (it wraps on narrow screens); the game area gets the rest. */
body { display: flex; flex-direction: column; }

button { font-family: inherit; }

/* ---- header ---- */
.bar {
  min-height: var(--bar-h);
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 8px 24px;
  border-bottom: 4px solid var(--gray-dark);
}
.brand { display: flex; align-items: center; }
.brand-logo { display: block; height: 64px; width: auto; }
.bar-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }

/* ---- buttons: flat color, hard shadow, they press down ---- */
.btn {
  font-size: 16px;
  letter-spacing: 0;
  color: var(--black);
  background: var(--gray);
  border: 3px solid var(--black);
  box-shadow: 4px 4px 0 var(--gray-dark);
  padding: 10px 18px;
  cursor: pointer;
  text-transform: uppercase;
}
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--gray-dark); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.focused, .btn:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
.btn-small { font-size: 16px; padding: 4px 10px; box-shadow: 3px 3px 0 var(--gray-dark); }
.btn-yellow { background: var(--yellow); }
.btn-red { background: var(--red); color: var(--white); text-shadow: 2px 2px 0 var(--black); }
.btn-green { background: var(--green); }
.btn-dark { background: var(--gray-dark); color: var(--white); }
.btn-wide { width: 100%; padding: 14px; }
.btn[hidden] { display: none; }
/* The controller button that reaches a top-bar button (RB, LB). */
.btn .key {
  display: inline-block;
  margin-left: 6px;
  padding: 0 4px;
  color: var(--white);
  background: var(--black);
  font-size: 16px;
  line-height: 1.25;
}

.badge {
  display: inline-block;
  font-size: 16px;
  letter-spacing: 0;
  padding: 6px 12px;
  color: var(--black);
  border: 3px solid var(--black);
  white-space: nowrap;
}
.badge-green { background: var(--green); }
.badge-gray { background: var(--gray); }
.badge-yellow { background: var(--yellow); }
.badge[hidden] { display: none; }

/* ---- layout: Game Genie on the left, the game on the right ---- */
/* The game fills the window; the Game Genie panel slides over it from the left when opened. */
.layout {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ---- the Game Genie panel ---- */
.genie-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 5;
  width: min(480px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 18px;
  overflow-y: auto;
  background: var(--black);
  border-right: 4px solid var(--yellow);
  box-shadow: 8px 0 0 rgba(0, 0, 0, 0.6);
  transform: translateX(calc(-100% - 12px));
  transition: transform 0.18s steps(6);
  visibility: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--gray-dark) var(--black);
}
.genie-panel.open { transform: none; visibility: visible; }
@media (prefers-reduced-motion: reduce) { .genie-panel { transition: none; } }

.gg-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 18px;
  border: 4px solid var(--white);
  outline: 5px solid var(--gray-dark);
  outline-offset: 0;
  margin: 5px;
}
.gg-card-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.gg-compare { display: flex; }
.gg-compare .btn + .btn { border-left-width: 0; }
.gg-compare[hidden] { display: none; }
.gg-banner {
  width: 100%;
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  padding: 10px 12px;
  text-align: center;
  color: var(--black);
  background: var(--yellow);
  border: 3px solid var(--black);
  box-shadow: 4px 4px 0 var(--gray-dark);
}
.gg-banner[hidden] { display: none; }
.letter.wide { grid-column: span 4; aspect-ratio: auto; font-size: 16px; padding: 8px 0; }
.letter.rubout { background: var(--gray); }
.letter.done { background: var(--yellow); }
.gg-card h2 { margin: 0; font-size: 24px; letter-spacing: 0; }
.gg-game { margin: 4px 0 0; color: var(--gray); font-size: 16px; }
.gg-card-text { min-width: 0; }

.gg-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.gg-tabs .tab:nth-child(3) { grid-column: 1 / -1; } /* CODE MAKER takes the second line */
.btn.tab { padding: 10px 4px; font-size: 16px; }

.gg-choose-title { color: var(--yellow); font-size: 16px; }
.gg-choose-title[hidden] { display: none; }

.genie-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
  padding: 14px;
  background: var(--blue);
  border: 4px solid var(--white);
}
.genie-panel.genie-browse .genie-grid { display: none; }
.letter {
  aspect-ratio: 1;
  font-size: 24px;
  color: var(--black);
  background: var(--white);
  border: 3px solid var(--black);
  box-shadow: 3px 3px 0 var(--black);
  cursor: pointer;
  padding: 0;
}
.letter:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--black); }
.letter.focused { background: var(--yellow); outline: 3px solid var(--yellow); outline-offset: 2px; }

.genie-lines { display: flex; flex-direction: column; gap: 14px; }

.code-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  border: 4px solid var(--white);
  background: var(--black);
}
.code-card.active { border-color: var(--yellow); outline: 4px solid var(--yellow); outline-offset: 4px; margin: 4px; }
.code-card .name { font-size: 16px; }
.code-card .desc { font-size: 16px; color: var(--blue-light); word-break: break-word; }
.code-card .desc.incomplete { color: var(--yellow); }
.code-card .desc.good { color: var(--green); }
/* Naming a code: the name so far, then an on-screen keyboard the d-pad can walk. */
.naming { display: flex; flex-direction: column; gap: 12px; }
.naming-label { color: var(--yellow); font-size: 16px; }
.naming-text {
  min-height: 48px;
  padding: 8px 10px;
  font-size: 16px;
  border: 3px solid var(--yellow);
  background: var(--ink);
  word-break: break-all;
}
.naming-cursor { color: var(--yellow); animation: blink-text 1s steps(2) infinite; }
@keyframes blink-text { 50% { color: transparent; } }
.kb {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  padding: 10px;
  background: var(--blue);
  border: 4px solid var(--white);
}
.kb-key {
  font-size: 16px;
  min-height: 32px;
  padding: 0;
  color: var(--black);
  background: var(--white);
  border: 3px solid var(--black);
  cursor: pointer;
}
.kb-key.focused { background: var(--yellow); outline: 3px solid var(--yellow); outline-offset: 2px; }
.kb-func { background: var(--gray); }
.kb-done { background: var(--yellow); }
.kb-done.focused { background: var(--white); }
.genie-panel.genie-naming .gg-tabs { display: none; }
.cells { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }

.slots { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; cursor: pointer; padding: 4px 2px; }
.slots.focused { outline: 3px solid var(--yellow); outline-offset: 4px; }
.slot {
  width: 28px;
  height: 32px;
  display: grid;
  place-items: center;
  font-size: 24px;
  border-bottom: 4px solid var(--white);
}
.slot:empty { border-bottom-color: var(--gray-dark); }
.slot.optional:empty { border-bottom-style: dotted; }
.slot.cursor { border-bottom-color: var(--yellow); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { border-bottom-color: transparent; } }
.code-card.on .slot { color: var(--yellow); }
.code-card.on .slot:not(:empty) { border-bottom-color: var(--yellow); }
.chip {
  font-size: 16px;
  letter-spacing: 0;
  padding: 3px 6px;
  border: 3px solid var(--gray-dark);
}
.code-card.on .chip { color: var(--yellow); border-color: var(--yellow); }
.plus, .prefix { color: var(--gray); font-size: 16px; }
.prefix { margin-right: 4px; }
.gg-note { color: var(--gray); margin: 0; }

.genie-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.gg-hint {
  margin: 0;
  padding: 12px 14px;
  border: 3px dashed var(--gray-dark);
  color: var(--gray);
  font-size: 16px;
}
.gg-empty { margin: 0; color: var(--gray); }
.genie-panel.has-game .gg-empty { display: none; }
.genie-panel:not(.has-game) .gg-tabs,
.genie-panel:not(.has-game) .genie-grid,
.genie-panel:not(.has-game) .genie-lines,
.genie-panel:not(.has-game) .genie-actions,
.genie-panel:not(.has-game) .gg-hint { display: none; }

/* ---- the game screen ---- */
.screen-panel {
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: hidden;
  container-type: size;
}
.screen-panel.dragging .screen-frame { outline: 4px dashed var(--yellow); outline-offset: 6px; }
.screen-frame {
  position: relative;
  /* As large as the right side allows, keeping the console's 256x240 shape. */
  width: min(100cqw - 16px, (100cqh - 16px) * 256 / 240);
  aspect-ratio: 256 / 240;
  padding: 6px;
  background: var(--blue);
  border: 4px solid var(--white);
  outline: 4px solid var(--gray-dark);
}
.layout.genie-open .screen-frame { filter: brightness(0.55); }
#screen {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--black);
}
.screen-panel.idle #screen { opacity: 0; }
/* ---- the status strip under the game: codes on, the code being tried, messages ---- */
.status {
  flex: none;
  min-height: 72px;
  display: flex;
  align-items: center; /* one row: each part wraps inside its own column */
  gap: 8px 14px;
  padding: 8px 24px;
  border-top: 4px solid var(--gray-dark);
}
.patched { cursor: pointer; }
.patched.is-original { background: var(--gray); }
.trial { flex: 1 1 0; min-width: 0; font-size: 16px; line-height: 1.5; }
.trial[hidden] { display: none; }
.trial-label { color: var(--blue-light); }
.trial-keys { color: var(--gray); margin-left: 10px; }
.trial-text { color: var(--white); }

/* ---- panels over the game screen (start, menu) ---- */
.panel {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  width: min(520px, calc(100% - 28px));
  max-height: calc(100% - 28px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  background: var(--black);
  border: 4px solid var(--white);
  outline: 5px solid var(--gray-dark);
}
.panel[hidden] { display: none; }
.screen-panel { position: relative; }
/* The start screen fills the game area so the game list gets the room, not the instructions. */
.panel.start {
  inset: 16px;
  transform: none;
  width: auto;
  max-width: 960px;
  max-height: none;
  margin: 0 auto;
}
.screen-panel.idle .screen-frame { visibility: hidden; }
/* The logo: beside the game list on wide screens, small above it on narrow ones, so the list keeps
   its room. */
.start-logo {
  display: block;
  width: auto;
  max-width: 100%;
  height: clamp(56px, 12vh, 120px);
  object-fit: contain;
  margin: 0 auto;
  flex: none;
}
@media (min-width: 900px) {
  .panel.start:not([hidden]) { /* :not([hidden]): the grid must not keep a closed start screen showing */
    max-width: 1240px;
    display: grid;
    grid-template-columns: minmax(240px, 36%) 1fr;
    grid-template-rows: auto 1fr auto auto;
    grid-template-areas: 'logo head' 'logo list' 'logo empty' 'logo hint';
    column-gap: 28px;
  }
  .start-logo { grid-area: logo; align-self: center; width: 100%; height: auto; max-height: 100%; }
  .panel.start .panel-head { grid-area: head; }
  .panel.start #recent { grid-area: list; }
  .panel.start #start-empty { grid-area: empty; }
  .panel.start .hint { grid-area: hint; }
}
@media (max-width: 600px) {
  /* Phones: a smaller logo, and no controller hint (a phone rarely has a controller attached). */
  .start-logo { height: clamp(48px, 9vh, 90px); }
  .panel.start .hint { display: none; }
}
.panel-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.panel-head-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.muted[hidden] { display: none; }
.panel h1, .panel h2 { margin: 0; font-size: 24px; letter-spacing: 0; }
.muted { color: var(--gray); margin: 0; }
.hint { color: var(--gray); font-size: 16px; margin: 0; }

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--gray-dark) var(--black);
}
.list:empty { display: none; }
.list-heading { color: var(--yellow); font-size: 16px; margin-top: 6px; }
.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  font-size: 16px;
  color: var(--white);
  background: var(--black);
  border: 3px solid var(--gray-dark);
  padding: 10px 12px;
  cursor: pointer;
}
.item .detail { color: var(--gray); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.focused { border-color: var(--yellow); color: var(--yellow); }
.item:disabled { opacity: 0.45; cursor: default; }
.item.waiting .detail { color: var(--yellow); }

.toast {
  flex: 1 1 0;
  min-width: 0;
  margin-left: auto;
  text-align: right;
  font-size: 16px;
  color: var(--yellow);
  opacity: 0;
  transition: opacity 0.15s;
}
.toast.show { opacity: 1; }
.toast.error { color: var(--red); }

.sound-hint {
  padding: 4px 10px;
  font-size: 16px;
  color: var(--black);
  background: var(--gray);
  border: 3px solid var(--black);
}
.sound-hint[hidden] { display: none; }

/* ---- tablets and phones: the Game Genie panel covers the whole width; the bar stacks ---- */
@media (max-width: 960px) {
  .bar { justify-content: center; }
  .bar-actions { justify-content: center; }
}
@media (max-width: 900px) {
  .genie-panel { width: 100%; }
}
/* Mid-size windows: FULL SCREEN shortens to FULL so the top bar stays on one line. */
@media (max-width: 1240px) {
  #btn-full .long { display: none; }
}
/* Phones: no room for a fourth button, and iPhones do not offer full screen to web pages anyway. */
@media (max-width: 480px) {
  #btn-full { display: none; }
}
@media (max-width: 600px) {
  .bar { min-height: 60px; padding: 8px 12px; }
  .status { padding: 8px 12px; min-height: 0; flex-wrap: wrap; }
  .trial, .toast { flex: 1 1 100%; } /* each on its own line */
  .toast { text-align: left; margin-left: 0; }
  .brand-logo { height: 48px; }
  .bar-actions { gap: 8px; flex-wrap: wrap; justify-content: center; }
  .bar .btn { font-size: 16px; padding: 4px 8px; box-shadow: 3px 3px 0 var(--gray-dark); }
  .bar .long, .bar .key { display: none; } /* GENIE, OPEN, MENU: room for all three on one line */
  .screen-panel { padding: 14px 12px; }
  .screen-frame { padding: 6px; border-width: 4px; outline-width: 5px; }
  .genie-grid { gap: 5px; padding: 10px; }
  .gg-card { padding: 12px; }
  .gg-card h2 { font-size: 16px; }
  .gg-tabs { grid-template-columns: 1fr; gap: 10px; }
  .letter { font-size: 16px; }
  .slot { width: 20px; font-size: 16px; }
  .btn { font-size: 16px; padding: 6px 10px; }
}
