/**
 * C64 Frontend Emulator: the machine on the page.
 *
 * Colours come from the theme's custom properties where it has them and
 * fall back to neutral values, so the block sits naturally in any theme,
 * light or dark. Mobile first: the keyboard wraps, the screen scales to the
 * column width, the joystick pad only appears on touch screens.
 */
.c64 { --c64-bg: var(--bg2, #f3f3f3); --c64-fg: var(--fg, #1b1b1f); --c64-fg2: var(--fg2, #5c5955); --c64-line: var(--line, #dcdcdc); --c64-accent: var(--accent, #c40e1d); --c64-accent-ink: var(--accent-ink, #fff); --c64-radius: var(--radius, 10px);
  margin: 0 0 1.6em; padding: 16px; background: var(--c64-bg); border: 1px solid var(--c64-line); border-radius: var(--c64-radius); color: var(--c64-fg); font-family: inherit; }
.c64 * { box-sizing: border-box; }

/* Top bar: program picker and buttons. */
.c64-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.c64-group { display: inline-flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }
.c64-bar label { font-weight: 500; white-space: nowrap; }
.c64-bar select { flex: 1 1 140px; min-width: 0; max-width: 100%; padding: 8px 10px; font: inherit; color: inherit; background: var(--bg, #fff); border: 1px solid var(--c64-line); border-radius: 8px; }
.c64-btn { padding: 8px 14px; font: inherit; font-weight: 500; cursor: pointer; border-radius: 8px; border: 1px solid var(--c64-line); background: var(--bg, #fff); color: var(--c64-fg); }
.c64-btn.primary { background: var(--c64-accent); border-color: var(--c64-accent); color: var(--c64-accent-ink); }
.c64-btn:disabled { opacity: .5; cursor: default; }
.c64-btn[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--c64-accent); }
.c64-note { margin: 0 0 12px; color: var(--c64-fg2); font-size: .95em; min-height: 1.4em; }

/* The screen: a 4:3-ish box (the engine draws 368 by 270 and we scale it). */
.c64-screen { position: relative; width: 100%; aspect-ratio: 368 / 270; background: #352879; border-radius: 6px; overflow: hidden; outline: none; }
.c64-screen:focus-visible { box-shadow: 0 0 0 3px var(--c64-accent); }
.c64-screen canvas { display: block; width: 100% !important; height: 100% !important; image-rendering: pixelated; image-rendering: crisp-edges; }
.c64-screen:fullscreen { background: #000; display: flex; align-items: center; justify-content: center; }
.c64-screen:fullscreen canvas { width: auto !important; height: 100% !important; max-width: 100%; aspect-ratio: 368 / 270; }
/* Where keystrokes go: a real input so mobile browsers open their keyboard when asked, kept out of sight. */
.c64-input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; }
/* Overlay for "click to start", loading and drop messages. */
.c64-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px; background: rgba(20, 16, 50, .72); color: #fff; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: clamp(.9rem, 2.5vw, 1.1rem); line-height: 1.5; cursor: pointer; }
.c64-overlay[hidden] { display: none; }
.c64-screen.is-dragover .c64-overlay { display: flex; background: rgba(196, 14, 29, .6); }

/* Status line under the screen. */
.c64-status { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 10px 0 0; font-size: .9em; color: var(--c64-fg2); }
.c64-status a { color: inherit; }

/* On-screen keyboard: shown by a toggle, wraps on narrow screens. */
.c64-keys { margin-top: 12px; }
.c64-keys[hidden] { display: none; }
.c64-row { display: flex; flex-wrap: nowrap; gap: 3px; margin-bottom: 3px; }
.c64-key { flex: 1 1 0; min-width: 0; padding: 9px 1px; font: inherit; font-size: .62em; font-weight: 500; line-height: 1; text-align: center; white-space: nowrap; overflow: hidden; cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation; border-radius: 5px; border: 1px solid var(--c64-line); border-bottom-width: 3px; background: var(--bg, #fff); color: var(--c64-fg); }
.c64-key:active, .c64-key.is-down { border-bottom-width: 1px; transform: translateY(2px); background: var(--c64-bg); }
.c64-key[aria-pressed="true"] { background: var(--c64-accent); border-color: var(--c64-accent); color: var(--c64-accent-ink); }
.c64-key.wide { flex-grow: 1.9; }
.c64-key.space { flex-grow: 7; }
.c64-key.fn { flex-grow: 1.3; }

/* Touch joystick: a d-pad and fire, only on coarse pointers. */
.c64-pad { display: none; margin-top: 12px; align-items: center; justify-content: space-between; gap: 16px; }
.c64-pad[hidden] { display: none; }
@media (pointer: coarse) { .c64-pad:not([hidden]) { display: flex; } }
.c64-dpad { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 52px); gap: 4px; }
.c64-dpad .c64-key { min-width: 0; padding: 0; font-size: 1.2em; }
.c64-dpad .up { grid-column: 2; grid-row: 1; } .c64-dpad .left { grid-column: 1; grid-row: 2; } .c64-dpad .right { grid-column: 3; grid-row: 2; } .c64-dpad .down { grid-column: 2; grid-row: 3; }
.c64-fire { width: 84px; height: 84px; border-radius: 50%; font-size: 1em; }

/* Help and credit. */
.c64 details { margin-top: 12px; font-size: .95em; }
.c64 details summary { cursor: pointer; font-weight: 500; }
.c64 details ul { margin: 8px 0 0; padding-left: 20px; }
.c64 kbd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; padding: 1px 5px; border: 1px solid var(--c64-line); border-radius: 4px; background: var(--bg, #fff); }
.c64-credit { margin: 12px 0 0; font-size: .85em; color: var(--c64-fg2); }

@media (min-width: 700px) {
  .c64 { padding: 20px; }
  .c64-row { gap: 4px; margin-bottom: 4px; }
  .c64-key { padding: 11px 3px; font-size: .78em; border-radius: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .c64-key:active, .c64-key.is-down { transform: none; }
}
