html,
body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

#wrap {
    position: relative;   /* anchors the fullscreen button + HUD overlays */
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 1rem;
    box-sizing: border-box;
}

/* Fullscreen toggle */
#fs-btn {
    position: absolute;
    top: 10px;
    right: 12px;
    z-index: 30;
    width: 30px;
    height: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 12, 16, 0.7);
    color: #e6e8ec;
    border: 1px solid #2a2f38;
    border-radius: 4px;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}

#fs-btn:hover {
    background: rgba(30, 34, 42, 0.9);
}

/* Fullscreen: fill the screen, letterbox view + status bar as one unit so the
   combined 480x344 ratio (300 view rows + 44 bar rows) is preserved. */
#wrap:fullscreen {
    background: #000;
    padding: 0;
    gap: 0;
}

#wrap:fullscreen #view {
    width: min(100vw, calc(100vh * 480 / 344));
    max-width: none;
}

#wrap:fullscreen .help {
    display: none;   /* reclaim the space so the canvas can use the full height */
}

/* The view and the status bar share a width so they scale together. */
#view {
    width: 100%;
    max-width: 960px;   /* 2x framebuffer: fills the frame, stays chunky */
    display: flex;
    flex-direction: column;
}

#screen,
#hudbar {
    display: block;
    image-rendering: pixelated;
    width: 100%;
    height: auto;
}

#screen {
    background: #000;
    aspect-ratio: 480 / 300;
}

#hudbar {
    background: #0d1015;
    aspect-ratio: 480 / 44;
}

#hudbar[hidden] {
    display: none;   /* `hidden` alone loses to display:block */
}

.help {
    flex: 0 0 auto;
    text-align: center;
    font-size: 12px;
    line-height: 1.5;
    opacity: .75;
    white-space: pre-wrap;
    pointer-events: none;
}

.hint {
    flex: 0 0 auto;
    text-align: center;
    font-size: 12px;
    opacity: .6;
    pointer-events: none;
}

/* Lobby overlay */
#lobby { position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; background: rgba(8, 10, 14, 0.92); z-index: 20; }
#lobby[hidden] { display: none; }
#lobby .panel { background: #14181f; color: #e6e8ec; padding: 20px 24px;
  border: 1px solid #2a2f38; border-radius: 8px; font: 14px/1.4 system-ui, sans-serif; }
#lobby h1 { font-size: 16px; margin: 0 0 14px; }
#lobby .lobby-grid { display: flex; gap: 20px; align-items: flex-start; }
#lobby .controls { display: flex; flex-direction: column; gap: 8px; min-width: 220px; }
#lobby label { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#lobby label.chk { justify-content: flex-start; }
#lobby input[type=text] { flex: 1; background: #0d1015; color: #e6e8ec;
  border: 1px solid #2a2f38; border-radius: 4px; padding: 4px 6px; }
#lobby button { margin-top: 8px; padding: 8px; background: #a84530; color: #fff;
  border: 0; border-radius: 4px; cursor: pointer; font-weight: 600; }
#lobby button:hover { background: #c05236; }
#preview { background: #0d1015; border: 1px solid #2a2f38; border-radius: 4px;
  image-rendering: pixelated; }

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none;
  font: 13px/1.3 system-ui, sans-serif; color: #e6e8ec; z-index: 10; }
#status { position: absolute; top: 8px; right: 10px; padding: 3px 8px;
  background: rgba(10,12,16,0.7); border-radius: 4px; }
#scoreboard { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: rgba(10,12,16,0.92); border: 1px solid #2a2f38; border-radius: 6px;
  padding: 10px 14px; min-width: 260px; }
#scoreboard table { width: 100%; border-collapse: collapse; }
#scoreboard th { text-align: right; padding: 2px 8px 6px; font-weight: 600;
  color: #9aa0ac; border-bottom: 1px solid #2a2f38; }
#scoreboard th:first-child { text-align: left; }
#scoreboard td { padding: 3px 8px; text-align: right; white-space: nowrap; }
#scoreboard td:first-child { text-align: left; }
#scoreboard tr.me td { color: #ffd27f; font-weight: 600; }
#scoreboard .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px;
  margin-right: 7px; vertical-align: baseline; border: 1px solid rgba(0,0,0,0.4); }

#lobby .panel .tagline {
  margin: 0 0 14px;
  opacity: 0.7;
  font-size: 14px;
}