:root {
        color-scheme: light dark;
        --bg: #0b0b1e;
        --bg2: #12122e;
        --panel: #1a1a3e;
        --panel2: #232355;
        --ink: #e8e8f8;
        --ink-dim: #9a9ac8;
        --line: #e8e8f8;
        --accent: #ffd23f;
        --accent2: #3ee06f;
        --accent3: #ff5470;
        --sky: #38b6ff;
        --shadow: #05050f;
        --bar-track: #2b2b57;
        --scan: rgba(0, 0, 0, 0.14);
        --star: #2c2c66;
      }
      @media (prefers-color-scheme: light) {
        :root {
          --bg: #7ec8f7;
          --bg2: #a5dcff;
          --panel: #fdfdf5;
          --panel2: #e9f4d8;
          --ink: #20203c;
          --ink-dim: #55557a;
          --line: #20203c;
          --accent: #e8a400;
          --accent2: #1d9e4b;
          --accent3: #d92b4f;
          --sky: #1b7fd4;
          --shadow: #20203c;
          --bar-track: #cfd8ec;
          --scan: rgba(255, 255, 255, 0.10);
        }
      }

      * { box-sizing: border-box; }
      html { scroll-behavior: smooth; }
      body {
        margin: 0;
        background: var(--bg);
        color: var(--ink);
        font-family: "VT323", "Courier New", monospace;
        font-size: 21px;
        line-height: 1.45;
        overflow-x: hidden;
      }
      h1, h2, h3, .px {
        font-family: "Press Start 2P", monospace;
        font-weight: 400;
        line-height: 1.5;
      }

      /* ---------- pixel frame helper ---------- */
      .frame {
        background: var(--panel);
        border: 4px solid var(--line);
        box-shadow:
          0 4px 0 0 var(--shadow),
          inset -4px -4px 0 0 rgba(0,0,0,0.18),
          inset 4px 4px 0 0 rgba(255,255,255,0.10);
      }
      .frame-inset {
        background: var(--panel2);
        border: 3px solid var(--line);
        box-shadow: inset 3px 3px 0 0 rgba(0,0,0,0.22);
      }

      /* ---------- background decor ---------- */
      .stars {
        position: fixed; inset: 0; z-index: 0; pointer-events: none;
        background-image:
          radial-gradient(2px 2px at 12% 18%, var(--ink) 50%, transparent 51%),
          radial-gradient(2px 2px at 78% 8%, var(--ink) 50%, transparent 51%),
          radial-gradient(3px 3px at 34% 30%, var(--ink) 50%, transparent 51%),
          radial-gradient(2px 2px at 58% 14%, var(--ink) 50%, transparent 51%),
          radial-gradient(2px 2px at 90% 34%, var(--ink) 50%, transparent 51%),
          radial-gradient(3px 3px at 6% 46%, var(--ink) 50%, transparent 51%),
          radial-gradient(2px 2px at 45% 52%, var(--ink) 50%, transparent 51%),
          radial-gradient(2px 2px at 70% 62%, var(--ink) 50%, transparent 51%),
          radial-gradient(3px 3px at 24% 72%, var(--ink) 50%, transparent 51%),
          radial-gradient(2px 2px at 84% 84%, var(--ink) 50%, transparent 51%);
        opacity: 0.35;
      }
      .scanlines {
        position: fixed; inset: 0; z-index: 60; pointer-events: none;
        background: repeating-linear-gradient(to bottom, transparent 0 3px, var(--scan) 3px 4px);
        mix-blend-mode: multiply;
      }
      .ground {
        position: fixed; left: 0; right: 0; bottom: 0; height: 26px; z-index: 0; pointer-events: none;
        background:
          repeating-linear-gradient(to right, transparent 0 22px, rgba(0,0,0,0.25) 22px 26px),
          linear-gradient(to bottom, var(--accent2), var(--accent2));
        border-top: 4px solid var(--line);
        opacity: 0.85;
      }

      main { position: relative; z-index: 1; max-width: 1060px; margin: 0 auto; padding: 0 16px 90px; }
      section { scroll-margin-top: 92px; margin-top: 64px; }

      /* ---------- HUD top bar ---------- */
      .hud {
        position: sticky; top: 0; z-index: 50;
        background: var(--bg2);
        border-bottom: 4px solid var(--line);
      }
      .hud-inner {
        max-width: 1060px; margin: 0 auto; padding: 10px 16px;
        display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
      }
      .hud .player-tag { font-family: "Press Start 2P", monospace; font-size: 10px; color: var(--accent); }
      .hud nav { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
      .hud nav a {
        font-family: "Press Start 2P", monospace; font-size: 9px;
        color: var(--ink); text-decoration: none; padding: 8px 10px;
        border: 3px solid transparent;
      }
      .hud nav a:hover, .hud nav a:focus-visible { border-color: var(--line); background: var(--panel); color: var(--accent); }
      .hud .coins { font-family: "Press Start 2P", monospace; font-size: 10px; color: var(--accent); white-space: nowrap; }
      .coin-ico { display: inline-block; width: 12px; height: 12px; background: var(--accent); border: 2px solid var(--line); vertical-align: -1px; margin-right: 6px; animation: coinspin 1.6s steps(4) infinite; }
      @keyframes coinspin { 0% { transform: scaleX(1); } 50% { transform: scaleX(0.25); } 100% { transform: scaleX(1); } }

      /* ---------- START SCREEN ---------- */
      .start-screen {
        min-height: calc(100svh - 60px);
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        text-align: center; padding: 48px 12px 70px; position: relative;
      }
      .start-screen .insert {
        font-family: "Press Start 2P", monospace; font-size: 10px; letter-spacing: 2px; color: var(--ink-dim);
      }
      .game-title {
        font-size: clamp(26px, 7vw, 54px);
        color: var(--accent);
        text-shadow: 4px 4px 0 var(--accent3), 8px 8px 0 var(--shadow);
        margin: 22px 0 6px;
      }
      .game-sub {
        font-family: "Press Start 2P", monospace; font-size: clamp(9px, 2.4vw, 13px);
        color: var(--sky); margin: 10px 0 4px;
      }
      .hero-sprite { margin: 26px auto 8px; image-rendering: pixelated; }
      .btn-start {
        margin-top: 30px;
        font-family: "Press Start 2P", monospace; font-size: clamp(12px, 3vw, 16px);
        color: #20203c; background: var(--accent);
        border: 4px solid var(--line);
        padding: 16px 26px; cursor: pointer;
        box-shadow: 0 6px 0 0 var(--shadow);
        animation: blink 1.1s steps(2) infinite;
      }
      .btn-start:hover { background: var(--accent2); }
      .btn-start:active { transform: translateY(4px); box-shadow: 0 2px 0 0 var(--shadow); }
      @keyframes blink { 0%, 60% { opacity: 1; } 61%, 100% { opacity: 0.25; } }
      .start-note { margin-top: 20px; color: var(--ink-dim); font-size: 19px; }
      .start-note .arrow { color: var(--accent3); }

      /* ---------- section headers ---------- */
      .sec-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
      .sec-head .badge {
        font-family: "Press Start 2P", monospace; font-size: 10px;
        background: var(--accent3); color: #fff; border: 3px solid var(--line);
        padding: 7px 9px; box-shadow: 3px 3px 0 0 var(--shadow); white-space: nowrap;
      }
      .sec-head h2 { font-size: clamp(15px, 3.6vw, 22px); margin: 0; color: var(--ink); }
      .sec-head .rule { flex: 1; height: 4px; background: repeating-linear-gradient(to right, var(--line) 0 10px, transparent 10px 18px); opacity: 0.5; }

      /* ---------- PLAYER PROFILE ---------- */
      .profile-grid { display: grid; grid-template-columns: 300px 1fr; gap: 22px; }
      .avatar-box { padding: 18px; text-align: center; }
      .avatar-box .sprite-wrap {
        background: var(--star); border: 3px solid var(--line);
        padding: 18px 10px 10px; box-shadow: inset 3px 3px 0 rgba(0,0,0,0.3);
      }
      .avatar-box svg { image-rendering: pixelated; width: 128px; height: 128px; }
      .avatar-name { font-family: "Press Start 2P", monospace; font-size: 11px; margin-top: 14px; color: var(--accent); line-height: 1.7; }
      .avatar-class { color: var(--ink-dim); font-size: 19px; }
      .stat-list { padding: 18px 20px; }
      .stat-row { display: grid; grid-template-columns: 92px 1fr 74px; align-items: center; gap: 12px; margin: 13px 0; }
      .stat-row .lbl { font-family: "Press Start 2P", monospace; font-size: 10px; }
      .stat-row .val { font-family: "Press Start 2P", monospace; font-size: 10px; text-align: right; }
      .bar { height: 20px; background: var(--bar-track); border: 3px solid var(--line); position: relative; overflow: hidden; }
      .bar > i {
        display: block; height: 100%; width: 0%;
        background: repeating-linear-gradient(to right, rgba(255,255,255,0.22) 0 8px, transparent 8px 16px), var(--c, var(--accent2));
        transition: width 1.2s steps(24);
      }
      .bio { padding: 4px 20px 18px; }
      .bio p { margin: 10px 0; }
      .bio .hl { color: var(--accent); }
      .bio .hl2 { color: var(--sky); }
      .type-caret { display: inline-block; width: 10px; height: 18px; background: var(--accent); vertical-align: -2px; animation: blink 0.9s steps(2) infinite; }

      /* ---------- SKILL INVENTORY ---------- */
      .inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 18px; }
      .inv-item { padding: 16px; position: relative; }
      .inv-item .slot {
        width: 64px; height: 64px; margin-bottom: 12px;
        display: flex; align-items: center; justify-content: center;
        font-family: "Press Start 2P", monospace; font-size: 13px;
      }
      .inv-item h3 { font-size: 11px; margin: 0 0 8px; }
      .inv-item p { margin: 0 0 12px; color: var(--ink-dim); font-size: 19px; }
      .inv-item .lvl-row { display: flex; align-items: center; gap: 10px; }
      .inv-item .lvl-row .bar { flex: 1; height: 14px; }
      .inv-item .lvl-txt { font-family: "Press Start 2P", monospace; font-size: 9px; white-space: nowrap; }
      .rarity { position: absolute; top: 10px; right: 12px; font-size: 17px; letter-spacing: 1px; }
      .rarity .on { color: var(--accent); }
      .rarity .off { color: var(--ink-dim); opacity: 0.45; }

      /* ---------- QUESTS ---------- */
      .quest { padding: 20px; margin-bottom: 18px; }
      .quest-top { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
      .quest h3 { font-size: 12px; margin: 0; flex: 1; min-width: 220px; }
      .quest-status {
        font-family: "Press Start 2P", monospace; font-size: 8.5px; padding: 7px 8px;
        border: 3px solid var(--line); white-space: nowrap; box-shadow: 3px 3px 0 0 var(--shadow);
      }
      .st-done { background: var(--accent2); color: #0c2413; }
      .st-progress { background: var(--accent); color: #1c1cdd; }
      .quest p { color: var(--ink-dim); margin: 12px 0; }
      .quest-meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
      .chip {
        font-family: "Press Start 2P", monospace; font-size: 8.5px;
        border: 3px solid var(--line); padding: 6px 8px; background: var(--panel2); color: var(--ink);
      }
      .chip.reward { color: var(--accent); border-color: var(--accent); }
      .quest-link {
        margin-left: auto; font-family: "Press Start 2P", monospace; font-size: 9px;
        color: var(--sky); text-decoration: none; border-bottom: 3px solid var(--sky); padding-bottom: 2px;
      }
      .quest-link:hover { color: var(--accent); border-color: var(--accent); }

      /* ---------- ACHIEVEMENTS ---------- */
      .ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
      .ach { padding: 16px; display: flex; gap: 16px; align-items: flex-start; }
      .ach .medal {
        flex: 0 0 auto; width: 52px; height: 52px;
        display: flex; align-items: center; justify-content: center;
        font-family: "Press Start 2P", monospace; font-size: 15px;
      }
      .ach h3 { font-size: 10.5px; margin: 2px 0 8px; }
      .ach p { margin: 0; color: var(--ink-dim); font-size: 19px; }
      .ach .date { font-family: "Press Start 2P", monospace; font-size: 8px; color: var(--accent2); display: block; margin-top: 8px; }

      /* ---------- SAVE POINT / CONTACT ---------- */
      .save-wrap { padding: 26px 22px; text-align: center; }
      .save-crystal { margin: 4px auto 16px; width: 44px; height: 44px; animation: floaty 2.2s steps(6) infinite; }
      @keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
      .save-wrap h3 { font-size: 13px; margin: 0 0 10px; color: var(--accent); }
      .save-wrap p { color: var(--ink-dim); margin: 8px auto; max-width: 560px; }
      .save-mail {
        display: inline-block; margin: 14px 0 4px;
        font-family: "Press Start 2P", monospace; font-size: clamp(10px, 3vw, 14px);
        color: var(--sky); word-break: break-all;
      }
      .btn-save {
        display: inline-block; margin-top: 18px;
        font-family: "Press Start 2P", monospace; font-size: 12px;
        color: #0c2413; background: var(--accent2); text-decoration: none;
        border: 4px solid var(--line); padding: 15px 22px;
        box-shadow: 0 6px 0 0 var(--shadow); cursor: pointer;
      }
      .btn-save:hover { background: var(--accent); color: #20203c; }
      .btn-save:active { transform: translateY(4px); box-shadow: 0 2px 0 0 var(--shadow); }
      .social-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }
      .social-row a {
        font-family: "Press Start 2P", monospace; font-size: 9px; color: var(--ink);
        text-decoration: none; border: 3px solid var(--line); background: var(--panel2);
        padding: 10px 12px; box-shadow: 3px 3px 0 0 var(--shadow);
      }
      .social-row a:hover { color: var(--accent); }

      footer {
        position: relative; z-index: 1; text-align: center; padding: 30px 16px 60px;
        color: var(--ink-dim); font-size: 19px;
      }
      footer .px { font-size: 9px; color: var(--ink-dim); }

      /* sound toggle */
      .sound-btn {
        position: fixed; right: 14px; bottom: 40px; z-index: 70;
        width: 52px; height: 52px; cursor: pointer;
        font-family: "Press Start 2P", monospace; font-size: 13px;
        color: var(--ink); background: var(--panel);
        border: 4px solid var(--line); box-shadow: 0 4px 0 0 var(--shadow);
      }
      .sound-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 0 var(--shadow); }

      /* toast (game message box) */
      .toast {
        position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(24px);
        z-index: 80; max-width: min(92vw, 520px); width: max-content;
        padding: 14px 18px; opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s;
        font-size: 20px;
      }
      .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
      .toast .px { font-size: 9px; color: var(--accent); display: block; margin-bottom: 6px; }

      @media (max-width: 760px) {
        body { font-size: 20px; }
        .profile-grid { grid-template-columns: 1fr; }
        .stat-row { grid-template-columns: 70px 1fr 60px; gap: 8px; }
        .hud nav a { font-size: 8px; padding: 7px 7px; }
        .hud .player-tag { display: none; }
        .quest-link { margin-left: 0; }
      }
      @media (prefers-reduced-motion: reduce) {
        html { scroll-behavior: auto; }
        .btn-start, .coin-ico, .type-caret, .save-crystal { animation: none; }
        .bar > i { transition: none; }
      }
