  @import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

  :root {
    --font-retro: "VT323", monospace;
    --gba-body: #40366b;
    --gba-body-dark: #2e2247;
    --gba-body-lite: #5b4e94;
    --gba-shell: #35285a;
    --gba-shell-lite: #655a93;
    --gba-screen-bg: #171722;
    --gba-screen-bezel: #0c0d12;
    --gba-panel: #231a3f;
    --gba-panel-lite: #312455;
    --gba-lcd: #d9ebbc;
    --gba-lcd-dark: #7f9363;
    --gba-line: #6f62a8;
    --gba-line-dark: #201733;
    --gba-accent: #58d7d6;
    --gba-gold: #e6c56f;
    --text: #f5f1ff;
    --muted: #cdc1ef;
    --ok: #89f0b3;
    --err: #ff9b9b;
    --shadow: rgba(0, 0, 0, 0.46);
  }

  *,
  *::before,
  *::after {
    box-sizing: border-box;
    font-family: var(--font-retro);
  }
  html, body { margin: 0; }
  body {
    background-color: var(--gba-body);
    background-image:
      radial-gradient(circle at top, rgba(120, 106, 192, 0.45), transparent 30%),
      linear-gradient(180deg, #51448b 0%, #40366b 32%, #34295a 100%),
      linear-gradient(135deg, var(--gba-body) 25%, transparent 25%),
      linear-gradient(225deg, var(--gba-body) 25%, transparent 25%),
      linear-gradient(45deg, var(--gba-body) 25%, transparent 25%),
      linear-gradient(315deg, var(--gba-body) 25%, var(--gba-body-lite) 25%);
    background-size: cover, cover, 4px 4px, 4px 4px, 4px 4px, 4px 4px;
    color: var(--text);
    min-height: 100vh;
    padding: 16px;
    font-size: 22px;
    letter-spacing: 0.02em;
  }

  .app {
    width: min(1280px, 100%);
    margin: 0 auto;
    position: relative;
    background:
      linear-gradient(180deg, rgba(96, 84, 146, 0.94), rgba(48, 38, 82, 0.96) 20%, rgba(35, 26, 63, 0.98));
    border: 4px solid var(--gba-line-dark);
    border-radius: 24px 24px 56px 24px;
    padding: 16px;
    box-shadow:
      inset 0 2px 0 rgba(255, 255, 255, 0.1),
      inset 0 -16px 26px rgba(0, 0, 0, 0.34),
      0 18px 36px var(--shadow);
  }

  .app::before {
    content: "";
    position: absolute;
    inset: 10px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px 16px 46px 16px;
    pointer-events: none;
  }

  h1 {
    margin: 0 0 2px;
    font-size: 38px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #f4f2ff;
    font-style: regular;
    text-shadow: 3px 3px 0 #000;
  }
  h1::before {
    content: 'GBA';
    color: var(--gba-gold);
  }

  .subtitle {
    margin: 8px 0 14px;
    color: var(--muted);
    font-size: 24px;
  }

a {
    margin: 8px 0 14px;
    color: var(--muted);
    font-size: 24px;

}

  .topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
  }

  .btn,
  .tab-btn,
  button,
  input,
  select,
  textarea,
  code {
    font: inherit;
  }

  .btn,
  .tab-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: linear-gradient(180deg, #7a6ab7, #51407e);
    border: 2px solid #191327;
    border-bottom-width: 5px;
    color: var(--text);
    padding: 9px 14px 7px;
    border-radius: 999px;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-shadow: 1px 1px 0 #000;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.14),
      0 5px 0 rgba(0, 0, 0, 0.28);
    transition: transform 0.08s ease, filter 0.08s ease;
  }

  .btn:hover,
  .tab-btn:hover { filter: brightness(1.08); }
  .btn:active,
  .tab-btn:active {
    transform: translateY(2px);
    border-bottom-width: 3px;
  }
  .btn:disabled { opacity: 0.45; cursor: not-allowed; }
  .btn.disabled,
  .tab-btn.disabled {
    opacity: 0.45;
    pointer-events: none;
  }

  .btn.primary {
    background: linear-gradient(180deg, #6de7da, #2e8c98);
    color: #081016;
    text-shadow: none;
  }

  .btn.gold {
    background: linear-gradient(180deg, #f2dc8a, #a97f24);
    color: #23160a;
    text-shadow: none;
  }

  .btn.danger {
    background: linear-gradient(180deg, #e88a8a, #913f4c);
    color: #fff4f7;
  }

  input[type=file] { display: none; }
  label.btn { display: inline-flex; align-items: center; }

  .start-screen {
    width: min(760px, 100%);
    margin: 0 auto;
    background: linear-gradient(180deg, rgba(89, 74, 141, 0.96), rgba(36, 27, 64, 0.98));
    border: 4px solid #181122;
    border-radius: 26px 26px 52px 26px;
    padding: 22px 20px 24px;
    box-shadow:
      inset 0 2px 0 rgba(255,255,255,0.08),
      inset 0 -12px 20px rgba(0,0,0,0.28),
      0 14px 30px var(--shadow);
    text-align: center;
  }

  .start-shell {
    min-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
  }

  .start-title {
    margin: 0;
    font-size: 40px;
    letter-spacing: 0.05em;
    color: #fff6d7;
    text-shadow: 3px 3px 0 #000;
  }

  .start-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
  }

  .btn.big {
    min-width: 238px;
    padding: 12px 16px 10px;
    font-size: 28px;
  }

  .rom-download {
    display: inline-flex;
    min-width: min(100%, 360px);
  }

  .drop-zone {
    margin-top: 18px;
    border: 3px dashed #9c8ad0;
    border-radius: 18px;
    padding: 28px 12px;
    background: linear-gradient(180deg, rgba(20, 15, 36, 0.98), rgba(38, 30, 66, 0.98));
    color: #e6dcff;
    font-size: 30px;
    transition: 0.12s ease-in-out;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.04);
  }

  .drop-zone.over {
    background: linear-gradient(180deg, #2f2552, #463777);
    border-color: #ffe07e;
    color: #fff4c7;
    transform: scale(1.01);
  }

  .tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
  }

  .tab-btn {
    min-width: 140px;
  }

  .tab-btn.active {
    background: linear-gradient(180deg, #d7f3d7, #94b07f);
    color: #18230d;
    text-shadow: none;
  }

  .panel {
    background: linear-gradient(180deg, rgba(39, 29, 68, 0.98), rgba(22, 16, 38, 0.98));
    border: 3px solid var(--gba-line-dark);
    border-radius: 20px;
    padding: 14px;
    box-shadow:
      inset 0 1px 0 rgba(255,255,255,0.06),
      0 8px 20px var(--shadow);
  }

  .format-info {
    font-size: 18px;
    color: var(--muted);
    margin-bottom: 12px;
    line-height: 1.5;
  }

  .format-info strong { color: #d7e2ff; }

  .slots-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(720px, 1fr));
    gap: 10px;
  }

  .slot-card {
    border: 2px solid #14101d;
    border-radius: 18px;
    overflow: hidden;
    background: linear-gradient(180deg, #22213c, #16182c);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
  }

  .slot-card.empty-slot { opacity: 0.7; }

  .slot-header {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    background: linear-gradient(180deg, #34457a, #202e57);
    border-bottom: 2px solid #12182b;
  }

  .slot-num {
    min-width: 36px;
    text-align: center;
    border-radius: 999px;
    background: linear-gradient(180deg, #1d1f2a, #090a0e);
    color: var(--gba-gold);
    font-weight: 700;
    padding: 6px 8px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
  }

  .slot-name-input {
    flex: 1;
    background: linear-gradient(180deg, #dce9b3, #b9ca89);
    border: 2px solid #2b301d;
    color: #1b2311;
    border-radius: 10px;
    padding: 6px 10px;
    font-size: 24px;
    text-transform: uppercase;
    box-shadow: inset 0 2px 0 rgba(255,255,255,0.18);
  }

  .slot-name-input:focus { outline: none; border-color: var(--gba-accent); }

  .slot-badge {
    font-size: 18px;
    padding: 5px 10px;
    border-radius: 999px;
    text-transform: uppercase;
  }

  .badge-used {
    background: #224933;
    color: #abffd0;
    border: 1px solid #3a8460;
  }

  .badge-empty {
    background: #3b2d35;
    color: #d8b0c0;
    border: 1px solid #6a4a58;
  }

  .slot-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 8px 12px;
    background: #111528;
    border-bottom: 1px solid #202947;
    flex-wrap: wrap;
    font-size: 20px;
    color: var(--muted);
  }

  .slot-meta select {
    background: linear-gradient(180deg, #dce9b3, #b9ca89);
    color: #1b2311;
    border: 2px solid #2b301d;
    border-radius: 9px;
    padding: 5px 8px;
    font-size: 22px;
  }

  .slot-preview {
    display: flex;
    gap: 10px;
    padding: 8px 10px;
    align-items: flex-start;
  }

  .preview-wrap { display: flex; flex-direction: column; gap: 6px; }
  .preview-label { font-size: 18px; color: var(--muted); }

  canvas.level-preview {
    display: block;
    image-rendering: pixelated;
    border: 1px solid #3a4875;
    background: #0c1225;
  }

  .legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-width: 190px;
  }

  .legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 16px;
    color: #a7b4e0;
    background: #141c34;
    border: 1px solid #2f3a63;
    border-radius: 999px;
    padding: 2px 7px;
  }

  .legend-swatch {
    width: 8px;
    height: 8px;
    border: 1px solid #111;
    border-radius: 2px;
  }

  .slot-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 8px 10px;
    border-top: 1px solid #2a3559;
    background: #0f1529;
  }

  .texture-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 14px;
  }

  .pack-list {
    border: 3px solid #121118;
    border-radius: 18px;
    background: linear-gradient(180deg, #171826, #10111a);
    min-height: 260px;
    max-height: 470px;
    overflow-y: auto;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04);
  }

  .pack-item {
    border-bottom: 1px solid #24293d;
    padding: 10px 12px;
    cursor: pointer;
  }

  .pack-item:last-child { border-bottom: 0; }
  .pack-item:hover { background: #21263a; }
  .pack-item.active {
    background: linear-gradient(180deg, #dce9b3, #a4b576);
    color: #14180c;
  }

  .pack-name {
    font-size: 24px;
    color: #ecf1ff;
    line-height: 1.2;
    margin-bottom: 2px;
    word-break: break-word;
  }

  .pack-meta {
    font-size: 17px;
    color: var(--muted);
  }

  .pack-item.active .pack-name,
  .pack-item.active .pack-meta {
    color: #15180d;
  }

  .small-note {
    margin-top: 8px;
    font-size: 18px;
    color: var(--muted);
    line-height: 1.4;
  }

  .pack-buttons {
    margin-top: 10px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }

  .editor-grid {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 14px;
  }

  .editor-main,
  .editor-side {
    border: 3px solid var(--gba-screen-bezel);
    border-radius: 20px 20px 38px 20px;
    padding: 12px;
    background:
      linear-gradient(180deg, #151821, #0f1118 26%, #171a24 100%);
    box-shadow:
      inset 0 1px 0 rgba(255,255,255,0.05),
      inset 0 0 0 2px rgba(255,255,255,0.03);
  }

  .field {
    margin-bottom: 10px;
  }

  .field label {
    display: block;
    font-size: 20px;
    color: #edf7cf;
    margin-bottom: 6px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .field input[type=text],
  .field select,
  .field input[type=range] {
    width: 100%;
  }

  .field input[type=text],
  .field select {
    background: linear-gradient(180deg, var(--gba-lcd), #b9c98a);
    color: #16200e;
    border: 2px solid #2a311d;
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 24px;
    box-shadow: inset 0 2px 0 rgba(255,255,255,0.15);
  }

  .asset-wrap {
    border: 4px solid var(--gba-screen-bezel);
    border-radius: 18px 18px 34px 18px;
    background:
      radial-gradient(circle at top, rgba(255,255,255,0.04), transparent 30%),
      linear-gradient(180deg, #0d1118, #06070a);
    padding: 14px;
    display: inline-block;
    box-shadow:
      inset 0 0 0 2px rgba(255,255,255,0.03),
      inset 0 0 22px rgba(0,0,0,0.58);
  }

  #asset-canvas {
    display: block;
    image-rendering: pixelated;
    background:
      linear-gradient(45deg, #2f3658 25%, transparent 25%),
      linear-gradient(-45deg, #2f3658 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #2f3658 75%),
      linear-gradient(-45deg, transparent 75%, #2f3658 75%);
    background-size: 14px 14px;
    background-position: 0 0, 0 7px, 7px -7px, -7px 0;
    border: 3px solid #495375;
    cursor: crosshair;
    box-shadow: 0 0 0 2px #000;
  }

  .asset-actions {
    margin-top: 12px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }

  .asset-actions .btn {
    flex: 1;
    min-width: 120px;
  }

  .palette-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
  }

  .swatch {
    height: 26px;
    border: 1px solid #1a1f34;
    border-radius: 5px;
    cursor: pointer;
    position: relative;
  }

  .swatch.active {
    outline: 3px solid #ffe27a;
    outline-offset: 1px;
  }

  .swatch .idx {
    position: absolute;
    right: 2px;
    bottom: 1px;
    font-size: 14px;
    color: #fff;
    text-shadow: 0 1px 2px #000;
  }

  .rgb-row {
    display: grid;
    grid-template-columns: 22px 1fr 36px;
    gap: 6px;
    align-items: center;
    margin-top: 7px;
    font-size: 18px;
    color: var(--muted);
  }

  .rgb-row input[type=range],
  #zoom-range {
    accent-color: var(--gba-accent);
  }

  .image-tools {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 2px solid rgba(255,255,255,0.08);
  }

  .image-tools.hidden {
    display: none;
  }

  .image-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin: 10px 0 12px;
  }

  .image-actions .btn {
    width: 100%;
    min-width: 0;
    font-size: 20px;
    padding-inline: 10px;
  }

  .image-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 10px;
  }

  .image-grid label {
    margin-bottom: 4px;
    font-size: 18px;
  }

  .image-grid input[type=number] {
    width: 100%;
    background: linear-gradient(180deg, var(--gba-lcd), #b9c98a);
    color: #16200e;
    border: 2px solid #2a311d;
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 22px;
    box-shadow: inset 0 2px 0 rgba(255,255,255,0.15);
  }

  .image-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 18px;
  }

  .image-toggles label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    text-transform: none;
    letter-spacing: 0.02em;
    color: var(--muted);
  }

  .image-commit {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .image-commit .btn {
    flex: 1;
    min-width: 120px;
  }

  .status {
    margin-top: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 20px;
    display: none;
  }

  .status.ok { display: block; color: #d4ffe5; background: #174c33; border: 1px solid #2f8a5e; }
  .status.err { display: block; color: #ffd7d7; background: #592727; border: 1px solid #9f4d4d; }
  .status.info { display: block; color: #dbe6ff; background: #26396b; border: 1px solid #4d6cc1; }

  .hidden { display: none !important; }

  @media (max-width: 1100px) {
    .slots-grid { grid-template-columns: 1fr; }
    .texture-layout { grid-template-columns: 1fr; }
    .editor-grid { grid-template-columns: 1fr; }
  }
