  @import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=JetBrains+Mono:wght@400;500;600&display=swap');

  /* CSS Houdini — animate custom properties for sky gradient */
  @property --sky-mid {
    syntax: '<color>';
    inherits: true;
    initial-value: #1a1242;
  }
  @property --sky-low {
    syntax: '<color>';
    inherits: true;
    initial-value: #2e1845;
  }
  @property --horizon {
    syntax: '<color>';
    inherits: true;
    initial-value: #c27850;
  }

  :root {
    --bg:         #0d1117;
    --surface:    rgba(20, 25, 45, 0.55);
    --surface-solid: #151a2e;
    --border:     rgba(127, 219, 202, 0.08);
    --border-hi:  rgba(127, 219, 202, 0.18);
    --text:       #d4d8e8;
    --text-dim:   #6872a0;
    --accent:     #7fdbca;
    --accent-dim: #1e4a42;
    --danger:     #ff6b6b;
    --warm:       #daa520;
    --sky-top:    #0b0e1a;
    --sky-mid:    #1a1242;
    --sky-low:    #2e1845;
    --horizon:    #c27850;
    --star:       #fff8e7;
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }

  html, body {
    height: 100%;
    background:
      repeating-linear-gradient(
        0deg,
        transparent, transparent 1px,
        rgba(255,255,255,0.012) 1px, rgba(255,255,255,0.012) 2px
      ),
      repeating-linear-gradient(
        90deg,
        transparent, transparent 1px,
        rgba(255,255,255,0.012) 1px, rgba(255,255,255,0.012) 2px
      ),
      linear-gradient(
        180deg,
        var(--sky-top) 0%,
        var(--sky-mid) 30%,
        var(--sky-low) 60%,
        var(--horizon) 100%
      );
    background-attachment: fixed;
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    overflow: hidden;
    animation: skyShift 25s ease-in-out infinite alternate;
  }

  @keyframes skyShift {
    0%   { --sky-mid: #1a1242; --sky-low: #2e1845; --horizon: #c27850; }
    50%  { --sky-mid: #1a1848; --sky-low: #351a4a; --horizon: #d4886a; }
    100% { --sky-mid: #161040; --sky-low: #281642; --horizon: #b06a48; }
  }

  /* ── STARFIELD ── */
  body::before, body::after {
    content: '';
    position: fixed; inset: 0;
    pointer-events: none;
    z-index: 0;
  }
  body::before {
    background: radial-gradient(1px 1px at 12% 8%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 28% 15%, var(--star) 50%, transparent 100%),
      radial-gradient(1.5px 1.5px at 45% 4%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 62% 12%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 78% 6%, var(--star) 50%, transparent 100%),
      radial-gradient(1.5px 1.5px at 91% 18%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 5% 25%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 35% 22%, var(--star) 50%, transparent 100%),
      radial-gradient(1.5px 1.5px at 55% 28%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 72% 20%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 88% 30%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 18% 35%, var(--star) 50%, transparent 100%),
      radial-gradient(1.5px 1.5px at 40% 38%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 65% 33%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 82% 40%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 8% 44%, var(--star) 50%, transparent 100%),
      radial-gradient(1.5px 1.5px at 25% 48%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 50% 42%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 70% 46%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 95% 10%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 15% 52%, var(--star) 50%, transparent 100%),
      radial-gradient(1.5px 1.5px at 58% 50%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 38% 55%, var(--star) 50%, transparent 100%),
      radial-gradient(1px 1px at 85% 48%, var(--star) 50%, transparent 100%);
    animation: twinkle1 4s ease-in-out infinite alternate;
  }
  body::after {
    background: radial-gradient(1px 1px at 7% 11%, rgba(255,248,231,0.6) 50%, transparent 100%),
      radial-gradient(1.5px 1.5px at 22% 5%, rgba(255,248,231,0.5) 50%, transparent 100%),
      radial-gradient(1px 1px at 42% 18%, rgba(255,248,231,0.6) 50%, transparent 100%),
      radial-gradient(1px 1px at 58% 9%, rgba(255,248,231,0.5) 50%, transparent 100%),
      radial-gradient(1.5px 1.5px at 75% 22%, rgba(255,248,231,0.6) 50%, transparent 100%),
      radial-gradient(1px 1px at 90% 14%, rgba(255,248,231,0.5) 50%, transparent 100%),
      radial-gradient(1px 1px at 33% 30%, rgba(255,248,231,0.6) 50%, transparent 100%),
      radial-gradient(1px 1px at 48% 35%, rgba(255,248,231,0.5) 50%, transparent 100%),
      radial-gradient(1.5px 1.5px at 68% 28%, rgba(255,248,231,0.6) 50%, transparent 100%),
      radial-gradient(1px 1px at 83% 36%, rgba(255,248,231,0.5) 50%, transparent 100%),
      radial-gradient(1px 1px at 3% 40%, rgba(255,248,231,0.6) 50%, transparent 100%),
      radial-gradient(1px 1px at 52% 44%, rgba(255,248,231,0.5) 50%, transparent 100%),
      radial-gradient(1.5px 1.5px at 30% 46%, rgba(255,248,231,0.6) 50%, transparent 100%),
      radial-gradient(1px 1px at 76% 42%, rgba(255,248,231,0.5) 50%, transparent 100%),
      radial-gradient(1px 1px at 93% 50%, rgba(255,248,231,0.6) 50%, transparent 100%),
      radial-gradient(1px 1px at 15% 55%, rgba(255,248,231,0.5) 50%, transparent 100%);
    animation: twinkle2 5s ease-in-out infinite alternate;
  }
  @keyframes twinkle1 {
    0%   { opacity: 0.6; }
    50%  { opacity: 1; }
    100% { opacity: 0.7; }
  }
  @keyframes twinkle2 {
    0%   { opacity: 0.8; }
    50%  { opacity: 0.4; }
    100% { opacity: 0.9; }
  }

  /* ── FLOATING PIXEL PARTICLES ── */
  .pixel-particle {
    position: fixed;
    width: 3px; height: 3px;
    background: var(--horizon);
    opacity: 0;
    pointer-events: none;
    z-index: 0;
    image-rendering: pixelated;
    animation: floatUp var(--dur) var(--delay) ease-in-out infinite;
  }
  .pixel-particle:nth-child(odd) { background: var(--accent); width: 2px; height: 2px; }
  .pixel-particle:nth-child(3n) { background: var(--star); width: 2px; height: 2px; }
  @keyframes floatUp {
    0%   { transform: translateY(0) translateX(0); opacity: 0; }
    15%  { opacity: 0.5; }
    50%  { opacity: 0.3; transform: translateY(-40vh) translateX(12px); }
    85%  { opacity: 0.5; }
    100% { transform: translateY(-85vh) translateX(-8px); opacity: 0; }
  }

  .screen { display: none; width: 100%; height: 100%; position: relative; z-index: 1; }
  .screen.active { display: flex; }

  /* ── BOOT ── */
  #boot-screen {
    align-items: center; justify-content: center;
    flex-direction: column; gap: 16px;
  }
  .boot-spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin 0.7s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }
  .boot-text { font-size: 11px; color: var(--text-dim); }
  .boot-error {
    font-size: 12px; color: var(--danger); text-align: center;
    line-height: 1.8; max-width: 400px;
  }

  /* ── AUTH ── */
  #auth-screen {
    flex-direction: column; align-items: center; justify-content: center;
    padding: 20px;
  }
  .auth-box {
    background: rgba(15, 18, 35, 0.65);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(127, 219, 202, 0.1);
    border-radius: 16px; padding: 32px; width: 100%; max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.04);
  }
  .auth-logo {
    font-family: 'Press Start 2P', monospace; font-size: 14px;
    color: var(--accent); letter-spacing: 2px; margin-bottom: 8px; text-align: center;
  }
  .auth-tagline { font-size: 11px; color: var(--text-dim); text-align: center; margin-bottom: 28px; }
  .form-group { margin-bottom: 14px; }
  .form-group label { display: block; font-size: 10px; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
  .form-group input {
    width: 100%; padding: 12px 14px; background: rgba(10, 12, 25, 0.6); border: 2px solid rgba(127, 219, 202, 0.08);
    border-radius: 8px; color: #fff; font-family: inherit; font-size: 13px; transition: all 0.2s;
  }
  .form-group input:hover { border-color: rgba(127, 219, 202, 0.15); }
  .form-group input:focus { outline: none; border-color: var(--accent); }
  .form-group input::placeholder { color: var(--text-dim); }
  .btn-primary {
    width: 100%; padding: 14px; background: var(--accent); color: var(--bg);
    border: none; border-radius: 8px; font-family: 'Press Start 2P', monospace;
    font-size: 9px; cursor: pointer; transition: all 0.15s; margin-top: 8px; letter-spacing: 1px;
  }
  .btn-primary:hover { background: #a8f0e0; transform: translateY(-1px); }
  .btn-primary:disabled { background: var(--border); color: var(--text-dim); cursor: default; transform: none; }
  .btn-secondary {
    width: 100%; padding: 12px; background: none; border: 1px solid var(--border);
    border-radius: 8px; color: var(--text-dim); font-family: inherit; font-size: 12px;
    cursor: pointer; margin-top: 10px; transition: all 0.15s;
  }
  .btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
  .auth-error { font-size: 11px; color: var(--danger); margin-top: 10px; text-align: center; }
  .auth-toggle { font-size: 11px; color: var(--text-dim); text-align: center; margin-top: 16px; }
  .auth-toggle a { color: var(--accent); cursor: pointer; text-decoration: none; }
  .auth-toggle a:hover { text-decoration: underline; }

  /* ── SELECT ── */
  #select-screen {
    flex-direction: column; align-items: center;
    overflow-y: auto; padding: 40px 20px 60px;
  }
  .logo { font-family: 'Press Start 2P', monospace; font-size: 18px; color: var(--accent); letter-spacing: 2px; margin-bottom: 6px; }
  .tagline { font-size: 11px; color: var(--text-dim); margin-bottom: 36px; }

  .gen-bar { display: flex; gap: 8px; width: 100%; max-width: 520px; margin-bottom: 12px; }
  .gen-bar input {
    flex: 1; padding: 12px 16px; background: rgba(15, 18, 35, 0.55);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 2px solid rgba(127, 219, 202, 0.08); border-radius: 8px;
    color: #fff; font-family: inherit; font-size: 13px; transition: all 0.2s;
  }
  .gen-bar input:focus { outline: none; border-color: var(--accent); }
  .gen-bar input::placeholder { color: var(--text-dim); }
  .gen-bar button {
    padding: 12px 20px; background: var(--accent); color: var(--bg);
    border: none; border-radius: 8px; font-family: 'Press Start 2P', monospace;
    font-size: 9px; cursor: pointer; white-space: nowrap; transition: all 0.15s;
  }
  .gen-bar button:hover { background: #a8f0e0; transform: translateY(-1px); }
  .gen-bar button:disabled { background: var(--border); color: var(--text-dim); cursor: default; transform: none; }

  .hint { font-size: 10px; color: var(--text-dim); margin-bottom: 32px; max-width: 520px; text-align: center; line-height: 1.6; }
  .section-label { font-family: 'Press Start 2P', monospace; font-size: 9px; color: var(--text-dim); letter-spacing: 1px; margin-bottom: 16px; text-transform: uppercase; }

  .char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 10px; width: 100%; max-width: 520px; margin-bottom: 20px; }
  .char-cell {
    aspect-ratio: 1; background: rgba(15, 18, 35, 0.5);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border: 2px solid rgba(127, 219, 202, 0.06);
    border-radius: 8px; cursor: pointer; display: flex; align-items: center;
    justify-content: center; transition: all 0.2s; position: relative; overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  }
  .char-cell:hover { border-color: var(--accent); transform: translateY(-2px); }
  .char-cell.selected { border-color: var(--accent); box-shadow: 0 0 12px rgba(127,219,202,0.25); }
  .char-cell canvas { image-rendering: pixelated; image-rendering: crisp-edges; width: 80%; height: 80%; }
  .char-cell .char-id {
    position: absolute; bottom: 2px; left: 0; right: 0; text-align: center;
    font-size: 7px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; padding: 0 4px;
  }
  .grid-empty { grid-column: 1 / -1; text-align: center; padding: 40px 20px; color: var(--text-dim); font-size: 12px; line-height: 1.8; }
  .grid-loading { grid-column: 1 / -1; text-align: center; padding: 40px; color: var(--text-dim); font-size: 11px; }

  /* "just created" glow */
  .char-cell.new-char {
    border-color: var(--warm);
    box-shadow: 0 0 14px rgba(218,165,32,0.45), inset 0 0 8px rgba(218,165,32,0.1);
    animation: newPulse 2s ease-in-out 3;
  }
  .char-cell.new-char .new-badge {
    position: absolute; top: -1px; right: -1px;
    background: var(--warm); color: var(--bg);
    font-size: 7px; font-family: 'Press Start 2P', monospace;
    padding: 2px 5px; border-radius: 0 6px 0 6px;
    letter-spacing: 0.5px;
  }
  @keyframes newPulse {
    0%, 100% { box-shadow: 0 0 14px rgba(218,165,32,0.45); }
    50% { box-shadow: 0 0 22px rgba(218,165,32,0.7), 0 0 40px rgba(218,165,32,0.2); }
  }

  /* gen overlay */
  .gen-overlay { display: none; position: fixed; inset: 0; background: rgba(8,10,18,0.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); z-index: 100; flex-direction: column; align-items: center; justify-content: center; gap: 20px; }
  .gen-overlay.active { display: flex; }
  .spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
  .gen-status { font-family: 'Press Start 2P', monospace; font-size: 10px; color: var(--accent); }
  .gen-time { font-size: 11px; color: var(--text-dim); }
  .gen-cancel { margin-top: 8px; background: none; border: 1px solid var(--border); color: var(--text-dim); padding: 6px 16px; border-radius: 4px; font-family: inherit; font-size: 11px; cursor: pointer; }
  .gen-cancel:hover { border-color: var(--danger); color: var(--danger); }

  /* ── ROOM ── */
  #room-screen { flex-direction: column; align-items: center; justify-content: center; position: relative; background: rgba(8, 10, 18, 0.7); }
  .room-back {
    position: absolute; top: 16px; left: 16px; z-index: 10;
    background: rgba(15, 18, 35, 0.6); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(127, 219, 202, 0.1); border-radius: 6px;
    color: var(--text-dim); font-family: inherit; font-size: 12px;
    padding: 8px 14px; cursor: pointer; transition: all 0.15s;
    display: flex; align-items: center; gap: 6px;
  }
  .room-back:hover { border-color: var(--accent); color: var(--accent); }
  .room-label {
    position: absolute; top: 18px; right: 16px; z-index: 10;
    font-size: 9px; color: var(--text-dim);
    background: rgba(15, 18, 35, 0.6); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(127, 219, 202, 0.08); border-radius: 4px; padding: 6px 10px;
  }
  .room-label.live { border-color: var(--accent-dim); color: var(--accent); }
  .room-label.live::before { content: ''; display: inline-block; width: 6px; height: 6px; background: var(--accent); border-radius: 50%; margin-right: 6px; }

  #room-canvas { image-rendering: pixelated; image-rendering: crisp-edges; border: 1px solid rgba(127, 219, 202, 0.1); border-radius: 4px; box-shadow: 0 4px 24px rgba(0,0,0,0.4); }
  .room-controls-hint { position: absolute; bottom: 80px; font-size: 9px; color: var(--text-dim); pointer-events: none; }

  /* ── TEMPLATE PICKER ── */
  .template-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    z-index: 10; background: rgba(15, 18, 35, 0.6); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(127, 219, 202, 0.12);
    border-radius: 6px; color: var(--accent); font-family: 'Press Start 2P', monospace;
    font-size: 18px; padding: 16px 14px; cursor: pointer; transition: all 0.15s;
    line-height: 1; display: none;
  }
  .template-nav:hover { background: rgba(127,219,202,0.15); border-color: var(--accent); }
  .template-nav.visible { display: block; }
  /* left/right position set dynamically by positionArrows() */
  #template-label {
    position: absolute; bottom: 88px; left: 50%; transform: translateX(-50%);
    font-family: 'Press Start 2P', monospace; font-size: 8px; color: var(--accent);
    background: rgba(15, 18, 35, 0.6); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(127, 219, 202, 0.12);
    padding: 6px 14px; border-radius: 4px; white-space: nowrap;
    display: none; pointer-events: none; letter-spacing: 1px;
  }
  #template-label.visible { display: block; }

  .room-bottom {
    position: absolute; bottom: 0; left: 0; right: 0;
    display: flex; align-items: center; justify-content: center;
    padding: 16px; gap: 10px; background: linear-gradient(transparent, rgba(8,10,18,0.7));
  }
  .btn-enter {
    padding: 14px 32px; background: var(--accent); color: var(--bg); border: none;
    border-radius: 8px; font-family: 'Press Start 2P', monospace; font-size: 10px;
    cursor: pointer; transition: all 0.15s; letter-spacing: 1px;
  }
  .btn-enter:hover { background: #a8f0e0; transform: translateY(-1px); }
  /* Toolbar — horizontal, centered bottom of game-screen */
  .live-toolbar {
    display: none; position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
    flex-direction: row; gap: 8px; z-index: 10;
  }
  .live-toolbar.visible { display: flex; }
  .tb-btn {
    padding: 10px 18px; background: rgba(15, 18, 35, 0.6); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(127, 219, 202, 0.12);
    border-radius: 6px; color: var(--text); font-family: inherit; font-size: 11px;
    cursor: pointer; transition: all 0.15s; white-space: nowrap;
  }
  .tb-btn:hover { border-color: var(--accent); color: var(--accent); }

  /* ── GAME (multiplayer) ── */
  #game-screen { flex-direction: row; align-items: stretch; position: relative; background: rgba(8, 10, 18, 0.75); }

  /* Left sidebar — online players + chat */
  #online-panel {
    width: 220px; min-width: 220px;
    background: rgba(12, 15, 30, 0.7); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid rgba(127, 219, 202, 0.06);
    display: flex; flex-direction: column; overflow: hidden; z-index: 5;
  }
  .panel-header {
    padding: 12px 12px 10px;
    font-family: 'Press Start 2P', monospace; font-size: 8px; letter-spacing: 1px;
    color: var(--text-dim); border-bottom: 1px solid rgba(127, 219, 202, 0.06);
    display: flex; justify-content: space-between; align-items: center;
    flex-shrink: 0;
  }
  .online-count {
    background: var(--accent-dim); color: var(--accent);
    font-size: 8px; padding: 2px 7px; border-radius: 8px;
  }
  #online-list { flex: 1; overflow-y: auto; padding: 4px 0; min-height: 0; }
  .online-player {
    padding: 8px 12px; border-bottom: 1px solid rgba(127, 219, 202, 0.04);
    display: flex; flex-direction: column; gap: 3px;
  }
  .online-player-name {
    font-size: 11px; color: var(--text);
    display: flex; align-items: center; gap: 6px; overflow: hidden;
  }
  .online-player-name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .online-dot { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; flex-shrink: 0; }
  .online-room { font-size: 9px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 12px; }
  .btn-visit {
    margin-top: 2px; padding: 4px 8px; background: none;
    border: 1px solid var(--border); border-radius: 4px;
    color: var(--text-dim); font-family: inherit; font-size: 10px;
    cursor: pointer; transition: all 0.15s; width: 100%; text-align: left;
  }
  .btn-visit:hover { border-color: var(--accent); color: var(--accent); }
  .online-self .online-dot { background: var(--warm); }
  .online-self .online-player-name { color: var(--warm); }

  /* Chat section inside sidebar */
  .chat-divider {
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px; border-top: 1px solid rgba(127, 219, 202, 0.06);
    font-family: 'Press Start 2P', monospace; font-size: 8px;
    letter-spacing: 1px; color: var(--text-dim);
  }
  .chat-toggle-btn {
    background: none; border: 1px solid rgba(127, 219, 202, 0.1); border-radius: 4px;
    color: var(--text-dim); font-size: 10px; padding: 2px 7px;
    cursor: pointer; line-height: 1; transition: all 0.15s;
  }
  .chat-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }
  #chat-section {
    flex-shrink: 0; display: flex; flex-direction: column;
    border-top: 1px solid rgba(127, 219, 202, 0.06);
    transition: max-height 0.2s ease; overflow: hidden;
    max-height: 320px;
  }
  #chat-section.collapsed { max-height: 0; border-top-color: transparent; }
  #chat-messages {
    flex: 1; overflow-y: auto; padding: 8px 12px;
    font-size: 11px; max-height: 250px; min-height: 120px;
  }
  .chat-msg { margin-bottom: 4px; line-height: 1.5; }
  .chat-msg .name { color: var(--accent); font-weight: 600; }
  .chat-msg .text { color: var(--text); }
  #chat-form {
    display: flex; flex-shrink: 0;
    border-top: 1px solid rgba(127, 219, 202, 0.06);
  }
  #chat-form input {
    flex: 1; padding: 9px 10px; background: rgba(10, 12, 25, 0.6);
    border: none; color: var(--text); font-family: inherit; font-size: 11px;
  }
  #chat-form input:focus { outline: none; background: rgba(20, 24, 45, 0.7); }
  #chat-form button {
    padding: 9px 12px; background: rgba(30, 74, 66, 0.5); color: var(--accent);
    border: none; border-left: 1px solid rgba(127, 219, 202, 0.06);
    font-family: inherit; font-size: 11px; cursor: pointer; flex-shrink: 0;
    transition: background 0.15s;
  }
  #chat-form button:hover { background: var(--accent); color: var(--bg); }

  /* Main game area */
  #game-main {
    flex: 1; position: relative; overflow: hidden; min-width: 0;
    background: rgba(6, 8, 14, 0.4);
  }
  #game-canvas {
    image-rendering: pixelated; image-rendering: crisp-edges;
    border: 1px solid rgba(127, 219, 202, 0.1); border-radius: 4px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  }
  .game-back {
    position: absolute; top: 12px; left: 232px; z-index: 10;
    background: rgba(15, 18, 35, 0.6); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(127, 219, 202, 0.1); border-radius: 6px;
    color: var(--text-dim); font-family: inherit; font-size: 12px;
    padding: 7px 12px; cursor: pointer; transition: all 0.15s;
  }
  .game-back:hover { border-color: var(--accent); color: var(--accent); }
  .controls-hint { font-size: 10px; color: var(--text-dim); margin-top: 8px; }

  /* log — narrow strip between sidebar and game canvas */
  .log-bar {
    width: 180px; min-width: 180px; background: rgba(8, 10, 20, 0.75);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border-right: 1px solid rgba(127, 219, 202, 0.05); font-size: 10px; color: var(--text-dim);
    display: none; flex-direction: column-reverse; justify-content: flex-start;
    overflow-y: auto; padding: 6px 8px;
  }
  .log-bar.open { display: flex; }
  .log-bar .entry { margin-bottom: 3px; white-space: pre-wrap; word-break: break-all; line-height: 1.5; }
  .log-bar .error { color: var(--danger); }
  .log-bar .ok { color: var(--accent); }

  /* Furniture edit mode */
  .furn-trash {
    position: absolute; bottom: 60px; right: 16px; z-index: 20;
    width: 52px; height: 52px; border-radius: 12px;
    background: rgba(180,50,50,0.25); border: 2px dashed var(--danger);
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; transition: all 0.15s; pointer-events: auto;
  }
  .furn-trash.over { background: rgba(220,60,60,0.55); transform: scale(1.15); }
  .furn-ghost {
    position: fixed; pointer-events: none; z-index: 200;
    image-rendering: pixelated; opacity: 0.7;
  }

  /* ── THEME TOGGLE ── */
  .theme-toggle {
    position: fixed; top: 14px; right: 14px; z-index: 999;
    width: 42px; height: 42px; border-radius: 50%;
    border: 1px solid rgba(127, 219, 202, 0.15);
    background: rgba(15, 18, 35, 0.5);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    cursor: pointer; transition: all 0.35s ease;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; line-height: 1;
    color: var(--accent);
    box-shadow: 0 2px 12px rgba(0,0,0,0.25);
  }
  .theme-toggle:hover {
    transform: scale(1.1) rotate(15deg);
    border-color: var(--accent);
    box-shadow: 0 4px 20px rgba(127, 219, 202, 0.2);
  }

  /* ═══════════════════════════════════════════════════════════════
     LIGHT THEME — "Pixel Daybreak"
     Warm cream surfaces, pastel sky, golden sparkles, soft shadows
     ═══════════════════════════════════════════════════════════════ */

  @property --sky-mid-l {
    syntax: '<color>';
    inherits: true;
    initial-value: #b8c8f0;
  }
  @property --sky-low-l {
    syntax: '<color>';
    inherits: true;
    initial-value: #e0c0d8;
  }
  @property --horizon-l {
    syntax: '<color>';
    inherits: true;
    initial-value: #f5d8a8;
  }

  html.light {
    --bg:         #f5f2ec;
    --surface:    rgba(255, 255, 255, 0.6);
    --surface-solid: #faf8f4;
    --border:     rgba(160, 130, 90, 0.12);
    --border-hi:  rgba(160, 130, 90, 0.22);
    --text:       #2a2440;
    --text-dim:   #7a7490;
    --accent:     #0e8a7a;
    --accent-dim: #d8f2ec;
    --danger:     #d94040;
    --warm:       #c88a18;
    --sky-top:    #8abce8;
    --sky-mid:    #b8c8f0;
    --sky-low:    #e0c0d8;
    --horizon:    #f5d8a8;
    --star:       rgba(220, 180, 80, 0.5);
  }

  html.light body {
    background:
      repeating-linear-gradient(
        0deg,
        transparent, transparent 1px,
        rgba(0,0,0,0.015) 1px, rgba(0,0,0,0.015) 2px
      ),
      repeating-linear-gradient(
        90deg,
        transparent, transparent 1px,
        rgba(0,0,0,0.015) 1px, rgba(0,0,0,0.015) 2px
      ),
      linear-gradient(
        180deg,
        var(--sky-top) 0%,
        var(--sky-mid) 30%,
        var(--sky-low) 55%,
        var(--horizon) 100%
      );
    color: var(--text);
    animation: skyShiftLight 25s ease-in-out infinite alternate;
  }

  @keyframes skyShiftLight {
    0%   { --sky-mid: #b8c8f0; --sky-low: #e0c0d8; --horizon: #f5d8a8; }
    50%  { --sky-mid: #c0d0f4; --sky-low: #e8c8e0; --horizon: #f8e0b8; }
    100% { --sky-mid: #b0c0e8; --sky-low: #d8b8d0; --horizon: #f0d0a0; }
  }

  /* Light starfield — golden sparkles */
  html.light body::before {
    background: radial-gradient(2px 2px at 12% 8%, rgba(220,180,60,0.4) 50%, transparent 100%),
      radial-gradient(2px 2px at 28% 15%, rgba(220,180,60,0.35) 50%, transparent 100%),
      radial-gradient(2.5px 2.5px at 45% 4%, rgba(240,200,80,0.4) 50%, transparent 100%),
      radial-gradient(2px 2px at 62% 12%, rgba(220,180,60,0.3) 50%, transparent 100%),
      radial-gradient(2px 2px at 78% 6%, rgba(220,180,60,0.35) 50%, transparent 100%),
      radial-gradient(2.5px 2.5px at 91% 18%, rgba(240,200,80,0.4) 50%, transparent 100%),
      radial-gradient(2px 2px at 5% 25%, rgba(220,180,60,0.3) 50%, transparent 100%),
      radial-gradient(2px 2px at 35% 22%, rgba(220,180,60,0.35) 50%, transparent 100%),
      radial-gradient(2.5px 2.5px at 55% 28%, rgba(240,200,80,0.4) 50%, transparent 100%),
      radial-gradient(2px 2px at 72% 20%, rgba(220,180,60,0.3) 50%, transparent 100%),
      radial-gradient(2px 2px at 88% 30%, rgba(220,180,60,0.35) 50%, transparent 100%),
      radial-gradient(2px 2px at 18% 35%, rgba(220,180,60,0.3) 50%, transparent 100%),
      radial-gradient(2.5px 2.5px at 40% 38%, rgba(240,200,80,0.4) 50%, transparent 100%),
      radial-gradient(2px 2px at 65% 33%, rgba(220,180,60,0.3) 50%, transparent 100%),
      radial-gradient(2px 2px at 82% 40%, rgba(220,180,60,0.35) 50%, transparent 100%),
      radial-gradient(2px 2px at 8% 44%, rgba(220,180,60,0.3) 50%, transparent 100%),
      radial-gradient(2.5px 2.5px at 25% 48%, rgba(240,200,80,0.4) 50%, transparent 100%),
      radial-gradient(2px 2px at 50% 42%, rgba(220,180,60,0.3) 50%, transparent 100%),
      radial-gradient(2px 2px at 70% 46%, rgba(220,180,60,0.35) 50%, transparent 100%),
      radial-gradient(2px 2px at 95% 10%, rgba(220,180,60,0.3) 50%, transparent 100%);
    animation: twinkle1Light 5s ease-in-out infinite alternate;
  }
  html.light body::after {
    background: radial-gradient(2px 2px at 7% 11%, rgba(200,160,60,0.3) 50%, transparent 100%),
      radial-gradient(2.5px 2.5px at 22% 5%, rgba(200,160,60,0.25) 50%, transparent 100%),
      radial-gradient(2px 2px at 42% 18%, rgba(200,160,60,0.3) 50%, transparent 100%),
      radial-gradient(2px 2px at 58% 9%, rgba(200,160,60,0.25) 50%, transparent 100%),
      radial-gradient(2.5px 2.5px at 75% 22%, rgba(200,160,60,0.3) 50%, transparent 100%),
      radial-gradient(2px 2px at 90% 14%, rgba(200,160,60,0.25) 50%, transparent 100%),
      radial-gradient(2px 2px at 33% 30%, rgba(200,160,60,0.3) 50%, transparent 100%),
      radial-gradient(2px 2px at 48% 35%, rgba(200,160,60,0.25) 50%, transparent 100%),
      radial-gradient(2.5px 2.5px at 68% 28%, rgba(200,160,60,0.3) 50%, transparent 100%),
      radial-gradient(2px 2px at 83% 36%, rgba(200,160,60,0.25) 50%, transparent 100%),
      radial-gradient(2px 2px at 3% 40%, rgba(200,160,60,0.3) 50%, transparent 100%),
      radial-gradient(2px 2px at 52% 44%, rgba(200,160,60,0.25) 50%, transparent 100%);
    animation: twinkle2Light 6s ease-in-out infinite alternate;
  }
  @keyframes twinkle1Light {
    0%   { opacity: 0.5; }
    50%  { opacity: 0.8; }
    100% { opacity: 0.5; }
  }
  @keyframes twinkle2Light {
    0%   { opacity: 0.6; }
    50%  { opacity: 0.3; }
    100% { opacity: 0.7; }
  }

  /* Light particles — golden / rose motes */
  html.light .pixel-particle { background: rgba(200, 160, 60, 0.6); }
  html.light .pixel-particle:nth-child(odd) { background: rgba(180, 100, 120, 0.5); }
  html.light .pixel-particle:nth-child(3n) { background: rgba(220, 180, 80, 0.5); }

  /* Light surfaces — warm frosted white glass */
  html.light .auth-box {
    background: rgba(255, 255, 252, 0.65);
    border-color: rgba(160, 130, 90, 0.15);
    box-shadow: 0 8px 32px rgba(120, 100, 60, 0.12), inset 0 1px 0 rgba(255,255,255,0.6);
  }
  html.light .form-group input {
    background: rgba(255, 255, 252, 0.7);
    border-color: rgba(160, 130, 90, 0.15);
    color: #2a2440;
  }
  html.light .form-group input:hover { border-color: rgba(160, 130, 90, 0.3); }
  html.light .form-group input:focus { border-color: var(--accent); }
  html.light .form-group input::placeholder { color: #a09ab0; }
  html.light .btn-primary { background: var(--accent); color: #fff; }
  html.light .btn-primary:hover { background: #10a090; }
  html.light .btn-primary:disabled { background: rgba(160,130,90,0.15); color: #a09ab0; }
  html.light .btn-secondary { border-color: rgba(160,130,90,0.2); color: #7a7490; }
  html.light .btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
  html.light .auth-logo { color: var(--accent); }
  html.light .auth-toggle a { color: var(--accent); }

  /* Light gen-bar */
  html.light .gen-bar input {
    background: rgba(255, 255, 252, 0.6);
    border-color: rgba(160, 130, 90, 0.12);
    color: #2a2440;
  }
  html.light .gen-bar input::placeholder { color: #a09ab0; }
  html.light .gen-bar button { background: var(--accent); color: #fff; }
  html.light .gen-bar button:hover { background: #10a090; }
  html.light .gen-bar button:disabled { background: rgba(160,130,90,0.15); color: #a09ab0; }

  /* Light character grid */
  html.light .char-cell {
    background: rgba(255, 255, 252, 0.55);
    border-color: rgba(160, 130, 90, 0.1);
    box-shadow: 0 2px 8px rgba(120, 100, 60, 0.08);
  }
  html.light .char-cell:hover { border-color: var(--accent); box-shadow: 0 4px 16px rgba(14, 138, 122, 0.12); }
  html.light .char-cell.selected { border-color: var(--accent); box-shadow: 0 0 16px rgba(14, 138, 122, 0.2); }
  html.light .char-cell .char-id { color: #7a7490; }
  html.light .char-cell.new-char { border-color: var(--warm); box-shadow: 0 0 14px rgba(200, 138, 24, 0.3); }
  html.light .char-cell.new-char .new-badge { color: #fff; }

  /* Light gen overlay */
  html.light .gen-overlay { background: rgba(248, 246, 240, 0.88); }
  html.light .gen-status { color: var(--accent); }
  html.light .gen-cancel { border-color: rgba(160,130,90,0.2); color: #7a7490; }

  /* Light spinner */
  html.light .boot-spinner { border-color: rgba(160,130,90,0.2); border-top-color: var(--accent); }
  html.light .spinner { border-color: rgba(160,130,90,0.2); border-top-color: var(--accent); }

  /* Light room screen */
  html.light #room-screen { background: rgba(248, 246, 240, 0.5); }
  html.light .room-back {
    background: rgba(255, 255, 252, 0.6);
    border-color: rgba(160, 130, 90, 0.15);
    color: #7a7490;
    box-shadow: 0 2px 8px rgba(120, 100, 60, 0.08);
  }
  html.light .room-back:hover { border-color: var(--accent); color: var(--accent); }
  html.light .room-label {
    background: rgba(255, 255, 252, 0.6);
    border-color: rgba(160, 130, 90, 0.12);
    color: #7a7490;
  }
  html.light .room-label.live { border-color: rgba(14, 138, 122, 0.3); color: var(--accent); }
  html.light .room-label.live::before { background: var(--accent); }
  html.light #room-canvas {
    border-color: rgba(160, 130, 90, 0.15);
    box-shadow: 0 4px 24px rgba(120, 100, 60, 0.15);
  }
  html.light .template-nav {
    background: rgba(255, 255, 252, 0.65);
    border-color: rgba(160, 130, 90, 0.15);
    color: var(--accent);
    box-shadow: 0 2px 8px rgba(120, 100, 60, 0.08);
  }
  html.light .template-nav:hover { background: rgba(14, 138, 122, 0.08); border-color: var(--accent); }
  html.light #template-label {
    background: rgba(255, 255, 252, 0.65);
    border-color: rgba(160, 130, 90, 0.12);
    color: var(--accent);
  }
  html.light .room-bottom { background: linear-gradient(transparent, rgba(248, 246, 240, 0.6)); }
  html.light .btn-enter { background: var(--accent); color: #fff; }
  html.light .btn-enter:hover { background: #10a090; }
  html.light .room-controls-hint { color: #8a84a0; }

  /* Light toolbar */
  html.light .tb-btn {
    background: rgba(255, 255, 252, 0.6);
    border-color: rgba(160, 130, 90, 0.15);
    color: #2a2440;
    box-shadow: 0 2px 8px rgba(120, 100, 60, 0.08);
  }
  html.light .tb-btn:hover { border-color: var(--accent); color: var(--accent); }

  /* Light game screen */
  html.light #game-screen { background: rgba(248, 246, 240, 0.55); }
  html.light #online-panel {
    background: rgba(255, 255, 252, 0.6);
    border-right-color: rgba(160, 130, 90, 0.1);
  }
  html.light .panel-header { border-bottom-color: rgba(160, 130, 90, 0.1); color: #7a7490; }
  html.light .online-count { background: rgba(14, 138, 122, 0.1); color: var(--accent); }
  html.light .online-player { border-bottom-color: rgba(160, 130, 90, 0.06); }
  html.light .online-player-name { color: #2a2440; }
  html.light .online-dot { background: var(--accent); }
  html.light .online-room { color: #8a84a0; }
  html.light .online-self .online-dot { background: var(--warm); }
  html.light .online-self .online-player-name { color: var(--warm); }
  html.light .btn-visit { border-color: rgba(160, 130, 90, 0.15); color: #7a7490; }
  html.light .btn-visit:hover { border-color: var(--accent); color: var(--accent); }

  /* Light chat */
  html.light .chat-divider { border-top-color: rgba(160, 130, 90, 0.1); color: #8a84a0; }
  html.light .chat-toggle-btn { border-color: rgba(160, 130, 90, 0.15); color: #8a84a0; }
  html.light .chat-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }
  html.light #chat-section { border-top-color: rgba(160, 130, 90, 0.08); }
  html.light .chat-msg .name { color: var(--accent); }
  html.light .chat-msg .text { color: #2a2440; }
  html.light #chat-form { border-top-color: rgba(160, 130, 90, 0.08); }
  html.light #chat-form input { background: rgba(255, 255, 252, 0.7); color: #2a2440; }
  html.light #chat-form input:focus { background: rgba(255, 255, 252, 0.9); }
  html.light #chat-form input::placeholder { color: #a09ab0; }
  html.light #chat-form button { background: rgba(14, 138, 122, 0.1); color: var(--accent); border-left-color: rgba(160, 130, 90, 0.08); }
  html.light #chat-form button:hover { background: var(--accent); color: #fff; }

  /* Light game area */
  html.light #game-main { background: rgba(248, 246, 240, 0.3); }
  html.light #game-canvas {
    border-color: rgba(160, 130, 90, 0.15);
    box-shadow: 0 4px 24px rgba(120, 100, 60, 0.15);
  }
  html.light .game-back {
    background: rgba(255, 255, 252, 0.6);
    border-color: rgba(160, 130, 90, 0.15);
    color: #7a7490;
    box-shadow: 0 2px 8px rgba(120, 100, 60, 0.08);
  }
  html.light .game-back:hover { border-color: var(--accent); color: var(--accent); }
  html.light .controls-hint { color: #8a84a0; }

  /* Light log bar */
  html.light .log-bar {
    background: rgba(255, 255, 252, 0.6);
    border-right-color: rgba(160, 130, 90, 0.08);
    color: #8a84a0;
  }
  html.light .log-bar .error { color: var(--danger); }
  html.light .log-bar .ok { color: var(--accent); }

  /* Light furniture */
  html.light .furn-trash { background: rgba(220, 80, 80, 0.1); border-color: var(--danger); }
  html.light .furn-trash.over { background: rgba(220, 80, 80, 0.25); }

  /* Light toggle button */
  html.light .theme-toggle {
    background: rgba(255, 255, 252, 0.6);
    border-color: rgba(160, 130, 90, 0.18);
    box-shadow: 0 2px 12px rgba(120, 100, 60, 0.12);
  }
  html.light .theme-toggle:hover {
    box-shadow: 0 4px 20px rgba(14, 138, 122, 0.15);
  }

  /* Smooth theme crossfade */
  html.transitioning, html.transitioning *,
  html.transitioning *::before, html.transitioning *::after {
    transition: background 0.5s ease, color 0.4s ease, border-color 0.4s ease,
                box-shadow 0.4s ease, opacity 0.4s ease !important;
  }
