/* ============================================================
   CCG BROWSER C64
   Compact control-deck layout inspired by the interaction density of
   the GPL-derived emulator runtime while retaining CCG branding.
   ============================================================ */

:root {
  --emu-bg: #080a25;
  --emu-bg-deep: #03040f;
  --emu-panel: #111431;
  --emu-panel-2: #15183b;
  --emu-panel-3: #0d1029;
  --emu-line: #30356f;
  --emu-line-soft: rgba(107, 111, 204, 0.24);
  --emu-accent: #8d82ff;
  --emu-accent-2: #d568db;
  --emu-cyan: #7aa9ff;
  --emu-text: #ecebff;
  --emu-muted: #9ea1c5;
  --emu-dim: #74789d;
  --emu-ok: #80d9b1;
  --emu-warn: #e7de73;
  --emu-danger: #dd657a;
  --emu-shadow: 0 14px 34px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }

html,
body.ccg-c64-lab-body {
  min-height: 100%;
  margin: 0;
  background: var(--emu-bg);
}

body.ccg-c64-lab-body {
  color: var(--emu-text);
  font-family: var(--ccg-font-main, "Segoe UI", Arial, sans-serif);
  background:
    linear-gradient(rgba(112, 119, 226, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 119, 226, 0.06) 1px, transparent 1px),
    radial-gradient(circle at 48% -20%, rgba(95, 88, 210, 0.24), transparent 42%),
    linear-gradient(180deg, #0b0e35 0%, #07091f 62%, #040512 100%);
  background-size: 48px 48px, 48px 48px, auto, auto;
  overflow-x: hidden;
}

button,
select,
input {
  font: inherit;
}

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

button:focus-visible,
a:focus-visible,
select:focus-visible,
#ccg-c64-screen:focus-visible {
  outline: 2px solid var(--emu-accent);
  outline-offset: 2px;
}

/* Phones/tablets: emulator buttons are controls, not selectable text.
   Cover labels nested inside buttons and the expandable function-key
   summary. Keep input/select/textarea and ordinary page text untouched.
   Do not override touch-action: none on the D-pad, FIRE or keyboard. */
@media (pointer: coarse) {
  body.ccg-c64-lab-body button,
  body.ccg-c64-lab-body button *,
  body.ccg-c64-lab-body summary,
  body.ccg-c64-lab-body summary * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
}

/* Header ----------------------------------------------------- */

.ccg-c64-topbar {
  position: relative;
  z-index: 10;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem clamp(0.8rem, 2vw, 1.35rem);
  border-bottom: 1px solid rgba(120, 126, 231, 0.23);
  background: rgba(7, 9, 32, 0.92);
  box-shadow: 0 8px 26px rgba(0,0,0,0.18);
  backdrop-filter: blur(14px);
}

.ccg-c64-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  color: var(--emu-text);
  text-decoration: none;
}

.ccg-c64-brand img {
  width: 52px;
  height: 38px;
  object-fit: contain;
}

.ccg-c64-brand span {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  white-space: nowrap;
}

