:root {
      --bg: #eef0f5;
      --panel: #ffffff;
      --border: #dde1ea;
      --text: #1a1d26;
      --muted: #6b7289;
      --accent: #00c9a7;
      --accent2: #6c5ce7;
      --sidebar-w: 210px;
      --b-draw: #4c97ff;
      --b-move: #ffab19;
      --b-ctrl: #ff8c42;
      --b-var: #d2691e;
      --b-game: #2e86c1;
      --b-event: #e67e22;
      --b-score: #9b59b6;
      --b-loop: #16a085;
      --b-func: #c0392b;
    }
    * { box-sizing: border-box; margin: 0; padding: 0; }
    body {
      font-family: 'Outfit', sans-serif;
      background: var(--bg);
      color: var(--text);
      height: 100vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      font-size: 17px;
    }

    .topbar {
      height: 54px;
      background: var(--panel);
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 16px;
      flex-shrink: 0;
      z-index: 40;
    }
    .brand-inline {
      display: flex;
      align-items: center;
      gap: 10px;
      font-weight: 700;
      font-size: 1.4rem;
      color: #16a085;
      font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    }
    .brand-inline .logo {
      width: 36px; height: 36px;
      border-radius: 10px;
      background: linear-gradient(135deg, var(--accent), var(--accent2));
      display: grid; place-items: center;
    }
    .brand-inline .logo svg { width: 20px; height: 20px; }
    .topbar-actions {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
    }
    /* Mobil oyun tarzı butonlar */
    .btn-pick, .btn-clear, .btn-help, .btn-save {
      padding: 10px 16px;
      border-radius: 16px;
      font-family: inherit;
      font-size: 0.9rem;
      font-weight: 800;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      border: 3px solid rgba(0,0,0,0.12);
      border-bottom-width: 5px;
      box-shadow: 0 2px 0 rgba(0,0,0,0.08);
      transition: transform 0.08s, border-bottom-width 0.08s, filter 0.12s;
      user-select: none;
    }
    .btn-pick:active, .btn-clear:active, .btn-help:active, .btn-save:active {
      transform: translateY(3px);
      border-bottom-width: 2px;
      box-shadow: none;
    }
    .btn-pick {
      background: linear-gradient(180deg, #9b7dff 0%, #6c5ce7 100%);
      color: #fff;
      border-color: #5a4bd1;
      text-shadow: 0 1px 0 rgba(0,0,0,0.2);
    }
    .btn-pick:hover { filter: brightness(1.06); }
    .btn-save {
      background: linear-gradient(180deg, #5eead4 0%, #14b8a6 100%);
      color: #fff;
      border-color: #0d9488;
      text-shadow: 0 1px 0 rgba(0,0,0,0.15);
    }
    .btn-save:hover { filter: brightness(1.06); }
    .btn-help {
      background: linear-gradient(180deg, #ffffff 0%, #e8ecf4 100%);
      color: #3d4455;
      border-color: #c5cad6;
    }
    .btn-help:hover { filter: brightness(1.03); }
    .btn-clear {
      background: linear-gradient(180deg, #ff8a9a 0%, #ef4444 100%);
      color: #fff;
      border-color: #dc2626;
      text-shadow: 0 1px 0 rgba(0,0,0,0.15);
    }
    .btn-clear:hover { filter: brightness(1.05); }

    .body-row { flex: 1; display: flex; min-height: 0; }

    #sidebar {
      width: var(--sidebar-w);
      background: var(--panel);
      border-right: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      flex-shrink: 0;
      z-index: 25;
      overflow-y: auto;
    }
    .nav-label {
      padding: 14px 12px 8px;
      font-size: 0.75rem;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 0.08em;
      font-weight: 700;
    }
    .cat-btn {
      margin: 3px 8px;
      padding: 13px 12px;
      border: none;
      border-radius: 10px;
      background: transparent;
      color: var(--muted);
      font-family: inherit;
      font-size: 1rem;
      font-weight: 600;
      text-align: left;
      cursor: pointer;
      display: flex;
      align-items: center;
      gap: 9px;
      width: calc(100% - 16px);
    }
    .cat-btn:hover, .cat-btn.open {
      background: #f0eefc;
      color: var(--accent2);
    }
    .cat-btn .dot {
      width: 10px; height: 10px;
      border-radius: 3px;
      flex-shrink: 0;
    }

    .block-flyout {
      position: fixed;
      top: 54px;
      left: var(--sidebar-w);
      width: 280px;
      height: calc(100vh - 54px);
      background: var(--panel);
      border-right: 1px solid var(--border);
      box-shadow: 10px 0 28px rgba(0,0,0,0.1);
      z-index: 30;
      display: flex;
      flex-direction: column;
      transform: translateX(-10px);
      opacity: 0;
      pointer-events: none;
      transition: 0.15s ease;
    }
    .block-flyout.open {
      transform: translateX(0);
      opacity: 1;
      pointer-events: auto;
    }
    .flyout-head {
      padding: 14px;
      border-bottom: 1px solid var(--border);
      font-weight: 700;
      font-size: 1.05rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .flyout-head button {
      border: none; background: none;
      font-size: 1.3rem; cursor: pointer; color: var(--muted);
    }
    #flyoutList { flex: 1; overflow-y: auto; padding: 12px; }
    .code-block {
      padding: 11px 12px;
      border-radius: 9px;
      color: #fff;
      font-family: 'JetBrains Mono', monospace;
      font-size: 0.82rem;
      font-weight: 600;
      cursor: pointer;
      margin-bottom: 8px;
      display: flex;
      flex-direction: column;
      gap: 3px;
      box-shadow: 0 2px 0 rgba(0,0,0,0.15);
    }
    .code-block:hover { filter: brightness(1.08); }
    .code-block .tr-label {
      font-family: Outfit, sans-serif;
      font-size: 0.78rem;
      font-weight: 600;
      opacity: 0.95;
    }
    .code-block .hint {
      font-size: 0.68rem;
      opacity: 0.8;
      font-family: Outfit, sans-serif;
      font-weight: 500;
    }
    .code-block.draw { background: var(--b-draw); }
    .code-block.move { background: var(--b-move); color: #1a1000; }
    .code-block.ctrl { background: var(--b-ctrl); }
    .code-block.vars { background: var(--b-var); }
    .code-block.game { background: var(--b-game); }
    .code-block.event { background: var(--b-event); }
    .code-block.score { background: var(--b-score); }
    .code-block.loop { background: var(--b-loop); }
    .code-block.func { background: var(--b-func); }
    .code-block.sprite { background: #e84393; }
    .code-block.anim { background: #ff6bcb; color: #fff; }

    .work { flex: 1; display: flex; min-width: 0; background-color: white; }

    .editor-col {
      flex: 1 1 40%;
      min-width: 300px;
      display: flex;
      flex-direction: column;
      background: #ffffff;
      margin: 10px 6px 10px 10px;
      overflow: hidden;
    }

    .right-col {
      flex: 1 1 60%;
      min-width: 360px;
      background: #fff;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 28px 14px 14px;
      overflow-y: auto;
    }

    .game-title {
      width: 100%;
      max-width: 480px;
      display: flex;
      align-items: center;
      gap: 12px;
      margin-bottom: 4px;
    }
    .game-title .icon {
      width: 44px; height: 44px;
      border-radius: 12px;
      background: linear-gradient(135deg, #ff6b6b, #feca57);
      display: grid; place-items: center;
      font-size: 1.4rem;
    }
    .game-title h2 { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
    .game-title small { display: block; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
    .step-label {
      width: 100%;
      max-width: 480px;
      color: #e67e22;
      font-weight: 700;
      font-size: 1.1rem;
      margin: 2px 0 8px;
    }

    .stage-area {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: flex-start;
      gap: 12px;
      width: 100%;
      max-width: 480px;
      margin: 12px auto 0;
      padding-top: 16px;
      flex: 1;
      min-height: 0;
    }
    .phone-wrap {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 12px;
      width: 100%;
      max-width: 480px;
      flex: 0 0 auto;
      margin-top: 8px;
    }
    .info-panel {
      position: fixed;
      z-index: 95;
      width: 380px;
      max-width: calc(100vw - 24px);
      max-height: min(640px, 85vh);
      right: 40px;
      top: 70px;
      left: auto;
      bottom: auto;
      overflow: hidden;
      background: #fff;
      border: 1px solid var(--border);
      border-radius: 16px;
      box-shadow: 0 18px 48px rgba(0,0,0,0.22);
      display: none;
      flex-direction: column;
      pointer-events: auto;
    }
    .info-panel.open {
      display: flex;
    }
    .info-drag-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 10px 12px;
      background: linear-gradient(135deg, #e8f0ff, #f0eefc);
      border-bottom: 1px solid var(--border);
      cursor: grab;
      user-select: none;
      touch-action: none;
      flex-shrink: 0;
    }
    .info-drag-head:active { cursor: grabbing; }
    .info-drag-head h3 {
      font-size: 1.05rem;
      margin: 0;
    }
    .info-drag-head button {
      border: none;
      background: rgba(255,255,255,0.9);
      color: var(--muted);
      width: 30px; height: 28px;
      border-radius: 8px;
      font-size: 1.1rem;
      cursor: pointer;
      flex-shrink: 0;
    }
    .info-drag-head button:hover { background: #fff; color: var(--text); }
    .info-panel-inner {
      width: 100%;
      flex: 1;
      overflow-y: auto;
      padding: 14px 18px 18px;
      min-height: 0;
    }
    .info-panel-inner > p:first-of-type { color: var(--muted); margin-bottom: 14px; font-size: 0.95rem; }
    .phone {
      width: min(440px, 100%);
      flex-shrink: 0;
      background: #1a1a1a;
      border-radius: 36px;
      padding: 16px 14px 22px;
      box-shadow: 0 20px 48px rgba(0,0,0,0.24);
    }
    .phone-notch {
      width: 72px; height: 8px;
      background: #333;
      border-radius: 4px;
      margin: 0 auto 14px;
    }
    .phone-screen {
      position: relative;
      background: #000;
      border-radius: 10px;
      overflow: hidden;
      aspect-ratio: 3 / 4;
    }
    #gameCanvas {
      width: 100%;
      height: 100%;
      display: block;
      background: #ffffff;
    }
    .phone-home {
      width: 44px; height: 44px;
      border: 2px solid #555;
      border-radius: 50%;
      margin: 14px auto 0;
      cursor: pointer;
      background: #2a2a2a;
      transition: background 0.15s, border-color 0.15s, transform 0.1s;
    }
    .phone-home:hover {
      background: #3a3a3a;
      border-color: #888;
    }
    .phone-home:active { transform: scale(0.92); }
    .phone-home.active-home {
      border-color: #7c5cff;
      box-shadow: 0 0 0 3px rgba(124, 92, 231, 0.35);
    }
    .phone-home-screen {
      position: absolute;
      inset: 0;
      z-index: 5;
      background: linear-gradient(160deg, #1a1d2e 0%, #2d1f4e 50%, #1a2a3a 100%);
      display: none;
      flex-direction: column;
      padding: 14px 12px 12px;
      overflow: hidden;
    }
    .phone-home-screen.open { display: flex; }
    .phs-title {
      color: #fff;
      font-size: 0.95rem;
      font-weight: 700;
      text-align: center;
      margin-bottom: 12px;
    }
    .phs-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 12px 8px;
      overflow-y: auto;
      flex: 1;
      min-height: 0;
      padding: 4px 2px 8px;
      align-content: start;
    }
    .phs-app {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 5px;
      cursor: pointer;
      border: none;
      background: transparent;
      font-family: inherit;
      padding: 4px;
    }
    .phs-app:hover .phs-icon {
      transform: scale(1.08);
      box-shadow: 0 6px 16px rgba(0,0,0,0.35);
    }
    .phs-icon {
      width: 52px;
      height: 52px;
      border-radius: 14px;
      background: linear-gradient(145deg, #fff, #e8e4ff);
      display: grid;
      place-items: center;
      font-size: 1.55rem;
      box-shadow: 0 4px 12px rgba(0,0,0,0.25);
      transition: transform 0.12s, box-shadow 0.12s;
    }
    .phs-label {
      color: #f0f0f5;
      font-size: 0.68rem;
      font-weight: 600;
      text-align: center;
      line-height: 1.2;
      max-width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .phs-empty {
      color: rgba(255,255,255,0.65);
      font-size: 0.85rem;
      text-align: center;
      margin: auto 12px;
      line-height: 1.45;
    }
    .phs-hint {
      color: rgba(255,255,255,0.45);
      font-size: 0.7rem;
      text-align: center;
      margin-top: 8px;
      flex-shrink: 0;
    }


    .editor-wrap {
      position: relative;
      flex: 1 1 auto;
      min-height: 180px;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
    .project-bar {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 12px 14px;
      background: linear-gradient(180deg, #ffffff 0%, #f3f4f8 100%);
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
      min-height: 52px;
    }
    .project-bar .project-icon,
    .project-bar #gameIcon {
      font-size: 1.4rem;
      line-height: 1;
      width: 40px;
      height: 40px;
      border-radius: 12px;
      background: #fff;
      border: 1px solid var(--border);
      box-shadow: 0 2px 6px rgba(0,0,0,0.06);
      display: grid;
      place-items: center;
      flex-shrink: 0;
    }
    .project-bar .project-name,
    .project-bar #gameName {
      font-weight: 800;
      font-size: 1.1rem;
      color: var(--text);
      letter-spacing: -0.02em;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    #editor {
      flex: 1 1 auto;
      min-height: 180px;
      width: 100%;
    }
    /* Beyaz arka plan + satır */
    #editor .ace_editor,
    #editor .ace_content {
      background: #ffffff !important;
      font-family: 'JetBrains Mono', monospace !important;
    }
    #editor .ace_gutter {
      background: #ffffff !important;
      color: #a0a5b5 !important;
      border-right: 1px solid #e8eaf0;
      width: 46px !important;
    }
    #editor .ace_gutter-active-line {
      background: #f0eefc !important;
      color: var(--accent2) !important;
      font-weight: 600;
    }
    #editor .ace_active-line { background: #f8f7ff !important; }
    #editor .ace_marker-layer .ace_selection {
      background: #d4ccf8 !important;
      border-radius: 3px;
    }
    #editor .ace_cursor { border-left: 2.5px solid var(--accent2) !important; }
    #editor .ace_print-margin { display: none !important; }
    #editor .ace_scrollbar-v { width: 10px !important; }
    #editor .ace_scrollbar-h { height: 10px !important; }
    #editor .ace_indent-guide { background: none !important; border-right: 1px dashed #e0e3ec !important; }
    #editor .ace_keyword { color: #6c5ce7 !important; font-weight: 600; }
    #editor .ace_string { color: #059669 !important; }
    #editor .ace_constant.ace_numeric { color: #d97706 !important; }
    #editor .ace_function { color: #2563eb !important; }
    #editor .ace_comment { color: #94a3b8 !important; font-style: italic; }
    #editor .ace_storage { color: #c0392b !important; font-weight: 600; }
    #editor .ace_support.ace_function { color: #2e86c1 !important; }

    /* Bilgi / rehber — sürüklenir popup (ilk konum: editör alanı) */
    .guide-panel {
      position: fixed;
      z-index: 90;
      width: 520px;
      max-width: calc(100vw - 24px);
      max-height: min(620px, 85vh);
      /* ilk konum JS ile editör üzerine ayarlanır; fallback sol-orta */
      left: 230px;
      top: 280px;
      right: auto;
      bottom: auto;
      overflow: hidden;
      background: #ffffff;
      border: 1px solid var(--border);
      border-radius: 16px;
      box-shadow: 0 18px 48px rgba(0,0,0,0.2);
      display: flex;
      flex-direction: column;
      gap: 0;
      padding: 0;
    }
    .guide-panel.hidden-panel {
      display: none !important;
    }
    .guide-panel.minimized {
      max-height: none;
      width: 300px;
    }
    .guide-panel.minimized .guide-body {
      display: none;
    }
    .guide-drag-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 10px 12px;
      background: linear-gradient(135deg, #f0eefc, #e8faf6);
      border-bottom: 1px solid var(--border);
      cursor: grab;
      user-select: none;
      touch-action: none;
      flex-shrink: 0;
    }
    .guide-drag-head:active { cursor: grabbing; }
    .guide-drag-head .gh-title {
      font-weight: 700;
      font-size: 0.95rem;
      color: var(--text);
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .guide-drag-head .gh-title span { opacity: 0.7; font-size: 0.85rem; font-weight: 600; }
    .guide-drag-btns {
      display: flex;
      gap: 4px;
      flex-shrink: 0;
    }
    .guide-drag-btns button {
      width: 30px; height: 28px;
      border: none;
      border-radius: 8px;
      background: rgba(255,255,255,0.85);
      color: var(--muted);
      font-size: 1rem;
      font-weight: 700;
      cursor: pointer;
      line-height: 1;
    }
    .guide-drag-btns button:hover {
      background: #fff;
      color: var(--accent2);
    }
    .guide-body {
      padding: 14px 16px 16px;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      gap: 8px;
      flex: 1;
      min-height: 0;
    }
    .speech .code-line {
      max-height: 160px !important;
    }
    .phone-play-bar {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
      margin-top: 8px;
      width: 100%;
      max-width: 480px;
    }
    .phone-play-bar .play-btn {
      margin-top: 0;
    }
    .btn-toggle-guide {
      padding: 10px 14px;
      border-radius: 14px;
      border: 3px solid #5a4bd1;
      border-bottom-width: 5px;
      background: linear-gradient(180deg, #9b7dff, #6c5ce7);
      color: #fff;
      font-family: inherit;
      font-size: 0.88rem;
      font-weight: 800;
      cursor: pointer;
      text-shadow: 0 1px 0 rgba(0,0,0,0.2);
    }
    .btn-toggle-guide:active {
      transform: translateY(2px);
      border-bottom-width: 2px;
    }
    .btn-toggle-guide:hover {
      border-color: var(--accent2);
      background: #f0eefc;
    }
    #gameCanvas {
      cursor: crosshair;
      touch-action: none;
    }

    /* Adım satırı:  1  fill('...')  gibi */
    .step-code-line {
      display: none;
      align-items: flex-start;
      gap: 10px;
      margin-bottom: 10px;
      font-family: 'JetBrains Mono', monospace;
      font-size: 0.95rem;
      font-weight: 600;
      line-height: 1.45;
      padding: 2px 0 6px;
    }
    .step-code-line.show { display: flex; }
    .step-code-line .num {
      color: #e67e22;
      min-width: 22px;
      text-align: right;
      user-select: none;
    }
    .step-code-line .code {
      color: #c0392b;
      white-space: pre-wrap;
      word-break: break-word;
    }

    .guide-row {
      display: flex;
      align-items: flex-start;
      gap: 12px;
      flex-wrap: wrap;
    }

    .play-btn {
      width: 56px; height: 56px;
      border-radius: 50%;
      border: 4px solid #16a34a;
      border-bottom-width: 6px;
      background: linear-gradient(180deg, #4ade80 0%, #22c55e 100%);
      color: #fff;
      font-size: 1.4rem;
      cursor: pointer;
      box-shadow: 0 4px 0 rgba(0,0,0,0.12), 0 6px 16px rgba(34, 197, 94, 0.35);
      transition: transform 0.08s, border-bottom-width 0.08s;
      flex-shrink: 0;
      margin-top: 8px;
      text-shadow: 0 1px 0 rgba(0,0,0,0.2);
    }
    .play-btn:hover { filter: brightness(1.06); }
    .play-btn:active {
      transform: translateY(3px);
      border-bottom-width: 3px;
      box-shadow: 0 1px 0 rgba(0,0,0,0.1);
    }
    .play-btn.pulse { animation: pulse 1s ease infinite; }
    .play-btn.running {
      background: linear-gradient(180deg, #f87171 0%, #ef4444 100%);
      border-color: #dc2626;
      box-shadow: 0 4px 0 rgba(0,0,0,0.12), 0 6px 16px rgba(239, 68, 68, 0.35);
    }
    @keyframes pulse {
      50% { transform: scale(1.08); box-shadow: 0 5px 18px rgba(34, 197, 94, 0.55); }
    }

    .speech {
      flex: 1;
      background: #eceff1;
      border-radius: 14px;
      overflow: hidden;
      position: relative;
      font-size: 0.98rem;
      min-width: 0;
    }
    .speech::before {
      content: "";
      position: absolute;
      left: 22px;
      top: -8px;
      border: 8px solid transparent;
      border-bottom-color: #eceff1;
    }
    .speech .line { padding: 10px 14px; border-bottom: 1px solid #dde3e8; }
    .speech .line:last-child { border-bottom: none; }
    .speech .say-line {
      color: #5a6570;
      font-weight: 600;
      font-size: 0.95rem;
    }
    .speech .code-line {
      background: #f7f9fb;
      font-family: 'JetBrains Mono', monospace;
      font-size: 0.92rem;
      font-weight: 600;
      color: #c0392b;
      white-space: pre-wrap;
      line-height: 1.45;
      max-height: 90px;
      overflow-y: auto;
    }
    .speech .hint-line {
      color: #6b7280;
      font-weight: 500;
      font-size: 0.9rem;
    }

    .guide-actions {
      display: flex;
      gap: 8px;
      margin-top: 10px;
      flex-wrap: wrap;
      padding-left: 0;
    }

    .btn-sample {
      flex: 1;
      min-width: 160px;
      padding: 14px 16px;
      border-radius: 12px;
      border: 2px dashed var(--accent2);
      background: #f8f7ff;
      color: var(--accent2);
      font-family: inherit;
      font-size: 1rem;
      font-weight: 700;
      cursor: pointer;
      text-align: center;
      line-height: 1.35;
    }
    .btn-sample:hover { background: #f0eefc; border-style: solid; }
    .guide-row {
      display: flex;
      align-items: stretch;
      gap: 12px;
      flex-wrap: wrap;
    }
    #btnSample:not([hidden]) {
      display: block;
      width: 100%;
    }

    .btn-copy {
      flex: 1;
      padding: 10px 12px;
      border: none;
      border-radius: 10px;
      background: #22c55e;
      color: #fff;
      font-family: inherit;
      font-size: 0.92rem;
      font-weight: 700;
      cursor: pointer;
    }
    .btn-copy:hover { filter: brightness(1.06); }
    .btn-copy[hidden] { display: none !important; }
    .btn-copy.copied {
      background: #059669;
    }

    .btn-next {
      flex: 1;
      padding: 10px 12px;
      border: none;
      border-radius: 10px;
      background: var(--accent2);
      color: #fff;
      font-family: inherit;
      font-size: 0.92rem;
      font-weight: 700;
      cursor: pointer;
    }
    .btn-next:hover { filter: brightness(1.06); }
    .btn-next[hidden], .btn-sample[hidden] { display: none !important; }

    #console {
      display: none !important;
    }

    .modal-bg {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(15, 18, 28, 0.45);
      z-index: 100;
      align-items: center;
      justify-content: center;
    }
    .modal-bg.open { display: flex; }
    .modal {
      background: #fff;
      border-radius: 18px;
      width: min(980px, 96vw);
      max-height: 92vh;
      overflow: hidden;
      padding: 16px 18px 14px;
      box-shadow: 0 24px 60px rgba(0,0,0,0.25);
      display: flex;
      flex-direction: column;
    }
    .modal h3 { font-size: 1.2rem; margin-bottom: 2px; flex-shrink: 0; }
    .modal p { color: var(--muted); margin-bottom: 10px; font-size: 0.92rem; flex-shrink: 0; }
    .game-grid {
      display: grid;
      grid-template-columns: repeat(5, 1fr);
      gap: 8px;
      margin-bottom: 10px;
      flex: 1;
      min-height: 0;
      overflow: hidden;
    }
    @media (max-width: 900px) {
      .game-grid { grid-template-columns: repeat(4, 1fr); }
    }
    @media (max-width: 640px) {
      .game-grid { grid-template-columns: repeat(3, 1fr); }
    }
    .game-card {
      display: flex;
      flex-direction: column;
      align-items: center;
      text-align: center;
      gap: 3px;
      padding: 8px 6px 8px;
      border: 2px solid var(--border);
      border-radius: 12px;
      cursor: pointer;
      margin-bottom: 0;
      background: #fafbfc;
      transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
      min-height: 0;
    }
    .game-card:hover {
      border-color: var(--accent2);
      background: #f8f7ff;
      transform: translateY(-2px);
      box-shadow: 0 8px 16px rgba(108, 92, 231, 0.12);
    }
    .game-card .ic {
      width: 40px; height: 40px;
      border-radius: 10px;
      display: grid; place-items: center;
      font-size: 1.25rem;
      flex-shrink: 0;
      margin-bottom: 0;
    }
    .game-card strong { font-size: 0.78rem; display: block; line-height: 1.2; }
    .game-card .desc { font-size: 0.68rem; color: var(--muted); line-height: 1.2; }
    .game-card .tag {
      margin-left: 0;
      margin-top: 2px;
      font-size: 0.62rem;
      font-weight: 700;
      padding: 2px 6px;
      border-radius: 999px;
      flex-shrink: 0;
    }
    .tag.easy { background: #e0fff6; color: #059669; }
    .tag.mid { background: #fff4e0; color: #d97706; }
    .tag.hard { background: #ffe0e6; color: #dc2626; }
    .modal-close {
      margin-top: 0;
      width: 100%;
      padding: 10px;
      border-radius: 10px;
      border: 1px solid var(--border);
      background: #f4f5f8;
      font-family: inherit;
      font-size: 0.95rem;
      font-weight: 600;
      cursor: pointer;
      flex-shrink: 0;
    }
    .modal-close:hover {
      background: #eef0f5;
      border-color: #c5cad6;
    }

    .help-modal {
      background: #fff;
      border-radius: 18px;
      width: min(640px, 94vw);
      max-height: 88vh;
      overflow-y: auto;
      padding: 22px 26px;
      box-shadow: 0 24px 60px rgba(0,0,0,0.25);
    }
    .help-modal h3 { font-size: 1.35rem; margin-bottom: 4px; }
    .help-modal > p { color: var(--muted); margin-bottom: 16px; font-size: 1rem; }
    .help-cat {
      margin-bottom: 14px;
      border: 1px solid var(--border);
      border-radius: 12px;
      overflow: hidden;
    }
    .help-cat-head {
      padding: 11px 13px;
      font-weight: 700;
      font-size: 1.02rem;
      display: flex;
      align-items: center;
      gap: 10px;
      color: #fff;
    }
    .help-cat-body { padding: 11px 13px; background: #fafbfc; }
    .help-cat-body p { margin: 0 0 7px; font-size: 0.96rem; line-height: 1.45; color: var(--text); }
    .help-cat-body p:last-child { margin-bottom: 0; }
    .help-cat-body code {
      font-family: 'JetBrains Mono', monospace;
      font-size: 0.86rem;
      background: #eef0f5;
      padding: 2px 6px;
      border-radius: 4px;
      color: var(--accent2);
    }
    .help-cat.game .help-cat-head { background: var(--b-game); }
    .help-cat.vars .help-cat-head { background: var(--b-var); }
    .help-cat.draw .help-cat-head { background: var(--b-draw); }
    .help-cat.move .help-cat-head { background: var(--b-move); color: #1a1000; }
    .help-cat.event .help-cat-head { background: var(--b-event); }
    .help-cat.ctrl .help-cat-head { background: var(--b-ctrl); }
    .help-cat.loop .help-cat-head { background: var(--b-loop); }
    .help-cat.func .help-cat-head { background: var(--b-func); }
    .help-cat.score .help-cat-head { background: var(--b-score); }

    .hover-popup {
      position: fixed;
      z-index: 200;
      background: #fff;
      border: 2px solid var(--border);
      border-radius: 14px;
      box-shadow: 0 16px 36px rgba(0,0,0,0.2);
      padding: 12px;
      display: none;
    }
    .hover-popup.show { display: block; }
    .calc-popup { width: 210px; }
    .calc-display {
      background: #f4f5f8;
      border-radius: 8px;
      padding: 10px 12px;
      font-family: 'JetBrains Mono', monospace;
      font-size: 1.25rem;
      text-align: right;
      margin-bottom: 8px;
      color: var(--text);
    }
    .calc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .calc-grid button {
      padding: 10px 0;
      border: none;
      border-radius: 8px;
      background: #f0eefc;
      font-family: 'JetBrains Mono', monospace;
      font-size: 1.05rem;
      font-weight: 700;
      cursor: pointer;
      color: var(--accent2);
    }
    .calc-grid button:hover { background: #e2ddfc; }
    .calc-grid button.wide { grid-column: span 3; background: var(--accent2); color: #fff; }
    .calc-grid button.wide:hover { filter: brightness(1.08); background: var(--accent2); }

    .color-popup { width: 240px; }
    .color-current {
      display: flex; align-items: center; gap: 10px;
      margin-bottom: 10px;
      font-family: 'JetBrains Mono', monospace;
      font-size: 0.9rem;
      color: var(--muted);
    }
    .color-current .cur-swatch {
      width: 32px; height: 32px; border-radius: 8px;
      border: 2px solid var(--border);
      flex-shrink: 0;
    }
    .color-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
    .color-grid .swatch {
      width: 30px; height: 30px;
      border-radius: 8px;
      cursor: pointer;
      border: 2px solid #fff;
      box-shadow: 0 0 0 1px var(--border);
      transition: transform 0.1s;
    }
    .color-grid .swatch:hover { transform: scale(1.15); }
    .color-popup .popup-title {
      font-size: 0.82rem; font-weight: 700; color: var(--muted);
      margin-bottom: 8px;
    }

    .choice-popup { width: 260px; max-height: 320px; overflow-y: auto; }
    .choice-popup .popup-title {
      font-size: 0.85rem; font-weight: 700; color: var(--text);
      margin-bottom: 10px;
    }
    .choice-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 8px;
    }
    .choice-chip {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 4px;
      padding: 10px 6px;
      border-radius: 12px;
      border: 2px solid var(--border);
      background: #fafbfc;
      cursor: pointer;
      font-family: inherit;
      font-size: 0.78rem;
      font-weight: 700;
      color: var(--text);
      transition: border-color 0.12s, transform 0.1s, background 0.12s;
    }
    .choice-chip:hover {
      border-color: var(--accent2);
      background: #f0eefc;
      transform: translateY(-2px);
    }
    .choice-chip.active {
      border-color: var(--accent2);
      background: #f0eefc;
      box-shadow: 0 0 0 2px rgba(108,92,231,0.2);
    }
    .choice-chip .chip-icon {
      font-size: 1.45rem;
      line-height: 1;
    }
    .choice-chip .chip-label {
      font-size: 0.72rem;
      color: var(--muted);
      font-weight: 600;
    }




    /* Confetti */
    .confetti-piece {
      position: fixed;
      width: 10px; height: 10px;
      top: -10px;
      z-index: 999;
      pointer-events: none;
      animation: confetti-fall 2.2s ease-out forwards;
    }
    @keyframes confetti-fall {
      0% { transform: translateY(0) rotate(0deg); opacity: 1; }
      100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
    }
