
  :root {
    --bg: #080a14;
    --panel: rgba(14, 18, 34, 0.95);
    --vermilion: #e84838;
    --gold: #ffd24c;
    --jade: #3ce6a8;
    --cyan: #48dcff;
    --violet: #b678ff;
    --ink: #f5f2ea;
    --muted: #98a4c4;
    --font: 'Hiragino Sans', 'Yu Gothic UI', 'Meiryo', system-ui, -apple-system, sans-serif;
  }

  * {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    touch-action: none;
  }

  #error-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 9999;
    background: #8f1a24;
    color: #fff;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 800;
    display: none;
    white-space: pre-wrap;
    border-bottom: 2px solid var(--gold);
  }

  #app {
    position: relative;
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: radial-gradient(circle at 50% 25%, #181c36 0%, #070912 78%);
  }

  /* 上部コンパクト操作バー */
  #topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 5px 10px;
    background: linear-gradient(180deg, #16182e 0%, #0d0f20 100%);
    border-bottom: 2px solid var(--vermilion);
    z-index: 30;
    min-height: 44px;
  }

  .tb-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 900;
    letter-spacing: 0.05em;
    color: var(--gold);
    white-space: nowrap;
  }
  .tb-brand small {
    font-size: 10px;
    color: var(--muted);
    font-weight: 800;
  }

  .tb-hud-mini {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    font-weight: 900;
    white-space: nowrap;
  }
  .tb-pill {
    background: rgba(8, 11, 24, 0.85);
    border: 1px solid rgba(255, 210, 76, 0.35);
    padding: 2px 9px;
    border-radius: 999px;
    color: var(--ink);
  }
  .tb-pill strong { color: var(--gold); }

  .tb-controls {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
  }

  .tb-btn {
    border: 1.5px solid rgba(255, 255, 255, 0.22);
    background: rgba(22, 28, 52, 0.92);
    color: var(--ink);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
  }
  .tb-btn:active { transform: scale(0.95); }
  .tb-btn.on {
    background: rgba(60, 230, 168, 0.2);
    border-color: var(--jade);
    color: #dcfff2;
  }

  /* メイン 960x540 Canvas ステージ */
  #stage-wrap {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 6px;
  }

  #game-canvas {
    display: block;
    border-radius: 12px;
    box-shadow: 0 0 0 2px rgba(232, 72, 56, 0.42), 0 18px 48px rgba(0, 0, 0, 0.78);
    background: #0d1224;
  }

  /* オーバーレイ共通 */
  .overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: rgba(5, 7, 16, 0.84);
    backdrop-filter: blur(5px);
  }
  .overlay.show { display: flex; }

  .modal {
    width: min(96vw, 720px);
    max-height: 94dvh;
    overflow-y: auto;
    background: linear-gradient(180deg, #171b33 0%, #0d1022 100%);
    border: 2.5px solid var(--vermilion);
    border-radius: 18px;
    padding: 16px 20px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.86), 0 0 34px rgba(232, 72, 56, 0.22);
    display: flex;
    flex-direction: column;
    gap: 11px;
  }
  .modal.narrow { width: min(94vw, 470px); text-align: center; }

  .title-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
  }

  .title-badge {
    display: inline-block;
    padding: 2px 11px;
    border-radius: 999px;
    background: rgba(232, 72, 56, 0.18);
    border: 1px solid var(--vermilion);
    color: #ff9c8f;
    font-size: 10.5px;
    font-weight: 900;
    letter-spacing: 0.1em;
  }

  .title-top-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }

  /* ゲームパッド接続状態ピル（タイトル画面表示） */
  .pad-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 800;
    background: rgba(8, 12, 26, 0.85);
    border: 1px solid rgba(152, 164, 196, 0.35);
    color: var(--muted);
    transition: all 0.2s ease;
  }
  .pad-status.connected {
    background: rgba(60, 230, 168, 0.18);
    border-color: var(--jade);
    color: #dcfff2;
    box-shadow: 0 0 12px rgba(60, 230, 168, 0.35);
  }
  .pad-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
  }
  .pad-status.connected .pad-dot {
    background: var(--jade);
    box-shadow: 0 0 6px var(--jade);
  }

  .lang-switch {
    display: inline-flex;
    background: rgba(7, 10, 22, 0.88);
    border: 1.5px solid rgba(255, 210, 76, 0.5);
    border-radius: 999px;
    padding: 2px;
    gap: 2px;
    flex-shrink: 0;
  }
  .lang-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    padding: 4px 10px;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
  }
  .lang-btn.active {
    background: var(--gold);
    color: #0b0d18;
  }

  .title-head { text-align: center; }
  .title-logo {
    margin: 2px 0;
    font-size: clamp(26px, 5.2vw, 38px);
    font-weight: 900;
    letter-spacing: 0.06em;
    background: linear-gradient(180deg, #fff8e6 0%, #ffd24c 58%, #e84838 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
  .title-sub {
    margin: 0;
    font-size: 12px;
    color: var(--muted);
    font-weight: 700;
  }

  .sec-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 5px;
  }
  .sec-lbl {
    font-size: 12px;
    font-weight: 900;
    color: var(--gold);
    letter-spacing: 0.04em;
  }
  .coin-badge {
    font-size: 13px;
    font-weight: 900;
    color: var(--gold);
    background: rgba(255, 210, 76, 0.14);
    border: 1px solid rgba(255, 210, 76, 0.55);
    padding: 2px 10px;
    border-radius: 999px;
  }

  /* 永続アップグレードグリッド */
  .meta-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  .meta-card {
    background: rgba(9, 13, 28, 0.9);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 9px 8px;
    color: var(--ink);
    display: flex;
    flex-direction: column;
    gap: 5px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  }
  .meta-card:hover:not(:disabled) {
    transform: translateY(-2px);
    border-color: var(--gold);
    box-shadow: 0 0 14px rgba(255, 210, 76, 0.25);
  }
  .meta-card:disabled {
    opacity: 0.58;
    cursor: default;
  }
  .meta-ico { font-size: 22px; line-height: 1; }
  .meta-name { font-size: 12px; font-weight: 900; }
  .meta-desc { font-size: 10px; color: var(--muted); font-weight: 700; min-height: 24px; }
  .meta-pips {
    display: flex;
    justify-content: center;
    gap: 3px;
  }
  .pip {
    width: 11px;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.14);
  }
  .pip.on { background: var(--jade); box-shadow: 0 0 6px var(--jade); }
  .meta-cost {
    margin-top: 2px;
    font-size: 11px;
    font-weight: 900;
    color: var(--gold);
    background: rgba(255, 210, 76, 0.12);
    border-radius: 6px;
    padding: 3px 4px;
  }
  .meta-cost.max {
    color: var(--jade);
    background: rgba(60, 230, 168, 0.15);
  }

  .btn-start {
    border: none;
    border-radius: 12px;
    padding: 13px 22px;
    font-size: 17px;
    font-weight: 900;
    letter-spacing: 0.05em;
    color: #0b0d18;
    background: linear-gradient(135deg, #ffe270 0%, #ff8b3d 100%);
    box-shadow: 0 5px 0 #8a3812, 0 0 24px rgba(255, 174, 71, 0.45);
    cursor: pointer;
    width: 100%;
    transition: transform 0.1s ease, filter 0.15s ease;
  }
  .btn-start:hover { filter: brightness(1.06); }
  .btn-start:active { transform: translateY(2px); }

  .btn-share-x {
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    border-radius: 12px;
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 900;
    color: #ffffff;
    background: linear-gradient(135deg, #11141c 0%, #22293a 100%);
    box-shadow: 0 4px 0 #06080e;
    cursor: pointer;
    width: 100%;
  }
  .btn-share-x:hover { border-color: var(--cyan); }
  .btn-share-x:active { transform: translateY(2px); }

  .btn-sub {
    border: 1.5px solid rgba(255, 255, 255, 0.26);
    background: rgba(16, 22, 44, 0.92);
    color: var(--ink);
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    width: 100%;
  }

  .studio-link-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 13px;
    border-radius: 12px;
    background: rgba(8, 12, 26, 0.88);
    border: 1px solid rgba(255, 210, 76, 0.38);
    color: var(--ink);
    text-decoration: none;
    font-size: 12px;
    font-weight: 800;
    text-align: left;
  }
  .studio-link-card:hover {
    border-color: var(--gold);
    background: rgba(20, 26, 52, 0.94);
  }
  .studio-link-sub {
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: var(--muted);
    margin-top: 1px;
  }
  .studio-link-arrow {
    color: var(--gold);
    font-size: 14px;
    font-weight: 900;
    flex-shrink: 0;
  }

  .ctrl-guide {
    background: rgba(8, 11, 22, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--muted);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 12px;
  }
  .ctrl-guide strong { color: var(--ink); }

  /* レベルアップ3択 */
  .lvl-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }
  .lvl-card {
    background: linear-gradient(180deg, #1d2342 0%, #101429 100%);
    border: 2px solid rgba(255, 210, 76, 0.42);
    border-radius: 14px;
    padding: 14px 10px;
    color: var(--ink);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    transition: transform 0.14s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  }
  .lvl-card:hover, .lvl-card.sel {
    transform: translateY(-4px);
    border-color: var(--gold);
    box-shadow: 0 0 22px rgba(255, 210, 76, 0.45);
  }
  .lvl-tag {
    font-size: 10px;
    font-weight: 900;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(72, 220, 255, 0.18);
    color: var(--cyan);
    border: 1px solid rgba(72, 220, 255, 0.5);
  }
  .lvl-tag.new {
    background: rgba(232, 72, 56, 0.22);
    color: #ff9c8f;
    border-color: var(--vermilion);
  }
  .lvl-tag.passive {
    background: rgba(60, 230, 168, 0.18);
    color: var(--jade);
    border-color: var(--jade);
  }
  .lvl-ico { font-size: 36px; line-height: 1; }
  .lvl-name { font-size: 14px; font-weight: 900; color: #fff; }
  .lvl-lv { font-size: 11px; font-weight: 900; color: var(--gold); }
  .lvl-desc { font-size: 11.5px; color: #c7d6f5; line-height: 1.4; }

  /* リザルト */
  .res-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .res-box {
    background: rgba(8, 12, 24, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 10px;
    padding: 8px 6px;
  }
  .res-lbl { font-size: 10px; color: var(--muted); font-weight: 800; }
  .res-val { font-size: 17px; font-weight: 900; color: var(--gold); margin-top: 2px; }

  @media (max-width: 700px) {
    .meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .lvl-grid { grid-template-columns: 1fr; }
    .lvl-card { flex-direction: row; text-align: left; padding: 11px 12px; gap: 11px; }
    .lvl-ico { font-size: 30px; flex-shrink: 0; }
    .ctrl-guide { grid-template-columns: 1fr; }
    .tb-hud-mini { display: none; }
  }