.ccg-c64-brand strong,
.ccg-c64-brand b {
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: clamp(1rem, 1.4vw, 1.35rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ccg-c64-brand strong { color: #f5f3ff; }
.ccg-c64-brand b {
  color: var(--emu-accent);
  text-shadow: 0 0 16px rgba(141, 130, 255, 0.35);
}

.ccg-c64-topnav {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.ccg-c64-topnav a,
.ccg-c64-topnav button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0.78rem;
  border: 1px solid var(--emu-line);
  border-radius: 7px;
  background: rgba(14, 17, 47, 0.8);
  color: #c9c9ef;
  text-decoration: none;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.ccg-c64-topnav a:hover,
.ccg-c64-topnav button:hover {
  color: #fff;
  border-color: var(--emu-accent);
  background: rgba(141, 130, 255, 0.11);
}

.ccg-c64-site-nav {
  position: relative;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.52rem clamp(0.8rem, 2vw, 1.35rem);
  overflow-x: auto;
  border-bottom: 1px solid rgba(120, 126, 231, 0.18);
  background: rgba(5, 7, 25, 0.94);
  scrollbar-width: thin;
}

.ccg-c64-site-nav a,
.ccg-c64-site-nav button {
  flex: 0 0 auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.48rem 0.72rem;
  border: 1px solid rgba(74, 80, 157, 0.8);
  border-radius: 7px;
  background: rgba(15, 18, 50, 0.86);
  color: #d6d7f7;
  text-decoration: none;
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.ccg-c64-site-nav a:hover,
.ccg-c64-site-nav button:hover {
  border-color: var(--emu-accent);
  color: #fff;
  background: rgba(141, 130, 255, 0.14);
}

.ccg-c64-site-nav .ccg-c64-back {
  border-color: rgba(213, 104, 219, 0.55);
  color: #ffd6ff;
}

/* Main workstation ------------------------------------------ */

.ccg-c64-workspace {
  width: min(1880px, calc(100% - 1.2rem));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.64fr) minmax(520px, 0.96fr);
  grid-template-areas: "console controls";
  gap: 0.8rem;
  padding: 0.8rem 0 1rem;
  align-items: start;
}

/*
   The installed CCG/PWA shell may inject route UI (for example a breadcrumb)
   as a direct child of <main>. This workstation must always remain a strict
   two-column application surface; an injected third grid item otherwise takes
   column 1 and pushes the emulator screen into column 2.
*/
.ccg-c64-workspace > :not(.ccg-c64-console):not(.ccg-c64-control-stack) {
  display: none !important;
}

.ccg-c64-console {
  grid-area: console;
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid var(--emu-line);
  border-radius: 13px;
  background:
    linear-gradient(145deg, rgba(74, 77, 151, 0.09), transparent 28%),
    rgba(8, 10, 28, 0.94);
  box-shadow: var(--emu-shadow);
}

.ccg-c64-display-head {
  min-height: 45px;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.1rem 0.35rem 0.65rem;
}

.ccg-c64-display-head > div:first-child {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.ccg-c64-display-head h1.ccg-c64-kicker { margin: 0; }
.ccg-c64-kicker {
  color: var(--emu-accent);
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.ccg-c64-display-head strong {
  overflow: hidden;
  color: #f5f4ff;
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: 0.7rem;
  letter-spacing: 0.07em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ccg-c64-live-state {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--emu-muted);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.07em;
}

.ccg-c64-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emu-ok);
  box-shadow: 0 0 12px rgba(128, 217, 177, 0.7);
}

.ccg-c64-screen-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: min(66vh, 760px);
  padding: clamp(0.6rem, 1.25vw, 1rem);
  overflow: hidden;
  border: 1px solid rgba(132, 135, 224, 0.27);
  border-radius: 10px;
  background:
    radial-gradient(circle at 50% 50%, #0c0f18 0%, #040508 66%, #010204 100%);
  box-shadow:
    inset 0 0 70px rgba(0,0,0,0.88),
    0 0 0 1px rgba(255,255,255,0.015);
}

.ccg-c64-screen-bezel {
  position: relative;
  width: min(100%, 1120px);
  aspect-ratio: 384 / 272;
  overflow: hidden;
  border: 8px solid #050608;
  border-radius: 10px;
  background: #000;
  box-shadow:
    0 0 0 1px rgba(144, 146, 232, 0.17),
    0 18px 46px rgba(0,0,0,0.55),
    inset 0 0 34px #000;
  transition: width 160ms ease;
}

#ccg-c64-screen {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.ccg-c64-screen-glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 4px;
  background:
    linear-gradient(118deg, rgba(255,255,255,0.028), transparent 18% 74%, rgba(255,255,255,0.012)),
    radial-gradient(circle at 50% 47%, transparent 66%, rgba(0,0,0,0.28) 100%);
  mix-blend-mode: screen;
}

.ccg-c64-screen-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.35rem 0.8rem;
  padding: 0.52rem 0.2rem 0;
  color: var(--emu-dim);
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: 0.53rem;
  letter-spacing: 0.08em;
}

.ccg-c64-stage-note {
  margin: 0.55rem 0 0;
  min-height: 34px;
  padding: 0.5rem 0.65rem;
  border-left: 3px solid var(--emu-warn);
  border-radius: 3px;
  background: rgba(231, 222, 115, 0.055);
  color: #c8c39a;
  font-size: 0.66rem;
  line-height: 1.45;
}

/* Right-side modular deck ----------------------------------- */

.ccg-c64-control-stack {
  grid-area: controls;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  align-items: start;
}

.ccg-c64-panel {
  min-width: 0;
  padding: 0.72rem;
  border: 1px solid var(--emu-line);
  border-radius: 11px;
  background:
    linear-gradient(145deg, rgba(103, 100, 200, 0.055), transparent 45%),
    var(--emu-panel);
  box-shadow: 0 10px 28px rgba(0,0,0,0.22);
}

.ccg-c64-panel--controls {
  grid-row: span 2;
}

.ccg-c64-panel--vault {
  grid-column: 1 / -1;
}

.ccg-c64-panel-title {
  min-height: 28px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.48rem;
  padding: 0 0 0.55rem;
  margin-bottom: 0.58rem;
  border-bottom: 1px solid var(--emu-line-soft);
}

.ccg-c64-panel-title > span {
  color: var(--emu-dim);
  font-size: 0.55rem;
  letter-spacing: -0.12em;
}

.ccg-c64-panel-title strong {
  color: #b4b5df;
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: 0.63rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.ccg-c64-panel-title em {
  overflow: hidden;
  color: var(--emu-dim);
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: 0.5rem;
  font-style: normal;
  letter-spacing: 0.05em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ccg-c64-status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 0.42rem;
}

.ccg-c64-status-grid > div {
  min-width: 0;
  padding: 0.5rem 0.55rem;
  border: 1px solid rgba(102, 108, 197, 0.18);
  border-radius: 7px;
  background: var(--emu-panel-3);
}

.ccg-c64-status-grid span,
.ccg-c64-status-grid strong {
  display: block;
}

.ccg-c64-status-grid span {
  color: var(--emu-dim);
  font-size: 0.49rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.ccg-c64-status-grid strong {
  margin-top: 0.18rem;
  overflow: hidden;
  color: #dbdcff;
  font-size: 0.61rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ccg-c64-status-grid b {
  color: var(--emu-ok);
  font-weight: 800;
}

/* Buttons --------------------------------------------------- */

.ccg-c64-button-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 0.38rem;
}

.ccg-c64-button-grid button,
.ccg-c64-media-row button,
.ccg-c64-vault-row button,
.ccg-c64-vault-row select,
.ccg-c64-rail-action {
  min-width: 0;
  border: 1px solid #373b74;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.025), transparent),
    #131633;
  color: #d4d5f4;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.ccg-c64-button-grid button {
  min-height: 57px;
  display: grid;
  place-content: center;
  gap: 0.16rem;
  padding: 0.42rem;
  text-align: center;
}

.ccg-c64-button-grid button span {
  color: #9b9dc2;
  font-size: 0.49rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.ccg-c64-button-grid button strong {
  overflow: hidden;
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: 0.58rem;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ccg-c64-button-grid button.is-power {
  border-color: rgba(213, 104, 219, 0.5);
  background: rgba(116, 48, 127, 0.22);
}

.ccg-c64-button-grid button[data-warp-load][aria-pressed="true"] {
  border-color: rgba(231, 222, 115, 0.62);
  background: rgba(126, 117, 45, 0.2);
  color: #fffbd0;
  box-shadow: inset 0 0 0 1px rgba(231, 222, 115, 0.08), 0 0 16px rgba(231, 222, 115, 0.08);
}

.ccg-c64-button-grid button[data-warp-load][aria-pressed="true"] span,
.ccg-c64-button-grid button[data-warp-load][aria-pressed="true"] strong {
  color: #fff6a8;
}

.ccg-c64-button-grid button:hover:not(:disabled),
.ccg-c64-media-row button:hover:not(:disabled),
.ccg-c64-vault-row button:hover:not(:disabled),
.ccg-c64-vault-row select:hover,
.ccg-c64-rail-action:hover {
  border-color: var(--emu-accent);
  background: rgba(91, 87, 173, 0.2);
}

.ccg-c64-button-grid button:active:not(:disabled),
.ccg-c64-media-row button:active:not(:disabled),
.ccg-c64-vault-row button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled,
select:disabled {
  opacity: 0.34;
  cursor: not-allowed;
}

.ccg-c64-media-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 0.4rem;
}

.ccg-c64-media-row--three {
  grid-template-columns: repeat(3, minmax(0,1fr));
}

.ccg-c64-media-row--four {
  grid-template-columns: repeat(4, minmax(0,1fr));
}

.ccg-c64-media-row button,
.ccg-c64-vault-row button,
.ccg-c64-vault-row select {
  min-height: 35px;
  padding: 0.42rem 0.48rem;
  color: #bfc0e3;
  font-size: 0.53rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.ccg-c64-media-row button[aria-pressed="true"] {
  border-color: rgba(128,217,177,0.48);
  color: var(--emu-ok);
  background: rgba(54, 106, 86, 0.16);
}

.ccg-c64-vault-row {
  display: grid;
  grid-template-columns: minmax(96px, .75fr) repeat(3, minmax(0,1fr));
  gap: 0.4rem;
}

.ccg-c64-vault-row select {
  appearance: auto;
}

.ccg-c64-port-row {
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto;
  align-items: center;
  gap: 0.55rem;
  min-height: 42px;
}

.ccg-c64-port-dot {
  width: 22px;
  height: 14px;
  border: 2px solid #7175b5;
  border-radius: 3px;
  background:
    radial-gradient(circle, #7175b5 1px, transparent 2px) 0 0/6px 6px;
}

.ccg-c64-port-row strong,
.ccg-c64-port-row small {
  display: block;
}

.ccg-c64-port-row strong {
  color: #d6d7f7;
  font-size: 0.57rem;
  letter-spacing: 0.07em;
}

.ccg-c64-port-row small {
  margin-top: 0.12rem;
  color: var(--emu-dim);
  font-size: 0.5rem;
}

/* Joystick switch lives inside the existing control-port panel. */
.ccg-c64-joystick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.3rem;
  margin-top: 0.25rem;
}

.ccg-c64-joystick-swap {
  display: block;
  width: 100%;
  margin-top: 0;
  min-height: 30px;
  padding: 0.2rem 0.4rem;
  border: 1px solid rgba(141, 130, 255, 0.55);
  border-radius: 6px;
  background: #181c45;
  color: #e1deff;
  font: 800 0.58rem var(--ccg-font-mono, "Courier New", monospace);
  cursor: pointer;
}
.ccg-c64-joystick-swap:hover,
.ccg-c64-joystick-swap:focus-visible {
  border-color: var(--emu-accent);
  background: rgba(111, 99, 196, 0.25);
}

.ccg-c64-chip {
  padding: 0.3rem 0.42rem;
  border: 1px solid rgba(128,217,177,0.3);
  border-radius: 6px;
  color: var(--emu-ok);
  font-size: 0.48rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}


/* File-first media flow -------------------------------------- */

.ccg-c64-panel--quickload,
.ccg-c64-panel--library {
  grid-column: 1 / -1;
}

/* No empty approval library panel or phantom space before genuine games exist. */
.ccg-c64-panel--library[hidden] {
  display: none !important;
}

.ccg-c64-quickload {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(0, 1.2fr);
  gap: 0.6rem;
  align-items: center;
}

.ccg-c64-primary-load {
  min-height: 46px;
  border: 1px solid rgba(213, 104, 219, 0.58);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(213,104,219,0.16), rgba(116,48,127,0.2));
  color: #fff;
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.ccg-c64-primary-load:hover,
.ccg-c64-primary-load:focus-visible {
  border-color: var(--emu-accent-2);
  background: rgba(213,104,219,0.22);
}

.ccg-c64-quickload p,
.ccg-c64-library-note {
  margin: 0;
  color: var(--emu-muted);
  font-size: 0.56rem;
  line-height: 1.45;
}

.ccg-c64-library-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px;
  gap: 0.4rem;
}

.ccg-c64-library-disks {
  margin-top: 0.35rem;
}

.ccg-c64-library-disks[hidden] {
  display: none !important;
}

.ccg-c64-library-row select,
.ccg-c64-library-row button {
  min-height: 38px;
  border: 1px solid #373b74;
  border-radius: 8px;
  background: #131633;
  color: #d4d5f4;
  font-size: 0.56rem;
  font-weight: 800;
}

.ccg-c64-library-row select {
  min-width: 0;
  padding: 0.45rem 0.55rem;
}

.ccg-c64-library-row button {
  cursor: pointer;
}

.ccg-c64-library-row button:hover:not(:disabled),
.ccg-c64-library-row select:hover {
  border-color: var(--emu-accent);
}

.ccg-c64-library-note {
  display: block;
  margin-top: 0.45rem;
}

/* Compact type-to-search library. The suggestion list overlays the
   command deck instead of growing its grid row or pushing controls down. */
.ccg-c64-panel--library {
  position: relative;
  min-width: 0;
  overflow: visible;
}
.ccg-c64-panel--library.is-suggesting {
  z-index: 70;
}
.ccg-c64-library-search-wrap {
  position: relative;
  min-width: 0;
}
.ccg-c64-library-search-wrap > input[type="search"] {
  display: block;
  width: 100%;
  min-width: 0;
  height: 39px;
  padding: 0.45rem 0.75rem;
  border: 1px solid #555198;
  border-radius: 6px;
  background: #0a0e28;
  color: #fff;
  font: 700 0.67rem var(--ccg-font-mono, "Courier New", monospace);
  letter-spacing: 0.025em;
}
.ccg-c64-library-search-wrap > input[type="search"]:focus-visible {
  outline: 2px solid var(--emu-accent);
  outline-offset: 1px;
}
.ccg-c64-library-confirm {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  min-height: 38px;
  margin-top: 0.35rem;
}

.ccg-c64-library-result-count {
  min-width: 0;
  flex: 1 1 auto;
  margin: 0;
  color: var(--emu-muted);
  font: 600 0.55rem/1.45 var(--ccg-font-mono, "Courier New", monospace);
  overflow-wrap: anywhere;
}

.ccg-c64-library-load {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0.48rem 0.78rem;
  border: 1px solid rgba(210, 113, 225, 0.75);
  border-radius: 6px;
  color: #fff;
  background: linear-gradient(180deg, rgba(170, 73, 191, 0.7), rgba(109, 42, 137, 0.9));
  font: 800 0.62rem var(--ccg-font-mono, "Courier New", monospace);
  cursor: pointer;
}

.ccg-c64-library-load[hidden] {
  display: none !important;
}
.ccg-c64-library-retry {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0.4rem 0.65rem;
  border: 1px solid rgba(224, 180, 87, 0.65);
  border-radius: 6px;
  color: #fff0bc;
  background: rgba(95, 63, 24, 0.68);
  font: 800 0.55rem var(--ccg-font-mono, "Courier New", monospace);
  cursor: pointer;
}
.ccg-c64-library-retry[hidden] { display: none !important; }
.ccg-c64-library-retry:hover,
.ccg-c64-library-retry:focus-visible {
  border-color: #f8d990;
  outline-offset: 2px;
}


.ccg-c64-library-load:hover:not(:disabled),
.ccg-c64-library-load:focus-visible {
  border-color: #eeb3f7;
  background: rgba(200, 101, 213, 0.48);
}

.ccg-c64-library-load:disabled {
  cursor: wait;
  opacity: 0.65;
}
.ccg-c64-library-suggestions {
  position: absolute;
  z-index: 75;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  min-width: 0;
  padding: 0.25rem;
  border: 1px solid #6763af;
  border-radius: 8px;
  background: #11152e;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.7);
}
.ccg-c64-library-suggestions[hidden] {
  display: none !important;
}
#ccg-c64-library-options {
  max-height: min(320px, 42dvh);
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.ccg-c64-library-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  gap: 0.7rem;
  padding: 0.72rem 0.68rem;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #f3f2ff;
  cursor: pointer;
}
.ccg-c64-library-option + .ccg-c64-library-option {
  border-top: 1px solid rgba(130, 131, 209, 0.16);
}
.ccg-c64-library-option strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font: 800 0.66rem/1.35 var(--ccg-font-mono, "Courier New", monospace);
}
.ccg-c64-library-option span {
  flex: 0 0 auto;
  color: #aab5ea;
  font: 800 0.5rem var(--ccg-font-mono, "Courier New", monospace);
  letter-spacing: 0.07em;
}
.ccg-c64-library-option:hover:not(:disabled),
.ccg-c64-library-option.is-active,
.ccg-c64-library-option:focus-visible {
  outline: none;
  border-color: rgba(166, 140, 255, 0.52);
  background: rgba(133, 94, 193, 0.25);
}
.ccg-c64-library-option:disabled {
  opacity: 0.55;
  cursor: wait;
}
.ccg-c64-library-no-results {
  margin: 0;
  padding: 0.9rem 0.7rem;
  color: var(--emu-muted);
  font-size: 0.65rem;
}
.ccg-c64-library-match-count {
  margin: 0;
  padding: 0.45rem 0.65rem 0.2rem;
  border-top: 1px solid var(--emu-line-soft);
  color: #b5b7e4;
  font: 700 0.49rem/1.5 var(--ccg-font-mono, "Courier New", monospace);
  letter-spacing: 0.055em;
}
.ccg-c64-library-disks {
  margin-top: 0.65rem;
}
@media (max-width: 600px) {
  .ccg-c64-library-search-wrap > input[type="search"] {
    font-size: 0.63rem;
  }
  #ccg-c64-library-options {
    max-height: min(260px, 38dvh);
  }
}

.ccg-c64-drop-hint {
  position: absolute;
  inset: auto 50% 1rem auto;
  z-index: 4;
  transform: translateX(50%);
  padding: 0.45rem 0.65rem;
  border: 1px solid rgba(141,130,255,0.34);
  border-radius: 7px;
  background: rgba(7,9,28,0.8);
  color: rgba(228,227,255,0.65);
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: 0.52rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  pointer-events: none;
  /* Never cover running games; show the hint during a file drag only. */
  opacity: 0;
  visibility: hidden;
  transition: opacity 120ms ease, transform 120ms ease, visibility 120ms ease;
}

.ccg-c64-screen-stage.is-dragover {
  border-color: var(--emu-accent);
  box-shadow: inset 0 0 70px rgba(0,0,0,0.88), 0 0 28px rgba(141,130,255,0.18);
}

.ccg-c64-screen-stage.is-dragover .ccg-c64-drop-hint {
  visibility: visible;
  opacity: 1;
  color: #fff;
  border-color: var(--emu-accent);
  background: rgba(62,55,137,0.86);
  transform: translateX(50%) scale(1.04);
}

/* Touch controller ----------------------------------------- */

.ccg-c64-touch-controls {
  display: none;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 0.65rem;
  padding: 0.7rem;
  border: 1px solid var(--emu-line-soft);
  border-radius: 9px;
  background: rgba(10, 12, 34, 0.82);
}

.ccg-c64-touch-dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 0.24rem;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.ccg-c64-touch-dpad button,
.ccg-c64-touch-fire,
.ccg-c64-touch-jump {
  border: 1px solid #4a4e8c;
  background: #171a3c;
  color: #e2e2ff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.ccg-c64-touch-dpad .ccg-c64-touch-diagonal {
  border-color: #373d6d;
  background: #11152f;
  color: #bcbdea;
  font-size: 0.85rem;
}
.ccg-c64-touch-dpad button.is-pressed {
  background: #584583;
  border-color: #d7b6ff;
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(233, 207, 255, 0.3);
}

.ccg-c64-touch-fire {
  width: 92px;
  height: 92px;
  border-color: rgba(213,104,219,0.5);
  border-radius: 50%;
  background: rgba(116, 48, 127, 0.2);
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

/* Optional joystick-UP JUMP, function keys remain in expandable drawer. */
.ccg-c64-touch-actions { display: flex; align-items: center; justify-content: center; gap: 0.3rem; min-width: 0; }
.ccg-c64-touch-actions .ccg-c64-touch-fire, .ccg-c64-touch-jump {
  flex: 0 1 auto; width: clamp(75px, 21vw, 102px); height: clamp(75px, 21vw, 102px);
}
.ccg-c64-touch-jump {
  border: 1px solid #829be3; border-radius: 50%; background: rgba(38,65,140,0.35);
  font: 800 0.75rem var(--ccg-font-mono, "Courier New", monospace);
  color: #eef3ff; touch-action: none;
}
.ccg-c64-touch-jump[hidden] { display: none !important; }
.ccg-c64-touch-options { display: none; align-items: flex-start; justify-content: center; gap: 0.55rem; margin-top: 0.4rem; flex-wrap: wrap; }
.ccg-c64-touch-options button, .ccg-c64-function-drawer summary {
  border: 1px solid #7774b9; border-radius: 7px; background: #20234d;
  color: #f4f0ff; min-height: 44px; padding: 0.5rem; cursor: pointer;
  font: 700 0.68rem var(--ccg-font-mono, "Courier New", monospace);
}
.ccg-c64-function-drawer summary { display: list-item; }
.ccg-c64-function-drawer .ccg-c64-touch-fkeys { margin-top: 0.35rem; }
/* Real C64 function keys for phones (not browser key events).
   The same matrix bindings as a physical F1/F3/F5/F7 keyboard are used. */
.ccg-c64-touch-fkeys {
  display: grid;
  grid-template-columns: repeat(2, minmax(44px, 1fr));
  gap: 0.25rem;
  flex: 0 0 auto;
  min-width: 0;
}
.ccg-c64-touch-fkeys button {
  min-width: 44px;
  min-height: 48px;
  padding: 0.3rem;
  border: 1px solid #7774b9;
  border-radius: 8px;
  background: #20234d;
  color: #f4f0ff;
  font: 800 0.7rem var(--ccg-font-mono, "Courier New", monospace);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}
.ccg-c64-touch-fkeys button.is-pressed,
.ccg-c64-touch-fkeys button:active {
  border-color: #dca4ea;
  background: #703b87;
}

/* Footer ---------------------------------------------------- */

.ccg-c64-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem 1rem;
  padding: 0.75rem 1rem 1.1rem;
  color: var(--emu-dim);
  font-size: 0.58rem;
}

.ccg-c64-footer a {
  color: #a9a2ff;
}

/* ROM setup ------------------------------------------------- */

.ccg-c64-setup[hidden] { display: none; }

.ccg-c64-setup {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 0.65rem;
}

.ccg-c64-setup__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 3, 13, 0.9);
  backdrop-filter: blur(10px);
}

.ccg-c64-setup__dialog {
  position: relative;
  z-index: 1;
  width: min(1060px, 100%);
  max-height: calc(100dvh - 1.3rem);
  overflow: auto;
  padding: 1rem;
  border: 1px solid #464b91;
  border-radius: 12px;
  background:
    linear-gradient(140deg, rgba(119, 109, 230, 0.08), transparent 35%),
    #0d1029;
  box-shadow: 0 30px 90px rgba(0,0,0,0.7);
}

.ccg-c64-setup__header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.ccg-c64-setup__header h2 {
  margin: 0.28rem 0 0;
  color: #f1efff;
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: clamp(1.05rem, 2.5vw, 1.55rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ccg-c64-setup__exit {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.62rem;
  border: 1px solid var(--emu-line);
  border-radius: 7px;
  color: var(--emu-muted);
  text-decoration: none;
  font-size: 0.56rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.ccg-c64-setup__lead {
  max-width: 88ch;
  margin: 0.7rem 0 0.85rem;
  color: var(--emu-muted);
  font-size: 0.73rem;
  line-height: 1.55;
}

.ccg-c64-setup__steps {
  display: grid;
  grid-template-columns: 0.9fr 1.35fr 0.8fr;
  gap: 0.55rem;
}

.ccg-c64-setup-step {
  min-width: 0;
  display: grid;
  grid-template-columns: 34px minmax(0,1fr);
  border: 1px solid var(--emu-line-soft);
  border-radius: 9px;
  overflow: hidden;
  background: rgba(7, 9, 29, 0.62);
}

.ccg-c64-setup-step__number {
  display: grid;
  place-items: start center;
  padding-top: 0.72rem;
  border-right: 1px solid var(--emu-line-soft);
  color: var(--emu-accent);
  background: rgba(91, 86, 181, 0.07);
  font-family: var(--ccg-font-mono, "Courier New", monospace);
  font-size: 0.56rem;
  font-weight: 800;
}

.ccg-c64-setup-step__body {
  min-width: 0;
  padding: 0.72rem;
}

.ccg-c64-setup-step h3 {
  margin: 0;
  color: #e8e7ff;
  font-size: 0.69rem;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.ccg-c64-setup-step p {
  margin: 0.4rem 0 0;
  color: var(--emu-muted);
  font-size: 0.64rem;
  line-height: 1.45;
}

.ccg-c64-file-trigger,
.ccg-c64-ready-button {
  min-height: 37px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.55rem;
  padding: 0.5rem 0.68rem;
  border: 1px solid #4f549b;
  border-radius: 7px;
  background: rgba(91, 86, 181, 0.12);
  color: #e5e4ff;
  font-size: 0.57rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  cursor: pointer;
}

.ccg-c64-setup-message {
  display: block;
  margin-top: 0.45rem;
  min-height: 2em;
  color: var(--emu-dim);
  font-size: 0.58rem;
  line-height: 1.4;
}

.ccg-c64-rom-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 0.34rem;
  margin-top: 0.5rem;
}

.ccg-c64-rom-slot {
  min-width: 0;
  display: grid;
  gap: 0.12rem;
  padding: 0.5rem;
  border: 1px solid #33376e;
  border-radius: 7px;
  background: #111431;
  cursor: pointer;
}

.ccg-c64-rom-slot:hover {
  border-color: var(--emu-accent);
}

.ccg-c64-rom-slot span,
.ccg-c64-rom-slot strong,
.ccg-c64-rom-slot small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ccg-c64-rom-slot span {
  color: #d9d9fa;
  font-size: 0.61rem;
  font-weight: 800;
}

.ccg-c64-rom-slot strong {
  color: var(--emu-warn);
  font-size: 0.51rem;
  letter-spacing: 0.05em;
}

.ccg-c64-rom-slot small {
  color: var(--emu-dim);
  font-size: 0.5rem;
}

.ccg-c64-rom-slot.is-ready {
  border-color: rgba(128,217,177,0.34);
  background: rgba(38, 81, 65, 0.13);
}

.ccg-c64-rom-slot.is-ready strong { color: var(--emu-ok); }

.ccg-c64-ready-button {
  width: 100%;
  border-color: rgba(128,217,177,0.35);
  background: rgba(42, 101, 78, 0.14);
}

.ccg-c64-ready-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.ccg-c64-setup__privacy {
  display: flex;
  gap: 0.7rem;
  align-items: baseline;
  margin-top: 0.55rem;
  padding: 0.52rem 0.62rem;
  border: 1px solid rgba(128,217,177,0.2);
  border-radius: 7px;
  background: rgba(41, 91, 72, 0.08);
}

.ccg-c64-setup__privacy strong {
  flex: 0 0 auto;
  color: var(--emu-ok);
  font-size: 0.54rem;
  letter-spacing: 0.08em;
}

.ccg-c64-setup__privacy span {
  color: #96afaa;
  font-size: 0.57rem;
  line-height: 1.4;
}

body.ccg-c64-lab-body.is-rom-setup-open { overflow: hidden; }

/* Legal page compatibility --------------------------------- */

.ccg-c64-lab {
  width: min(1100px, calc(100% - 1rem));
  margin: 0 auto;
  padding: 1rem 0;
}

.ccg-c64-legal-card {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 1rem;
  border: 1px solid var(--emu-line);
  border-radius: 12px;
  background: var(--emu-panel);
  box-shadow: var(--emu-shadow);
}

.ccg-c64-legal-card h1,
.ccg-c64-legal-card h2 { color: #f1efff; }

.ccg-c64-legal-card h2 {
  margin: 1.2rem 0 0.35rem;
  font-size: 0.95rem;
}

.ccg-c64-legal-card p {
  color: var(--emu-muted);
  font-size: 0.78rem;
  line-height: 1.6;
}

.ccg-c64-legal-card a { color: #aaa3ff; }

.ccg-c64-rail-action {
  display: inline-flex;
  padding: 0.55rem 0.7rem;
  color: #dad9f7;
  text-decoration: none;
  font-size: 0.62rem;
}

/* Responsive ------------------------------------------------ */

@media (max-width: 1360px) {
  .ccg-c64-workspace {
    grid-template-columns: minmax(0, 1.45fr) minmax(460px, 0.95fr);
  }

  .ccg-c64-screen-stage {
    min-height: min(60vh, 680px);
  }

  .ccg-c64-button-grid {
    grid-template-columns: repeat(2, minmax(0,1fr));
  }
}

@media (max-width: 1100px) {
  .ccg-c64-workspace {
    display: block;
  }

  .ccg-c64-console {
    margin-bottom: 0.7rem;
  }

  .ccg-c64-control-stack {
    grid-template-columns: repeat(3, minmax(0,1fr));
  }

  .ccg-c64-panel--controls {
    grid-row: auto;
    grid-column: span 2;
  }

  .ccg-c64-panel--vault {
    grid-column: span 2;
  }

  .ccg-c64-screen-stage {
    min-height: 0;
  }

  .ccg-c64-setup__steps {
    grid-template-columns: 1fr 1.3fr;
  }

  .ccg-c64-setup-step--final {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .ccg-c64-topbar {
    min-height: 60px;
    padding: 0.55rem 0.6rem;
  }

  .ccg-c64-brand img {
    width: 42px;
    height: 30px;
  }

  .ccg-c64-brand strong,
  .ccg-c64-brand b {
    font-size: 0.75rem;
  }

  .ccg-c64-topnav {
    gap: 0.25rem;
  }

  .ccg-c64-topnav a,
  .ccg-c64-topnav button {
    min-height: 33px;
    padding: 0.4rem 0.5rem;
    font-size: 0.52rem;
  }

  .ccg-c64-topnav a:nth-child(1) { display: none; }

  .ccg-c64-workspace {
    width: calc(100% - 0.5rem);
    padding-top: 0.25rem;
  }

  .ccg-c64-console {
    padding: 0.45rem;
    border-radius: 9px;
  }

  .ccg-c64-display-head {
    min-height: 40px;
    padding: 0.05rem 0.15rem 0.45rem;
  }

  .ccg-c64-live-state {
    display: none;
  }

  .ccg-c64-screen-stage {
    padding: 0.28rem;
    border-radius: 7px;
  }

  .ccg-c64-screen-bezel {
    border-width: 4px;
    border-radius: 6px;
  }

  .ccg-c64-screen-foot {
    font-size: 0.46rem;
  }

  .ccg-c64-screen-foot span:nth-child(2) { display: none; }

  .ccg-c64-touch-controls {
    display: flex;
  }

  .ccg-c64-control-stack {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .ccg-c64-quickload {
    grid-template-columns: 1fr;
  }

  .ccg-c64-panel--quickload,
  .ccg-c64-panel--library {
    grid-column: auto;
  }

  .ccg-c64-drop-hint {
    bottom: 0.55rem;
    font-size: 0.46rem;
  }

  .ccg-c64-panel,
  .ccg-c64-panel--controls,
  .ccg-c64-panel--vault {
    grid-column: auto;
    grid-row: auto;
  }

  .ccg-c64-button-grid {
    grid-template-columns: repeat(3, minmax(0,1fr));
  }

  .ccg-c64-button-grid button {
    min-height: 50px;
  }

  .ccg-c64-setup {
    padding: 0.25rem;
  }

  .ccg-c64-setup__dialog {
    max-height: calc(100dvh - 0.5rem);
    padding: 0.7rem;
    border-radius: 9px;
  }

  .ccg-c64-setup__steps {
    grid-template-columns: 1fr;
  }

  .ccg-c64-setup-step--final {
    grid-column: auto;
  }

  .ccg-c64-rom-grid {
    grid-template-columns: 1fr;
  }

  .ccg-c64-setup__privacy {
    align-items: start;
    flex-direction: column;
    gap: 0.25rem;
  }
}

@media (max-width: 420px) {
  .ccg-c64-brand span {
    display: grid;
    gap: 0;
  }

  .ccg-c64-brand strong,
  .ccg-c64-brand b {
    font-size: 0.63rem;
  }

  .ccg-c64-button-grid {
    grid-template-columns: repeat(2, minmax(0,1fr));
  }

  .ccg-c64-touch-dpad {
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(3, 42px);
  }

  .ccg-c64-touch-fire {
    width: 82px;
    height: 82px;
  }
}

/*
   Desktop single-screen console.
   Preserve every existing control, but arrange the deck in six compact rows.
   Do not lock scrolling when browser zoom/short-height layouts require it.
*/
@media (min-width: 960px) {
  .ccg-c64-topbar {
    min-height: 54px;
    padding-block: 0.38rem;
  }

  .ccg-c64-brand img {
    width: 44px;
    height: 33px;
  }

  .ccg-c64-topnav a,
  .ccg-c64-topnav button {
    min-height: 31px;
    padding: 0.38rem 0.62rem;
  }

  .ccg-c64-site-nav {
    padding-block: 0.29rem;
    gap: 0.34rem;
  }

  .ccg-c64-site-nav a,
  .ccg-c64-site-nav button {
    min-height: 28px;
    padding: 0.33rem 0.55rem;
  }

  .ccg-c64-workspace {
    width: min(1880px, calc(100% - 0.8rem));
    grid-template-columns: minmax(0, 1.5fr) minmax(500px, 1fr);
    gap: 0.5rem;
    padding: 0.42rem 0 0.24rem;
    align-items: start;
  }

  .ccg-c64-console {
    margin-bottom: 0;
    padding: 0.46rem;
  }

  .ccg-c64-display-head {
    min-height: 36px;
    padding: 0 0.2rem 0.38rem;
  }

  .ccg-c64-screen-stage {
    min-height: 0;
    height: min(64vh, calc(100dvh - 250px));
    padding: 0.35rem;
  }

  .ccg-c64-screen-bezel {
    /* app.js sizes FIT from actual available stage height and width. */
    max-width: 100%;
  }

  .ccg-c64-screen-foot {
    padding-top: 0.3rem;
    font-size: 0.52rem;
  }

  .ccg-c64-stage-note {
    min-height: 0;
    margin: 0.35rem 0 0;
    padding: 0.32rem 0.5rem;
    font-size: 0.65rem;
  }

  .ccg-c64-control-stack {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-areas:
      "quick quick quick quick quick quick"
      "controls controls controls controls controls controls"
      "status status status port port port"
      "disk disk disk tape tape tape"
      "cartridge cartridge cartridge rom rom rom"
      "vault vault vault vault vault vault";
    gap: 0.38rem;
    align-items: stretch;
    align-content: start;
  }

  .ccg-c64-control-stack.has-online-library {
    grid-template-areas:
      "quick quick quick quick quick quick"
      "online online online online online online"
      "controls controls controls controls controls controls"
      "status status status port port port"
      "disk disk disk tape tape tape"
      "cartridge cartridge cartridge rom rom rom"
      "vault vault vault vault vault vault";
  }

  .ccg-c64-panel--quickload { grid-area: quick; }
  .ccg-c64-panel--library { grid-area: online; }
  .ccg-c64-panel--controls { grid-area: controls; }
  .ccg-c64-panel--status { grid-area: status; }
  .ccg-c64-panel--port { grid-area: port; }
  .ccg-c64-panel--disk { grid-area: disk; }
  .ccg-c64-panel--tape { grid-area: tape; }
  .ccg-c64-panel--cartridge { grid-area: cartridge; }
  .ccg-c64-panel--rom { grid-area: rom; }
  .ccg-c64-panel--vault { grid-area: vault; }

  .ccg-c64-panel {
    padding: 0.43rem 0.49rem;
    border-radius: 8px;
  }

  .ccg-c64-panel-title {
    min-height: 18px;
    padding-bottom: 0.28rem;
    margin-bottom: 0.35rem;
    gap: 0.32rem;
  }

  .ccg-c64-panel-title strong { font-size: 0.57rem; }
  .ccg-c64-panel-title em { font-size: 0.48rem; }

  .ccg-c64-quickload {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .ccg-c64-primary-load { min-height: 32px; font-size: 0.62rem; }

  .ccg-c64-quickload p,
  .ccg-c64-library-note {
    font-size: 0.53rem;
    line-height: 1.3;
  }

  .ccg-c64-library-row {
    grid-template-columns: minmax(0, 1fr) 57px;
    gap: 0.3rem;
  }

  .ccg-c64-library-row select,
  .ccg-c64-library-row button {
    min-height: 33px;
    font-size: 0.55rem;
  }

  .ccg-c64-library-note { margin-top: 0.24rem; }

  .ccg-c64-button-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.3rem;
  }

  .ccg-c64-button-grid button {
    min-height: 39px;
    padding: 0.25rem;
    gap: 0.07rem;
  }

  .ccg-c64-button-grid button span { font-size: 0.5rem; }
  .ccg-c64-button-grid button strong { font-size: 0.58rem; }

  .ccg-c64-status-grid { gap: 0.28rem; }
  .ccg-c64-status-grid > div { padding: 0.26rem 0.4rem; }

  .ccg-c64-media-row { gap: 0.28rem; }
  .ccg-c64-media-row button,
  .ccg-c64-vault-row button,
  .ccg-c64-vault-row select {
    min-height: 31px;
    padding: 0.25rem 0.3rem;
    font-size: 0.55rem;
  }

  .ccg-c64-vault-row { gap: 0.3rem; }
  .ccg-c64-port-row { min-height: 27px; }
  .ccg-c64-joystick-swap { min-height: 25px; margin-top: 0.2rem; }
  .ccg-c64-footer { padding: 0.24rem 0.7rem 0.4rem; }
}

/* Small monitors and high zoom must retain access to every button.
   Scaling the emulator up should never cut off inputs or trap the scroll. */
@media (min-width: 960px) and (max-height: 700px) {
  .ccg-c64-control-stack { gap: 0.26rem; }
  .ccg-c64-panel { padding: 0.25rem 0.4rem; }
  .ccg-c64-panel-title { margin-bottom: 0.2rem; padding-bottom: 0.2rem; }
  .ccg-c64-button-grid button { min-height: 33px; }
  .ccg-c64-media-row button,
  .ccg-c64-vault-row button,
  .ccg-c64-vault-row select { min-height: 27px; }
  .ccg-c64-status-grid > div { padding: 0.18rem 0.35rem; }
  .ccg-c64-stage-note { font-size: 0.59rem; }

  .ccg-c64-screen-stage {
    height: max(250px, calc(100dvh - 255px));
  }

  .ccg-c64-screen-bezel {
    max-width: 100%;
  }
}


/* Expanded SIZE mode gives the game its own wide row rather than constraining
   it beside the controls. The panel layout returns when SIZE NORMAL is used. */
@media (min-width: 960px) {
  .ccg-c64-workspace.is-display-expanded {
    display: block;
    width: min(1880px, calc(100% - 0.8rem));
  }

  .ccg-c64-workspace.is-display-expanded .ccg-c64-console {
    margin-bottom: 0.75rem;
  }

  .ccg-c64-workspace.is-display-expanded .ccg-c64-screen-stage {
    height: min(90dvh, 980px);
    min-height: min(68dvh, 760px);
  }

  .ccg-c64-workspace.is-display-expanded .ccg-c64-control-stack {
    width: 100%;
  }
}

/* The FULL button targets the picture stage alone, not its smaller parent
   console with a status header and a vh-limited game viewport. The actual
   C64 image stays at its native 384:272 ratio instead of being stretched. */
.ccg-c64-screen-stage:fullscreen {
  display: grid;
  place-items: center;
  width: 100vw !important;
  height: 100dvh !important;
  min-height: 100dvh !important;
  max-height: none !important;
  margin: 0;
  padding: 0 !important;
  border: 0;
  border-radius: 0;
  background: #000;
  box-shadow: none;
}

.ccg-c64-screen-stage:fullscreen .ccg-c64-screen-bezel {
  max-width: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transition: none;
}

.ccg-c64-screen-stage:fullscreen .ccg-c64-screen-glass {
  border-radius: 0;
}


/* Mobile gameplay: maximise the PAL picture, keep touch targets accessible,
   and never allow the search overlay or a control row to widen the viewport. */
@media (max-width: 760px) {
  .ccg-c64-topbar {
    flex-wrap: wrap;
    row-gap: 0.4rem;
    min-height: 0;
    padding: 0.5rem max(0.5rem, env(safe-area-inset-right)) 0.5rem max(0.5rem, env(safe-area-inset-left));
  }
  .ccg-c64-brand { gap: 0.32rem; flex: 1 1 auto; }
  .ccg-c64-brand span { white-space: normal; flex-wrap: wrap; }
  .ccg-c64-topnav { flex: 0 1 auto; flex-wrap: wrap; justify-content: flex-end; }
  .ccg-c64-topnav a, .ccg-c64-topnav button { min-height: 40px; }
  .ccg-c64-site-nav { justify-content: flex-start; overscroll-behavior-x: contain; }
  .ccg-c64-site-nav a, .ccg-c64-site-nav button { min-height: 40px; }
  .ccg-c64-workspace { width: 100%; padding: 0.3rem 0.35rem 0.85rem; }
  .ccg-c64-console { padding: 0.34rem; margin-bottom: 0.5rem; }
  .ccg-c64-screen-stage { min-height: 0; height: auto; padding: 0.16rem; }
  .ccg-c64-screen-bezel { width: 100%; max-width: 100%; border-width: 2px; }
  .ccg-c64-drop-hint { display: none; }
  .ccg-c64-stage-note { line-height: 1.4; font-size: 0.63rem; overflow-wrap: anywhere; }
  .ccg-c64-touch-controls {
    display: flex;
    align-items: center;
    justify-content: space-around;
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding: 0.6rem 0.25rem;
    touch-action: manipulation;
  }
  .ccg-c64-touch-options { display: flex; }
  .ccg-c64-touch-dpad {
    grid-template-columns: repeat(3, clamp(44px, 13vw, 58px));
    grid-template-rows: repeat(3, clamp(44px, 13vw, 58px));
    gap: 0.12rem;
  }
  .ccg-c64-touch-dpad button { min-width: 44px; min-height: 44px; border-radius: 9px; font-size: 1rem; }
  .ccg-c64-touch-fire { flex: 0 0 auto; width: clamp(80px, 24vw, 112px); height: clamp(80px, 24vw, 112px); }
  .ccg-c64-panel, .ccg-c64-quickload, .ccg-c64-library-confirm { min-width: 0; }
  .ccg-c64-panel-title { gap: 0.25rem; }
  .ccg-c64-panel-title strong { font-size: 0.64rem; }
  .ccg-c64-panel-title em { font-size: 0.53rem; text-align: right; overflow-wrap: anywhere; }
  .ccg-c64-library-search-wrap > input[type="search"] { min-height: 46px; font-size: 16px; }
  .ccg-c64-library-suggestions { z-index: 90; }
  #ccg-c64-library-options { max-height: min(46dvh, 340px); }
  .ccg-c64-library-option { min-height: 48px; }
  .ccg-c64-library-confirm { flex-wrap: wrap; align-items: center; }
  .ccg-c64-library-load, .ccg-c64-library-retry { min-height: 44px; }
  .ccg-c64-library-row { grid-template-columns: minmax(0, 1fr) auto; }
  .ccg-c64-library-row select { min-width: 0; }
  .ccg-c64-button-grid button { min-height: 46px; }
  .ccg-c64-media-row, .ccg-c64-vault-row { min-width: 0; }
  .ccg-c64-media-row button, .ccg-c64-vault-row button,
  .ccg-c64-vault-row select, .ccg-c64-joystick-actions button { min-height: 44px; }
  .ccg-c64-setup__dialog { overscroll-behavior: contain; }
  .ccg-c64-footer { padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
}
/* Preserve desktop fullscreen unchanged. For touch devices, fullscreen the
   whole console so gameplay never loses its on-screen joystick and FIRE. */
@media (max-width: 760px), (pointer: coarse) {
  .ccg-c64-console:fullscreen {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: max(0.3rem, env(safe-area-inset-top)) max(0.35rem, env(safe-area-inset-right))
      max(0.35rem, env(safe-area-inset-bottom)) max(0.35rem, env(safe-area-inset-left));
    margin: 0;
    border: 0;
    border-radius: 0;
    background: #03040e;
  }
  .ccg-c64-console:fullscreen .ccg-c64-display-head { min-height: 28px; padding-bottom: 0.15rem; }
  .ccg-c64-console:fullscreen .ccg-c64-screen-stage {
    flex: 0 0 auto;
    min-height: 0;
    width: 100%;
    padding: 0;
  }
  .ccg-c64-console:fullscreen .ccg-c64-screen-bezel { width: 100%; max-width: 100%; }
  .ccg-c64-console:fullscreen .ccg-c64-screen-foot,
  .ccg-c64-console:fullscreen .ccg-c64-stage-note { display: none; }
  .ccg-c64-console:fullscreen .ccg-c64-touch-options {
    display: flex; flex: 0 0 auto; margin-top: 0.1rem;
  }
  .ccg-c64-console:fullscreen .ccg-c64-touch-controls {
    display: flex;
    flex: 1 0 auto;
    align-items: center;
    justify-content: space-around;
    padding: 0.4rem;
  }
}
@media (max-width: 760px) and (orientation: landscape) {
  .ccg-c64-console { padding: 0.25rem; }
  .ccg-c64-screen-stage { min-height: 0; }
  .ccg-c64-console:fullscreen { overflow-y: auto; }
  .ccg-c64-console:fullscreen .ccg-c64-screen-bezel { width: 100%; }
  .ccg-c64-console:fullscreen .ccg-c64-touch-controls {
    flex: 0 0 auto;
    padding: 0.25rem 0;
  }
  .ccg-c64-console:fullscreen .ccg-c64-touch-dpad {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
  }
  .ccg-c64-console:fullscreen .ccg-c64-touch-fire { width: 80px; height: 80px; }
}
/* Landscape phones frequently report CSS widths above 760px. Apply the
   phone deck whenever a coarse-pointer device is held horizontally. */
@media (pointer: coarse) and (orientation: landscape) and (max-width: 1100px) {
  .ccg-c64-workspace { display: block; width: 100%; padding: 0.25rem 0.4rem; }
  .ccg-c64-control-stack { grid-template-columns: 1fr; gap: 0.45rem; }
  .ccg-c64-control-stack > .ccg-c64-panel { grid-column: auto; grid-row: auto; grid-area: auto; }
  .ccg-c64-console { margin-bottom: 0.5rem; }
  .ccg-c64-screen-stage { height: auto; min-height: 0; }
  .ccg-c64-touch-controls { display: flex; justify-content: space-around; }
  .ccg-c64-touch-options { display: flex; }
  .ccg-c64-console:fullscreen {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(176px, 33%);
    grid-template-rows: minmax(0, 1fr);
    align-items: center;
    gap: 0.35rem;
    overflow: hidden;
  }
  .ccg-c64-console:fullscreen .ccg-c64-display-head { display: none; }
  .ccg-c64-console:fullscreen .ccg-c64-screen-stage {
    grid-column: 1;
    grid-row: 1;
    height: auto;
    min-height: 0;
  }
  .ccg-c64-console:fullscreen .ccg-c64-touch-controls {
    grid-column: 2;
    grid-row: 1;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.35rem;
    min-width: 0;
  }
  .ccg-c64-console:fullscreen .ccg-c64-screen-bezel {
    width: min(100%, 120dvh);
  }
  .ccg-c64-console:fullscreen .ccg-c64-touch-dpad {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
  }
  .ccg-c64-console:fullscreen .ccg-c64-touch-fire { width: 80px; height: 80px; }
  .ccg-c64-console:fullscreen .ccg-c64-touch-options {
    grid-column: 2; grid-row: 1; align-self: end; justify-content: center;
    position: relative; z-index: 5; margin-top: 0; padding-bottom: 0.15rem;
  }
  .ccg-c64-console:fullscreen .ccg-c64-function-drawer[open] {
    position: absolute; right: 0; bottom: 100%; padding: 0.3rem;
    background: #0a0d24; border: 1px solid #7774b9; border-radius: 6px;
  }
}
@media (max-width: 360px) {
  .ccg-c64-button-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ccg-c64-touch-dpad { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); }
  .ccg-c64-touch-fire { width: 78px; height: 78px; }
}

/* Portable local-only ROM bank: desktop export and phone import controls. */
.ccg-c64-setup__transfer {
  display: grid;
  gap: 0.55rem;
  min-width: 0;
  margin: 0 0 0.75rem;
  padding: 0.72rem;
  border: 1px solid rgba(147, 132, 232, 0.55);
  border-radius: 8px;
  background: rgba(19, 22, 52, 0.78);
}
.ccg-c64-setup__transfer strong {
  font-size: 0.75rem;
  color: #f1edff;
}
.ccg-c64-setup__transfer p {
  margin: 0.35rem 0 0;
  font-size: 0.76rem;
  line-height: 1.5;
  color: #c4c3e1;
}
.ccg-c64-setup__transfer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.ccg-c64-setup__transfer-actions button,
.ccg-c64-setup__transfer-actions label {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 1px solid #8c83d0;
  border-radius: 8px;
  background: #24254a;
  color: #f4f0ff;
  font: 700 0.73rem var(--ccg-font-mono, "Courier New", monospace);
  cursor: pointer;
}
.ccg-c64-setup__transfer-actions button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}
.ccg-c64-setup__transfer output {
  display: block;
  font-size: 0.72rem;
  color: #e0d7ff;
}

/* Mobile player flow: C64 display -> game search/select/LOAD -> controls.
   The DOM is moved by app.js; this affects no desktop elements. */
@media (max-width: 760px), (pointer: coarse) and (orientation: landscape) and (max-width: 1100px) {
  .ccg-c64-console > .ccg-c64-panel--library {
    width: 100%;
    min-width: 0;
    margin: 0.45rem 0 0;
    padding: 0.55rem;
    border-radius: 8px;
    grid-area: auto;
  }
  .ccg-c64-console > .ccg-c64-panel--library[hidden] {
    display: none !important;
  }
  .ccg-c64-console > .ccg-c64-panel--library.is-suggesting {
    position: relative;
    z-index: 90;
  }
  .ccg-c64-console > .ccg-c64-panel--library input[type="search"] {
    min-height: 46px;
    font-size: 16px;
  }
  /* The old named grid has an empty library row after the panel moves. */
  .ccg-c64-control-stack,
  .ccg-c64-control-stack.has-online-library {
    grid-template-areas: none;
    grid-template-columns: minmax(0, 1fr);
  }
  .ccg-c64-control-stack > .ccg-c64-panel {
    grid-area: auto;
    grid-row: auto;
  }
  .ccg-c64-console > .ccg-c64-screen-foot,
  .ccg-c64-console > .ccg-c64-drop-hint {
    display: none;
  }
  .ccg-c64-console:fullscreen > .ccg-c64-panel--library {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ccg-c64-screen-bezel,
  .ccg-c64-button-grid button,
  .ccg-c64-media-row button,
  .ccg-c64-vault-row button {
    transition: none;
  }
}


/* Immersive in-game workspace is enabled only by the coarse-pointer game
   loader. All desktop layouts (including the FULL display control) are unchanged.
   Position-fixed is deliberate: iOS Safari does not allow fullscreen on divs. */
.ccg-c64-mobile-playbar[hidden],
.ccg-c64-mobile-keyboard[hidden] { display: none !important; }
/* Extra touch controls exist in the DOM for mobile gameplay only. */
.ccg-c64-mobile-joystick-swap { display: none !important; }
.ccg-c64-mobile-warp-load { display: none !important; }
.ccg-c64-mobile-playbar,
.ccg-c64-mobile-keyboard { display: none; }

@media (pointer: coarse) {
  body.ccg-c64-lab-body.is-mobile-playing { overflow: hidden; }
  .ccg-c64-console.is-mobile-playing,
  .ccg-c64-console.is-mobile-playing:fullscreen {
    position: fixed !important;
    z-index: 5000;
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-width: 100%;
    max-height: 100dvh;
    margin: 0;
    padding: max(0.35rem, env(safe-area-inset-top))
      max(0.45rem, env(safe-area-inset-right))
      max(0.35rem, env(safe-area-inset-bottom))
      max(0.45rem, env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    overflow: hidden;
    overscroll-behavior: none;
    border: 0;
    border-radius: 0;
    background: #040616;
  }
  /* Restore the original single-row mobile playbar. The zoom release used a
     two-line grid here, shrinking the game viewport and shifting its snap. */
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-playbar {
    display: flex;
    order: 0;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    min-height: 44px;
    width: 100%;
  }
  .ccg-c64-mobile-play-centre {
    display: flex;
    flex: 1 1 auto;
    justify-content: center;
    align-items: center;
    min-width: 0;
  }
  /* Keep the current game title in the DOM for screen readers and updates,
     without introducing a second row that can clip mobile gameplay. */
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-play-title {
    display: none;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-playbar .ccg-c64-mobile-zoom-toggle {
    min-height: 44px;
    flex: 0 0 auto;
    width: auto;
    max-width: 100%;
    padding: 0.35rem 0.45rem;
    border-color: #9b8be8;
    background: #2b285f;
    white-space: nowrap;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-playbar .ccg-c64-mobile-zoom-toggle[aria-pressed="true"] {
    border-color: #f3cb70;
    background: #5a441b;
    color: #fff2c8;
  }
  .ccg-c64-mobile-playbar button,
  .ccg-c64-mobile-keyboard-head button {
    min-height: 44px;
    flex: 0 0 auto;
    padding: 0.45rem 0.7rem;
    color: #f8f5ff;
    font: 800 0.69rem var(--ccg-font-mono, "Courier New", monospace);
    letter-spacing: 0.03em;
    background: #222650;
    border: 1px solid #827ad3;
    border-radius: 8px;
    touch-action: manipulation;
  }
  .ccg-c64-mobile-playbar .ccg-c64-mobile-exit { background: #572139; border-color: #df8da0; }
  .ccg-c64-mobile-playbar .ccg-c64-mobile-keyboard-toggle[aria-pressed="true"] {
    background: #4c3c83;
    border-color: #d0b1ff;
  }
  .ccg-c64-mobile-play-title {
    display: block;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: center;
    color: #c6c7e8;
    font: 700 0.64rem var(--ccg-font-mono, "Courier New", monospace);
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-display-head,
  .ccg-c64-console.is-mobile-playing .ccg-c64-screen-foot,
  .ccg-c64-console.is-mobile-playing .ccg-c64-stage-note,
  .ccg-c64-console.is-mobile-playing .ccg-c64-drop-hint,
  .ccg-c64-console.is-mobile-playing > .ccg-c64-panel--library {
    display: none !important;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-screen-stage,
  .ccg-c64-console.is-mobile-playing:fullscreen .ccg-c64-screen-stage {
    display: grid;
    order: 1;
    flex: 1 1 auto;
    align-items: center;
    justify-items: center;
    grid-column: auto;
    grid-row: auto;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: auto;
    padding: 0;
    overflow: hidden;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-screen-bezel,
  .ccg-c64-console.is-mobile-playing:fullscreen .ccg-c64-screen-bezel {
    height: auto;
    max-height: 100%;
    max-width: 100%;
    flex: 0 0 auto;
    border-width: 2px;
    aspect-ratio: 384 / 272;
  }
  /* Trim about 6.5% per edge of the emulated 384×272 PAL border.
     Scale the picture *inside* the clipped bezel, not the bezel itself:
     desktop, FIT measurements, touchscreen geometry and overlays are intact. */
  .ccg-c64-console.is-mobile-playing .ccg-c64-screen-bezel > #ccg-c64-screen {
    transform-origin: center center;
    transition: transform 160ms ease-out;
  }
  .ccg-c64-console.is-mobile-playing.is-mobile-zoomed .ccg-c64-screen-bezel > #ccg-c64-screen {
    transform: scale(1.15);
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-controls,
  .ccg-c64-console.is-mobile-playing:fullscreen .ccg-c64-touch-controls {
    display: flex;
    flex-direction: row;
    order: 2;
    grid-column: auto;
    grid-row: auto;
    align-self: stretch;
    justify-content: space-around;
    align-items: center;
    flex: 0 0 auto;
    gap: 0.5rem;
    margin: 0;
    padding: 0.28rem 0.4rem;
    min-width: 0;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-dpad,
  .ccg-c64-console.is-mobile-playing:fullscreen .ccg-c64-touch-dpad {
    grid-template-columns: repeat(3, clamp(40px, 11vw, 52px));
    grid-template-rows: repeat(3, clamp(40px, 11vw, 52px));
    gap: 0.1rem;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-dpad button { min-width: 40px; min-height: 40px; }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-fire,
  .ccg-c64-console.is-mobile-playing:fullscreen .ccg-c64-touch-fire {
    width: clamp(72px, 19vw, 104px);
    height: clamp(72px, 19vw, 104px);
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-options,
  .ccg-c64-console.is-mobile-playing:fullscreen .ccg-c64-touch-options {
    display: flex;
    position: static;
    order: 3;
    grid-column: auto;
    grid-row: auto;
    align-self: stretch;
    flex: 0 0 auto;
    margin: 0;
    padding: 0;
    justify-content: center;
  }
  /* Always reachable at the lower-right of the mobile control deck.
     The existing desktop switch remains in its original location. */
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-options {
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 0.8fr) minmax(0, 1.45fr);
    align-items: stretch;
    gap: clamp(0.18rem, 1.2vw, 0.35rem);
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-options > button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 0.35rem 0.15rem;
    font-size: clamp(0.54rem, 2vw, 0.69rem);
    line-height: 1.2;
    touch-action: manipulation;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-warp-load {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    border-color: #b6a4f8;
    background: #2d2759;
    color: #fff3d5;
    font-weight: 850;
    letter-spacing: 0.01em;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-warp-load[aria-pressed="true"] {
    border-color: #f3d06a;
    background: #705120;
    color: #fff8df;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-warp-load:disabled {
    opacity: 0.53;
    cursor: not-allowed;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-joystick-swap {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    margin-left: 0;
    flex: 0 1 auto;
    min-width: 0;
    min-height: 44px;
    padding: 0.35rem clamp(0.18rem, 1.2vw, 0.45rem);
    border: 1px solid #8d82ff;
    border-radius: 8px;
    background: #252858;
    color: #f5f2ff;
    font: 800 clamp(0.54rem, 2vw, 0.69rem) var(--ccg-font-mono, "Courier New", monospace);
    letter-spacing: 0.01em;
    white-space: normal;
    overflow-wrap: anywhere;
    touch-action: manipulation;
    cursor: pointer;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-joystick-swap:active {
    background: #4b418a;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-function-drawer { display: none; }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-keyboard {
    position: absolute;
    z-index: 60;
    display: block;
    inset: auto 0 0;
    max-height: min(70dvh, 410px);
    overflow: auto;
    overscroll-behavior: contain;
    padding: 0.5rem max(0.4rem, env(safe-area-inset-right))
      max(0.55rem, env(safe-area-inset-bottom))
      max(0.4rem, env(safe-area-inset-left));
    border-top: 2px solid #8d82ff;
    border-radius: 14px 14px 0 0;
    background: rgba(9, 12, 36, 0.98);
    box-shadow: 0 -12px 46px #000b;
  }
  .ccg-c64-mobile-keyboard-head {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.42rem;
    font: 800 0.65rem var(--ccg-font-mono, "Courier New", monospace);
  }
  .ccg-c64-mobile-keyboard-head span { color: #aeb2d6; font-size: 0.53rem; }
  .ccg-c64-mobile-keyboard-head button { min-height: 36px; }
  .ccg-c64-mobile-keyboard-row { display: flex; min-width: 0; gap: 0.15rem; margin-bottom: 0.15rem; }
  .ccg-c64-mobile-keyboard-row button {
    min-width: 0;
    flex: 1 1 0;
    min-height: 42px;
    padding: 0.1rem;
    border-radius: 5px;
    border: 1px solid #5b608f;
    background: #20284d;
    color: #f6f5ff;
    font: 750 clamp(0.53rem, 1.85vw, 0.75rem) var(--ccg-font-mono, "Courier New", monospace);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
  .ccg-c64-mobile-keyboard-row button.is-pressed {
    background: #8067b8;
    border-color: #e3b7ff;
  }
  .ccg-c64-mobile-keyboard-row button[data-c64-vkey="Space"] { flex: 4 1 0; }
  .ccg-c64-mobile-keyboard-row button[data-c64-vkey="Enter"],
  .ccg-c64-mobile-keyboard-row button[data-c64-vkey="ShiftLeft"],
  .ccg-c64-mobile-keyboard-row button[data-c64-vkey="ShiftRight"] { flex: 1.7 1 0; }
  .ccg-c64-mobile-keyboard-row button[data-c64-vkey="F12"],
  .ccg-c64-mobile-keyboard-row button[data-c64-vkey="F9"] { flex: 1.7 1 0; }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 490px) {
  .ccg-c64-console.is-mobile-playing,
  .ccg-c64-console.is-mobile-playing:fullscreen { gap: 0.15rem; }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-playbar { min-height: 38px; }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-playbar button { min-height: 38px; padding: 0.25rem 0.5rem; }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-playbar .ccg-c64-mobile-zoom-toggle { min-height: 38px; }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-controls { padding: 0.1rem 0.35rem; }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-dpad,
  .ccg-c64-console.is-mobile-playing:fullscreen .ccg-c64-touch-dpad {
    grid-template-columns: repeat(3, 38px);
    grid-template-rows: repeat(3, 38px);
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-dpad button { min-width: 38px; min-height: 38px; }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-options button { min-height: 36px; }
}


/* Dedicated C64 app installation is mobile/tablet-only; the desktop emulator
   and the separate site-wide CCG PWA retain their existing behaviour. */
.ccg-c64-install-promo, .ccg-c64-install-promo[hidden] { display: none !important; }
@media (pointer: coarse) {
  .ccg-c64-console:not(.is-mobile-playing) > .ccg-c64-install-promo:not([hidden]) {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.4rem 0.6rem;
    margin: 0.1rem 0 0.75rem;
    padding: 0.7rem 0.65rem;
    border: 1px solid rgba(133, 154, 255, 0.5);
    border-radius: 10px;
    background: linear-gradient(130deg, #1a2559, #101338);
  }
  .ccg-c64-console:fullscreen > .ccg-c64-install-promo { display: none !important; }
  .ccg-c64-install-promo__intro {
    display: grid;
    gap: 0.2rem;
    min-width: 0;
  }
  .ccg-c64-install-promo__intro strong {
    color: #faf7ff;
    font: 850 0.64rem var(--ccg-font-mono, "Courier New", monospace);
    letter-spacing: 0.03em;
  }
  .ccg-c64-install-promo__intro span,
  .ccg-c64-install-promo p {
    color: #c5c9ec;
    font: 600 0.61rem/1.45 var(--ccg-font-main, "Segoe UI", Arial, sans-serif);
  }
  .ccg-c64-install-promo > button {
    min-height: 44px;
    padding: 0.5rem;
    border: 1px solid #9c91f5;
    border-radius: 8px;
    background: #52418e;
    color: #fff;
    font: 800 0.59rem var(--ccg-font-mono, "Courier New", monospace);
    cursor: pointer;
    touch-action: manipulation;
  }
  .ccg-c64-install-promo > button:disabled { opacity: 0.72; cursor: default; }
  .ccg-c64-install-promo > p,
  .ccg-c64-install-promo > details { grid-column: 1 / -1; margin: 0; }
  .ccg-c64-install-promo > details {
    padding-top: 0.35rem;
    border-top: 1px solid #343a76;
  }
  .ccg-c64-install-promo summary {
    color: #d4d9ff;
    cursor: pointer;
    min-height: 38px;
    padding: 0.45rem 0.1rem;
    font: 800 0.62rem var(--ccg-font-mono, "Courier New", monospace);
  }
  .ccg-c64-install-promo details p { margin: 0.3rem 0 0.6rem; }
  .ccg-c64-install-promo details strong { color: #fff; }
}

/* Search landing-page description remains below the interactive emulator,
   outside fixed mobile gameplay. It must never resize the screen or controls. */
.ccg-c64-discovery {
  max-width: 1160px;
  margin: 1rem auto 1.25rem;
  padding: 1.05rem clamp(0.8rem, 2vw, 1.4rem);
  border: 1px solid rgba(141, 130, 255, 0.24);
  border-radius: 12px;
  background: rgba(8, 12, 34, 0.77);
  color: var(--emu-text);
}
.ccg-c64-discovery h2 {
  margin: 0 0 0.5rem;
  color: #f4efff;
  font-size: clamp(1rem, 1.7vw, 1.25rem);
  line-height: 1.35;
}
.ccg-c64-discovery p {
  margin: 0.5rem 0 0;
  color: var(--emu-muted);
  font-size: 0.85rem;
  line-height: 1.6;
}
.ccg-c64-discovery strong { color: var(--emu-text); }
.ccg-c64-discovery a { color: #bbbcff; text-underline-offset: 3px; }
@media (max-width: 760px) {
  .ccg-c64-discovery { margin: 0.65rem 0.4rem 1rem; padding: 0.8rem; }
  .ccg-c64-discovery p { font-size: 0.8rem; }
}


/* Per-game vault controls. Scoped to Game Vault so the mobile joystick and
   existing game-selection layout remain unchanged. */
.ccg-c64-vault-game-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}
.ccg-c64-vault-game-row label {
  color: #a5aed5;
  font-size: 0.57rem;
  font-weight: 800;
  letter-spacing: 0.07em;
}
.ccg-c64-vault-game-row select,
.ccg-c64-vault-backup-row button {
  min-width: 0;
  min-height: 35px;
  border: 1px solid #373b74;
  border-radius: 8px;
  background: #131633;
  color: #bfc0e3;
  padding: 0.42rem 0.48rem;
  font: inherit;
  font-size: 0.6rem;
  font-weight: 800;
}
.ccg-c64-vault-game-row select { width: 100%; appearance: auto; }
.ccg-c64-vault-backup-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
  margin-top: 0.4rem;
}
.ccg-c64-vault-backup-row button {
  cursor: pointer;
}
.ccg-c64-vault-backup-row button:hover:not(:disabled),
.ccg-c64-vault-game-row select:hover { border-color: var(--emu-accent); }
.ccg-c64-vault-help {
  margin: 0.42rem 0 0;
  color: #a5aed5;
  font-size: 0.6rem;
  line-height: 1.5;
}
.ccg-c64-vault-recovery { margin-top: 0.5rem; }
.ccg-c64-vault-recovery [hidden] { display: none !important; }
.ccg-c64-vault-recovery p {
  margin: 0 0 0.42rem;
  color: #f0d89e;
  font-size: 0.67rem;
  line-height: 1.5;
}
.ccg-c64-vault-recovery button {
  min-height: 36px;
  border: 1px solid #817ec2;
  border-radius: 8px;
  padding: 0.46rem 0.8rem;
  color: #e7e9ff;
  background: #242647;
  font: inherit;
  font-size: 0.69rem;
  font-weight: 800;
  cursor: pointer;
}
.ccg-c64-vault-recovery button:hover:not(:disabled),
.ccg-c64-vault-recovery button:focus-visible { border-color: var(--emu-accent); }
.ccg-c64-vault-recovery button:disabled { opacity: 0.6; cursor: wait; }
@media (max-width: 760px), (pointer: coarse) {
  .ccg-c64-vault-game-row select,
  .ccg-c64-vault-backup-row button { min-height: 44px; font-size: 0.7rem; }
}


/* CCG C64 usability refresh — scoped entirely to the emulator.
   Keep the mobile joystick, iOS selector and existing screen-sizing rules. */
.ccg-c64-play-help {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(215px, 0.56fr);
  gap: 0.55rem;
  align-items: center;
  margin: 0.4rem 0 0;
  border: 1px solid rgba(112, 124, 199, 0.36);
  border-radius: 9px;
  padding: 0.55rem 0.65rem;
  background: linear-gradient(110deg, rgba(41, 54, 105, 0.44), rgba(10, 18, 47, 0.84));
}
.ccg-c64-play-help > p {
  margin: 0;
  color: #c5c9e8;
  font-size: 0.69rem;
  line-height: 1.65;
}
.ccg-c64-play-help > p strong { color: #f6edff; }
.ccg-c64-play-help kbd {
  display: inline-block;
  margin: 0 0.1rem;
  padding: 0.08rem 0.36rem;
  border: 1px solid #868ad7;
  border-radius: 4px;
  background: #151b40;
  color: #f7f5ff;
  font: 800 0.7rem var(--ccg-font-mono, "Courier New", monospace);
}
.ccg-c64-warp-action {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.25rem;
}
.ccg-c64-warp-action button {
  width: 100%;
  min-height: 43px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
  padding: 0.42rem 0.7rem;
  border: 1px solid #e0c56c;
  border-radius: 7px;
  background: linear-gradient(120deg, #655023, #957020);
  color: #fffaf0;
  font: 900 0.74rem var(--ccg-font-mono, "Courier New", monospace);
  cursor: pointer;
}
.ccg-c64-warp-action button span { font-size: 0.65rem; }
.ccg-c64-warp-action button strong { font-size: 0.78rem; }
.ccg-c64-warp-action button:hover:not(:disabled),
.ccg-c64-warp-action button:focus-visible { border-color: #fff3af; box-shadow: 0 0 14px rgba(238, 197, 92, 0.25); }
.ccg-c64-warp-action button[aria-pressed="true"] {
  border-color: #a3eac1;
  background: linear-gradient(120deg, #175b53, #168365);
}
.ccg-c64-warp-action button:disabled { opacity: 0.5; cursor: default; }
.ccg-c64-warp-action small { color: #aab4d6; font-size: 0.57rem; line-height: 1.4; text-align: center; }
.ccg-c64-play-help.is-loading { border-color: rgba(239, 194, 67, 0.65); box-shadow: 0 0 15px rgba(200, 164, 55, 0.1); }

.ccg-c64-panel--library .ccg-c64-panel-title {
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.45rem;
}
.ccg-c64-panel--library .ccg-c64-panel-title > em { grid-column: 3; }
.ccg-c64-catalogue-open {
  grid-column: 1 / -1;
  min-height: 40px;
  border: 1px solid #45c8e5;
  border-radius: 7px;
  padding: 0.55rem;
  background: linear-gradient(140deg, #075887, #0a416a);
  color: #f3faff;
  font: 900 0.68rem var(--ccg-font-mono, "Courier New", monospace);
  letter-spacing: 0.035em;
  cursor: pointer;
}
.ccg-c64-catalogue-open:hover:not(:disabled), .ccg-c64-catalogue-open:focus-visible {
  background: linear-gradient(140deg, #0c7ca8, #145477);
  box-shadow: 0 0 14px rgba(21, 199, 227, 0.22);
}
.ccg-c64-catalogue-open:disabled { opacity: 0.55; cursor: progress; }

.ccg-c64-advanced {
  grid-column: 1 / -1;
  min-width: 0;
  border: 1px solid #353b78;
  border-radius: 9px;
  background: rgba(15, 18, 47, 0.82);
}
.ccg-c64-advanced > summary,
.ccg-c64-vault-backups > summary {
  padding: 0.72rem 0.8rem;
  color: #e6e5ff;
  font: 800 0.67rem var(--ccg-font-mono, "Courier New", monospace);
  cursor: pointer;
}
.ccg-c64-advanced > summary span {
  color: #a0abcf;
  font-size: 0.58rem;
  font-weight: 400;
  margin-left: 0.65rem;
}
.ccg-c64-advanced[open] > summary { border-bottom: 1px solid #353b78; }
.ccg-c64-advanced-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  padding: 0.65rem;
}
.ccg-c64-advanced-grid > .ccg-c64-panel { grid-area: auto; grid-row: auto; grid-column: auto; margin: 0; }
.ccg-c64-advanced-grid > .ccg-c64-panel--rom { grid-column: 1 / -1; }
.ccg-c64-vault-backups { margin-top: 0.42rem; border-top: 1px solid rgba(135, 127, 205, 0.35); }
.ccg-c64-vault-backups > summary { padding: 0.42rem 0; font-size: 0.59rem; color: #9ca9d6; }
.ccg-c64-vault-feedback {
  min-height: 1.2rem;
  color: #c2eecf;
  font-size: 0.65rem;
  line-height: 1.45;
  margin: 0.45rem 0 0;
}
.ccg-c64-vault-feedback.is-error { color: #ffd59d; }
.ccg-c64-panel--vault .ccg-c64-vault-row button[data-vault-save],
.ccg-c64-panel--vault .ccg-c64-vault-row button[data-vault-load] {
  border-color: #248ab5;
  background: #095379;
  color: #fff;
  font-size: 0.67rem;
}
.ccg-c64-panel--vault .ccg-c64-vault-row button:disabled { opacity: 0.52; cursor: default; }

/* Catalogue browser is separate from the workspace and does not alter gameplay
   on iOS/Android. Render only 60 games at a time, even in large archives. */
.ccg-c64-catalogue[hidden] { display: none !important; }
.ccg-c64-catalogue {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: grid;
  place-items: center;
  padding: clamp(0.6rem, 2vw, 1.4rem);
}
body.ccg-c64-catalogue-open { overflow: hidden; }
.ccg-c64-catalogue-backdrop { position: absolute; inset: 0; background: rgba(2, 5, 21, 0.84); backdrop-filter: blur(5px); }
.ccg-c64-catalogue-dialog {
  position: relative;
  isolation: isolate;
  width: min(100%, 1120px);
  height: min(93dvh, 920px);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #6670c0;
  border-radius: 14px;
  background: linear-gradient(160deg, #141941, #080e2a);
  color: #f2f1ff;
  box-shadow: 0 25px 90px rgba(0, 0, 0, 0.7);
}
.ccg-c64-catalogue-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.1rem 1.25rem 0.85rem;
  border-bottom: 1px solid #343d79;
}
.ccg-c64-catalogue-kicker { margin: 0; color: #69d8ed; font: 800 0.59rem var(--ccg-font-mono, "Courier New", monospace); letter-spacing: 0.1em; }
.ccg-c64-catalogue-head h2 { margin: 0.2rem 0; font-size: clamp(1.1rem, 2.3vw, 1.7rem); line-height: 1.2; }
.ccg-c64-catalogue-head p:not(.ccg-c64-catalogue-kicker) { margin: 0.3rem 0 0; color: #b7bfdc; font-size: 0.78rem; line-height: 1.45; }
.ccg-c64-catalogue-head button,
.ccg-c64-catalogue-pager button {
  border: 1px solid #5968a5; border-radius: 7px; background: #172150;
  color: #eef2ff; padding: 0.65rem 0.9rem;
  font: 800 0.68rem var(--ccg-font-mono, "Courier New", monospace);
  cursor: pointer;
}
.ccg-c64-catalogue-filters {
  display: grid; grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr));
  gap: 0.7rem; padding: 0.85rem 1.25rem;
}
.ccg-c64-catalogue-filters label { display: grid; gap: 0.28rem; min-width: 0; color: #c7ccee; font: 800 0.57rem var(--ccg-font-mono, "Courier New", monospace); }
.ccg-c64-catalogue-filters input, .ccg-c64-catalogue-filters select {
  min-height: 43px; min-width: 0; width: 100%; border: 1px solid #4f5a9a; border-radius: 7px;
  padding: 0.55rem 0.7rem; color: #fff; background: #0c1438; font-size: 0.82rem;
}
.ccg-c64-catalogue-summary {
  display: flex; justify-content: space-between; gap: 0.5rem;
  padding: 0 1.25rem 0.65rem; color: #b7cae8; font-size: 0.73rem;
}
.ccg-c64-catalogue-summary strong { color: #8ce7ef; }
.ccg-c64-catalogue-results {
  flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start; gap: 0.45rem; padding: 0.65rem 1.25rem 1.1rem;
  overflow-y: auto; scrollbar-color: #5763ad #111632;
  border-top: 1px solid #31386d;
}
.ccg-c64-catalogue-item {
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 0.4rem;
  min-width: 0; min-height: 74px; padding: 0.65rem 0.75rem; text-align: left;
  border: 1px solid #34427c; border-radius: 8px;
  background: #151d48; color: #f5f5ff; cursor: pointer;
}
.ccg-c64-catalogue-item strong { width: 100%; font-size: 0.81rem; overflow-wrap: anywhere; line-height: 1.3; }
.ccg-c64-catalogue-item span { color: #9cbbe7; font-size: 0.55rem; letter-spacing: 0.035em; }
.ccg-c64-catalogue-item:hover, .ccg-c64-catalogue-item:focus-visible {
  border-color: #56d4ef; background: #23346a; box-shadow: inset 3px 0 0 #49d7f5;
}
.ccg-c64-catalogue-empty { grid-column: 1 / -1; color: #cbd0ee; text-align: center; padding: 1.5rem; }
.ccg-c64-catalogue-pager {
  display: flex; justify-content: center; align-items: center; gap: 1rem;
  padding: 0.75rem; border-top: 1px solid #373c77; background: #0d1536;
}
.ccg-c64-catalogue-pager strong { min-width: 95px; text-align: center; font-size: 0.66rem; }
.ccg-c64-catalogue-pager button:disabled { opacity: 0.45; cursor: default; }

@media (min-width: 960px) {
  .ccg-c64-control-stack,
  .ccg-c64-control-stack.has-online-library {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-areas:
      "online online online online online online"
      "controls controls controls controls controls controls"
      "port port port quick quick quick"
      "vault vault vault vault vault vault"
      "advanced advanced advanced advanced advanced advanced";
    align-items: start;
  }
  .ccg-c64-control-stack .ccg-c64-advanced { grid-area: advanced; }
  .ccg-c64-panel--quickload { align-self: stretch; }
  .ccg-c64-panel--controls { grid-row: auto; }
  .ccg-c64-panel--library .ccg-c64-panel-title {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
  }
  .ccg-c64-panel--library .ccg-c64-panel-title > em { grid-column: 3; }
  .ccg-c64-catalogue-open { grid-column: 4; min-height: 31px; padding: 0.35rem 0.6rem; }
  .ccg-c64-button-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.36rem; }
  .ccg-c64-button-grid button { min-height: 42px; padding: 0.45rem; }
  .ccg-c64-button-grid button span { display: none; }
  .ccg-c64-button-grid button strong { font-size: 0.63rem; white-space: normal; }
  .ccg-c64-button-grid [data-load-media],
  .ccg-c64-button-grid [data-open-setup] { display: none; }
  .ccg-c64-quickload p { font-size: 0.62rem; }
  .ccg-c64-quickload .ccg-c64-primary-load { min-height: 36px; }
  /* A grid-column:auto override here discarded the named "vault" column span.
     It reduced Save / Resume to one 1/6-width track and inflated the page
     height. Explicitly span the full right-hand control deck on desktop. */
  .ccg-c64-control-stack > .ccg-c64-panel--vault {
    grid-area: vault;
    grid-column: 1 / -1;
    min-width: 0;
    width: 100%;
  }
  .ccg-c64-discovery { max-width: 1200px; }
}
@media (max-width: 959px) {
  .ccg-c64-play-help { grid-template-columns: 1fr; }
  .ccg-c64-advanced-grid { grid-template-columns: 1fr; }
  .ccg-c64-advanced-grid > .ccg-c64-panel--rom { grid-column: auto; }
}
@media (max-width: 760px) {
  .ccg-c64-play-help { display: none; } /* mobile play has its existing dedicated WARP and virtual keyboard */
  .ccg-c64-advanced > summary span { display: block; margin: 0.25rem 0 0; }
  .ccg-c64-catalogue { padding: 0; }
  .ccg-c64-catalogue-dialog { width: 100%; height: 100dvh; border-radius: 0; }
  .ccg-c64-catalogue-head { padding: 0.8rem; }
  .ccg-c64-catalogue-head p:not(.ccg-c64-catalogue-kicker) { display: none; }
  .ccg-c64-catalogue-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 0.65rem; gap: 0.5rem; }
  .ccg-c64-catalogue-filters label:first-child { grid-column: 1 / -1; }
  .ccg-c64-catalogue-summary { padding: 0 0.7rem 0.5rem; font-size: 0.62rem; }
  .ccg-c64-catalogue-results { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 0.55rem; }
  .ccg-c64-catalogue-item { min-height: 68px; padding: 0.5rem; }
  .ccg-c64-catalogue-item strong { font-size: 0.7rem; }
  .ccg-c64-catalogue-item span { font-size: 0.5rem; }
  .ccg-c64-catalogue-open { font-size: 0.63rem; }
}
@media (max-width: 400px) {
  .ccg-c64-catalogue-filters label { grid-column: 1 / -1; }
  .ccg-c64-catalogue-results { grid-template-columns: 1fr; }
  .ccg-c64-catalogue-item { min-height: 58px; }
}

/* CCG mobile in-game actions (2026-10-14): isolated to coarse-pointer
   immersive gameplay. Desktop layout and ordinary library remain unchanged. */
.ccg-c64-mobile-game-actions[hidden],
.ccg-c64-mobile-vault[hidden] { display: none !important; }
.ccg-c64-mobile-game-actions,
.ccg-c64-mobile-vault { display: none; }
.ccg-c64-mobile-crt-mode { display: none !important; }

@media (pointer: coarse) {
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-game-actions {
    display: grid;
    order: 1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
    gap: clamp(0.18rem, 1vw, 0.4rem);
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-game-actions > button {
    min-width: 0;
    min-height: 44px;
    padding: 0.35rem 0.15rem;
    border: 1px solid #827ad3;
    border-radius: 6px;
    background: #232653;
    color: #f8f5ff;
    font: 800 clamp(0.56rem, 2.25vw, 0.75rem)/1.15 var(--ccg-font-mono, "Courier New", monospace);
    text-align: center;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-game-actions > button[aria-pressed="true"] {
    color: #fff1c8;
    background: #514075;
    border-color: #f3cb70;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-game-actions > button:disabled {
    opacity: 0.5;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-screen-stage,
  .ccg-c64-console.is-mobile-playing:fullscreen .ccg-c64-screen-stage { order: 2; }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-controls,
  .ccg-c64-console.is-mobile-playing:fullscreen .ccg-c64-touch-controls { order: 3; }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-options,
  .ccg-c64-console.is-mobile-playing:fullscreen .ccg-c64-touch-options { order: 4; }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-fire,
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-jump {
    border-radius: 7px;
    min-width: 0;
    flex: 0 1 auto;
    width: clamp(69px, 19vw, 105px);
    height: clamp(69px, 19vw, 105px);
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-jump:not([hidden]) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-options {
    grid-template-columns: minmax(0, 1.04fr) minmax(0, 0.82fr) minmax(0, 1.38fr);
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-crt-mode {
    display: inline-flex !important;
    justify-content: center;
    align-items: center;
    white-space: normal;
    overflow-wrap: anywhere;
    border-color: #afa0ec;
    background: #262451;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-vault:not([hidden]) {
    position: absolute;
    inset: 0;
    z-index: 80;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: max(0.65rem, env(safe-area-inset-top))
      max(0.5rem, env(safe-area-inset-right))
      max(0.65rem, env(safe-area-inset-bottom))
      max(0.5rem, env(safe-area-inset-left));
    background: rgba(2, 4, 16, 0.82);
    touch-action: manipulation;
  }
  .ccg-c64-mobile-vault-card {
    display: grid;
    gap: 0.65rem;
    width: min(100%, 430px);
    max-height: min(85dvh, 540px);
    min-width: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: clamp(0.75rem, 3vw, 1.1rem);
    border: 1px solid #9389da;
    border-radius: 9px;
    background: #10142f;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.8);
    color: #f6f5ff;
  }
  .ccg-c64-mobile-vault-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
  }
  .ccg-c64-mobile-vault-header strong {
    font: 800 0.82rem var(--ccg-font-mono, "Courier New", monospace);
  }
  .ccg-c64-mobile-vault-header button,
  .ccg-c64-mobile-vault-slot {
    border: 1px solid #8983cc;
    border-radius: 5px;
    background: #222854;
    color: #f6f5ff;
    font: 800 0.65rem var(--ccg-font-mono, "Courier New", monospace);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
  }
  .ccg-c64-mobile-vault-header button { min-height: 44px; padding: 0.4rem 0.7rem; }
  .ccg-c64-mobile-vault-card p {
    margin: 0;
    color: #cbd0ed;
    font: 600 0.67rem/1.5 var(--ccg-font-mono, "Courier New", monospace);
  }
  .ccg-c64-mobile-vault-slots { display: grid; gap: 0.4rem; min-width: 0; }
  .ccg-c64-mobile-vault-slot {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.25rem;
    min-width: 0;
    min-height: 56px;
    padding: 0.65rem;
    text-align: left;
  }
  .ccg-c64-mobile-vault-slot strong { font-size: 0.76rem; }
  .ccg-c64-mobile-vault-slot span { color: #bfc6e9; font-size: 0.66rem; }
  .ccg-c64-mobile-vault-slot:disabled { opacity: 0.42; }
  .ccg-c64-mobile-vault-slot:not(:disabled):active { background: #49417e; }
  .ccg-c64-mobile-vault-card .ccg-c64-mobile-vault-message {
    min-height: 1.4rem;
    color: #f2d997;
  }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 490px) {
  .ccg-c64-console.is-mobile-playing .ccg-c64-mobile-game-actions > button {
    min-height: 32px;
    padding: 0.14rem 0.1rem;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-dpad,
  .ccg-c64-console.is-mobile-playing:fullscreen .ccg-c64-touch-dpad {
    grid-template-columns: repeat(3, 32px);
    grid-template-rows: repeat(3, 32px);
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-dpad button {
    min-width: 32px;
    min-height: 32px;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-fire,
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-jump {
    width: 64px;
    height: 64px;
  }
  .ccg-c64-console.is-mobile-playing .ccg-c64-touch-controls {
    padding: 0.1rem;
  }
}

/* Emulator help / troubleshooting: confined to the page section below
   gameplay and discovery, with no changes to C64 input or engine styles. */
.ccg-c64-faq {
  width: calc(100% - 0.8rem);
  max-width: 1160px;
  margin: 1.2rem auto 1.6rem;
  padding: clamp(0.9rem, 2vw, 1.5rem);
  border: 1px solid rgba(117, 183, 255, 0.42);
  border-radius: 14px;
  background: linear-gradient(155deg, #0d1637 0%, #0a102c 56%, #070d25 100%);
  box-shadow: inset 0 1px 0 rgba(163, 205, 255, 0.08), 0 12px 28px rgba(0, 0, 0, 0.2);
  color: var(--emu-text);
}

.ccg-c64-faq-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.8rem;
  padding-bottom: 1rem;
}

.ccg-c64-faq-kicker {
  margin: 0 0 0.35rem;
  color: #7cc6ff;
  font: 800 0.7rem var(--ccg-font-mono, "Courier New", monospace);
  letter-spacing: 0.09em;
}

.ccg-c64-faq-head h2 {
  margin: 0 0 0.35rem;
  color: #f7f8ff;
  font-size: clamp(1.18rem, 2.2vw, 1.55rem);
  line-height: 1.3;
}

.ccg-c64-faq-head p:not(.ccg-c64-faq-kicker) {
  margin: 0;
  color: #c6ceeb;
  font-size: 0.88rem;
  line-height: 1.6;
}

.ccg-c64-faq-count {
  flex: 0 0 auto;
  padding: 0.45rem 0.7rem;
  border: 1px solid rgba(100, 214, 165, 0.5);
  border-radius: 7px;
  background: rgba(39, 139, 101, 0.12);
  color: #9af0c5;
  font: 800 0.67rem var(--ccg-font-mono, "Courier New", monospace);
  white-space: nowrap;
}

.ccg-c64-faq-list {
  display: grid;
  gap: 0.55rem;
}

.ccg-c64-faq-list > details {
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(128, 157, 230, 0.3);
  border-radius: 10px;
  background: rgba(11, 19, 48, 0.9);
}

.ccg-c64-faq-list > details[open] {
  border-color: rgba(113, 223, 177, 0.65);
  background: #0d2030;
}

.ccg-c64-faq-list summary {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-height: 50px;
  padding: 0.85rem 1rem;
  list-style: none;
  cursor: pointer;
  color: #eef3ff;
  font-size: 0.88rem;
  font-weight: 750;
  line-height: 1.45;
}

.ccg-c64-faq-list summary::-webkit-details-marker { display: none; }

.ccg-c64-faq-list summary > span:nth-child(2) {
  flex: 1 1 auto;
  min-width: 0;
}

.ccg-c64-faq-list summary::after {
  content: "+";
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 1.45rem;
  height: 1.45rem;
  border: 1px solid #4d73a0;
  border-radius: 50%;
  color: #a8d4ff;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1;
}

.ccg-c64-faq-list details[open] summary::after {
  content: "−";
  color: #9af0c5;
  border-color: #63b995;
}

.ccg-c64-faq-number {
  flex: 0 0 auto;
  color: #75b8fa;
  font: 800 0.73rem var(--ccg-font-mono, "Courier New", monospace);
}

.ccg-c64-faq-list details[open] .ccg-c64-faq-number { color: #8ce8bd; }

.ccg-c64-faq-list summary:hover { background: rgba(69, 116, 179, 0.15); }

.ccg-c64-faq-list summary:focus-visible {
  outline: 2px solid #a5dfff;
  outline-offset: -3px;
  border-radius: 9px;
}

.ccg-c64-faq-answer {
  padding: 0.1rem 1rem 1rem 3.05rem;
  border-top: 1px solid rgba(132, 179, 216, 0.16);
}

.ccg-c64-faq-answer p {
  margin: 0.65rem 0 0;
  color: #d2dcf1;
  font-size: 0.87rem;
  line-height: 1.75;
}

.ccg-c64-faq-footer {
  margin: 1.05rem 0 0;
  padding: 0.85rem 1rem;
  border-left: 3px solid #64c49a;
  border-radius: 3px 8px 8px 3px;
  background: rgba(35, 109, 94, 0.12);
  color: #cdd8e9;
  font-size: 0.83rem;
  line-height: 1.7;
}

.ccg-c64-faq-footer strong { color: #9af0c5; }

@media (max-width: 760px) {
  .ccg-c64-faq {
    margin: 0.7rem auto 1rem;
    padding: 0.85rem 0.7rem;
  }
  .ccg-c64-faq-head { gap: 0.45rem; }
  .ccg-c64-faq-head p:not(.ccg-c64-faq-kicker) { font-size: 0.8rem; }
  .ccg-c64-faq-count { padding: 0.4rem 0.5rem; font-size: 0.59rem; }
  .ccg-c64-faq-list summary { gap: 0.6rem; padding: 0.8rem 0.7rem; font-size: 0.82rem; }
  .ccg-c64-faq-answer { padding: 0.1rem 0.75rem 0.85rem 0.75rem; }
  .ccg-c64-faq-answer p { font-size: 0.8rem; line-height: 1.65; }
  .ccg-c64-faq-footer { font-size: 0.78rem; }
}

/* Owner-approved FIND A GAME green beacon — 15 October 2026.
   Colour-only, scoped to the existing emulator library section.
   All layout, hidden states, touch targets and the LOAD mechanism remain owned
   by the original emulator CSS/JS. This is not an overlay or image. */
.ccg-c64-panel--library {
  --ccg-find-green: #4dff91;
  --ccg-find-border: #20d86e;
  border-color: var(--ccg-find-border);
  background: linear-gradient(150deg, #071b12 0%, #092c1b 52%, #052015 100%);
  box-shadow: inset 0 0 0 1px rgba(56, 234, 122, 0.12),
    0 0 20px rgba(28, 219, 95, 0.12);
}
.ccg-c64-panel--library .ccg-c64-panel-title {
  border-bottom-color: rgba(55, 226, 120, 0.46);
}
.ccg-c64-panel--library .ccg-c64-panel-title > span,
.ccg-c64-panel--library .ccg-c64-panel-title > strong {
  color: var(--ccg-find-green);
}
.ccg-c64-panel--library .ccg-c64-panel-title > em {
  color: #93ebae;
}
.ccg-c64-panel--library .ccg-c64-catalogue-open {
  border-color: #41ee86;
  background: linear-gradient(145deg, #0b9d51, #086b3b);
  color: #f1fff6;
  box-shadow: inset 0 0 0 1px rgba(169, 255, 199, 0.14);
}
.ccg-c64-panel--library .ccg-c64-catalogue-open:hover:not(:disabled),
.ccg-c64-panel--library .ccg-c64-catalogue-open:focus-visible {
  border-color: #acffd0;
  background: linear-gradient(145deg, #14b866, #078346);
  box-shadow: 0 0 15px rgba(40, 244, 124, 0.26);
}
.ccg-c64-panel--library .ccg-c64-catalogue-open:focus-visible,
.ccg-c64-panel--library .ccg-c64-library-load:focus-visible,
.ccg-c64-panel--library .ccg-c64-library-option:focus-visible {
  outline: 2px solid #b9ffce;
  outline-offset: 2px;
}
.ccg-c64-panel--library .ccg-c64-library-search-wrap > input[type="search"] {
  border-color: #3bd379;
  background: #061a12;
  color: #f3fff7;
  caret-color: #8effb7;
}
.ccg-c64-panel--library .ccg-c64-library-search-wrap > input[type="search"]::placeholder {
  color: #b1dabe;
  opacity: 1;
}
.ccg-c64-panel--library .ccg-c64-library-search-wrap > input[type="search"]:focus-visible {
  border-color: #6effa5;
  outline-color: #65ff9d;
  box-shadow: 0 0 0 3px rgba(67, 229, 119, 0.17);
}
.ccg-c64-panel--library .ccg-c64-library-result-count,
.ccg-c64-panel--library .ccg-c64-library-note {
  color: #b0e8c1;
}
.ccg-c64-panel--library .ccg-c64-library-load {
  border-color: #43ec86;
  background: linear-gradient(155deg, #0c9f50, #086c38);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(180, 255, 200, 0.12);
}
.ccg-c64-panel--library .ccg-c64-library-load:hover:not(:disabled),
.ccg-c64-panel--library .ccg-c64-library-load:focus-visible {
  border-color: #b5ffd0;
  background: linear-gradient(155deg, #17ba63, #087e43);
  box-shadow: 0 0 13px rgba(49, 230, 113, 0.24);
}
.ccg-c64-panel--library .ccg-c64-library-load:disabled {
  opacity: 0.65;
  cursor: wait;
}
.ccg-c64-panel--library .ccg-c64-library-suggestions {
  border-color: #35cb75;
  background: #071e15;
}
.ccg-c64-panel--library .ccg-c64-library-option {
  color: #f0fff5;
}
.ccg-c64-panel--library .ccg-c64-library-option + .ccg-c64-library-option {
  border-top-color: rgba(75, 215, 128, 0.2);
}
.ccg-c64-panel--library .ccg-c64-library-option span,
.ccg-c64-panel--library .ccg-c64-library-match-count {
  color: #a7eac0;
}
.ccg-c64-panel--library .ccg-c64-library-option:hover:not(:disabled),
.ccg-c64-panel--library .ccg-c64-library-option.is-active,
.ccg-c64-panel--library .ccg-c64-library-option:focus-visible {
  border-color: #6be99b;
  background: rgba(14, 122, 64, 0.36);
}
.ccg-c64-panel--library .ccg-c64-library-row select,
.ccg-c64-panel--library .ccg-c64-library-row button {
  border-color: #39ac6e;
  background: #0b3020;
  color: #e8fff0;
}
.ccg-c64-panel--library .ccg-c64-library-row button:hover:not(:disabled),
.ccg-c64-panel--library .ccg-c64-library-row select:hover {
  border-color: #7affae;
}