  * { margin: 0; padding: 0; box-sizing: border-box; }
  html, body {
    width: 100%; height: 100%; overflow: hidden;
    background: #1a0f0a;
    font-family: 'Trebuchet MS', sans-serif;
    color: #f0e0c0;
  }
  #wrap {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle at center, #2b1810 0%, #0a0503 100%);
  }
  #stage {
    position: relative;
    width: min(100vw, 100vh * 16 / 9);
    height: min(100vh, 100vw * 9 / 16);
    box-shadow: 0 0 60px rgba(0,0,0,0.8);
    background: #000;
    overflow: hidden;
  }
  /* Portrait mobile: stage fills the whole screen */
  @media (orientation: portrait) and (max-width: 900px) {
    #stage {
      width: 100vw;
      height: 100vh;
      box-shadow: none;
    }
  }
  canvas { display: block; width: 100%; height: 100%; image-rendering: -webkit-optimize-contrast; touch-action: none; }

  /* HUD */
  #hud {
    position: absolute; top: 0; left: 0; right: 0;
    padding: 12px 18px;
    display: flex; justify-content: space-between; align-items: center;
    pointer-events: none;
    font-weight: bold;
    text-shadow: 2px 2px 4px #000;
    z-index: 5;
  }
  @media (orientation: portrait) and (max-width: 900px) {
    #hud { padding: 10px 10px; flex-wrap: wrap; gap: 6px; }
    .stat { font-size: 14px; padding: 3px 8px; min-width: 50px; }
    .stat-icon { width: 18px; height: 18px; }
    .heart { width: 22px; height: 22px; }
    .hud-group { gap: 6px; }
  }
  .hud-group { display: flex; align-items: center; gap: 14px; }
  .hp-bar {
    display: flex; gap: 4px;
  }
  .heart {
    width: 28px; height: 28px;
    object-fit: contain;
    image-rendering: pixelated;
    transition: opacity 0.2s, transform 0.2s, filter 0.2s;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.5));
  }
  .heart.empty { opacity: 0.3; transform: scale(0.85); filter: grayscale(1) brightness(0.5); }
  .stat {
    background: rgba(0,0,0,0.55);
    border: 2px solid #d4a857;
    border-radius: 8px;
    padding: 4px 10px;
    display: flex; align-items: center; gap: 8px;
    color: #ffd96b;
    font-size: 18px;
    min-width: 60px;
  }
  .stat-icon { width: 22px; height: 22px; }

  /* Overlays */
  .overlay {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.78);
    backdrop-filter: blur(4px);
    z-index: 10;
    text-align: center;
    padding: 20px;
  }
  .overlay.hidden { display: none; }
  .overlay h1 {
    font-size: clamp(28px, 5vw, 56px);
    color: #ffd96b;
    text-shadow: 3px 3px 0 #4a1a0c, 6px 6px 12px #000;
    margin-bottom: 16px;
    letter-spacing: 2px;
  }
  .overlay h2 {
    font-size: clamp(22px, 3.5vw, 36px);
    color: #ffeead;
    margin-bottom: 24px;
  }
  .overlay p {
    font-size: clamp(14px, 1.8vw, 18px);
    color: #d8c89a;
    max-width: 500px;
    line-height: 1.6;
    margin-bottom: 12px;
  }
  .controls-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px 18px;
    margin: 20px 0;
    font-size: clamp(14px, 1.8vw, 16px);
  }
  .key {
    display: inline-block;
    background: linear-gradient(180deg, #5a3825 0%, #3d2515 100%);
    border: 2px solid #d4a857;
    border-radius: 6px;
    padding: 4px 12px;
    color: #ffd96b;
    font-weight: bold;
    min-width: 80px;
    text-align: center;
    box-shadow: 0 3px 0 #1d0e07;
  }
  button.btn {
    background: linear-gradient(180deg, #c8851f 0%, #8a4f10 100%);
    border: 3px solid #ffd96b;
    border-radius: 12px;
    color: #fff;
    font-size: clamp(18px, 2.5vw, 24px);
    font-weight: bold;
    padding: 12px 36px;
    cursor: pointer;
    margin-top: 16px;
    text-shadow: 2px 2px 0 #000;
    box-shadow: 0 6px 0 #4a1a0c, 0 8px 16px rgba(0,0,0,0.6);
    transition: transform 0.1s, box-shadow 0.1s;
    letter-spacing: 1px;
  }
  button.btn:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #4a1a0c, 0 10px 20px rgba(0,0,0,0.7); }
  button.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #4a1a0c; }
  button.btn.small { font-size: 16px; padding: 8px 18px; margin: 4px; box-shadow: 0 4px 0 #4a1a0c; }
  button.btn.small:active { transform: translateY(2px); box-shadow: 0 2px 0 #4a1a0c; }
  button.btn.primary { background: linear-gradient(180deg, #d8a032 0%, #9a5a14 100%); }
  button.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.7); }

  .menu-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
  .menu-row.small { margin-top: 6px; }

  .badge {
    display: inline-block;
    background: #ff4444;
    color: #fff;
    font-size: 11px;
    border-radius: 10px;
    padding: 1px 7px;
    margin-left: 4px;
    font-weight: bold;
  }
  .badge:empty { display: none; }

  .profile-strip {
    display: flex; gap: 16px; flex-wrap: wrap; justify-content: center;
    background: rgba(0,0,0,0.4);
    border: 1px solid #5a3825;
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 15px;
    color: #ffd96b;
    margin: 8px 0 12px;
  }

  /* Shop grid */
  .shop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    width: 100%;
    max-width: 720px;
    margin: 14px 0 18px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 4px;
  }
  .shop-item {
    background: linear-gradient(180deg, #2b1a0e 0%, #1a0e07 100%);
    border: 2px solid #6a4422;
    border-radius: 10px;
    padding: 12px;
    text-align: left;
    display: flex; flex-direction: column; gap: 6px;
  }
  .shop-item .si-head { display: flex; align-items: center; gap: 8px; }
  .shop-item .si-icon {
    width: 36px; height: 36px;
    background: rgba(255,217,107,0.15);
    border: 1px solid #d4a857;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; color: #ffd96b;
  }
  .shop-item .si-name { color: #ffd96b; font-weight: bold; font-size: 16px; flex: 1; }
  .shop-item .si-level { color: #cef0ff; font-size: 13px; }
  .shop-item .si-desc { color: #b9a880; font-size: 13px; line-height: 1.3; }
  .shop-item .si-buy {
    margin-top: 4px;
    background: linear-gradient(180deg, #c8851f 0%, #8a4f10 100%);
    border: 2px solid #ffd96b;
    border-radius: 6px;
    color: #fff; font-weight: bold;
    padding: 6px 12px; cursor: pointer; font-size: 14px;
    text-shadow: 1px 1px 0 #000;
  }
  .shop-item .si-buy:disabled { opacity: 0.5; cursor: not-allowed; }
  .shop-item.maxed .si-buy { background: #2a4a2a; border-color: #6acf6a; }
  .shop-item .si-bar { height: 6px; background: #1a0e07; border-radius: 3px; overflow: hidden; }
  .shop-item .si-bar-fill { height: 100%; background: linear-gradient(90deg, #c8851f, #ffd96b); }

  /* Missions */
  .mission-list {
    display: flex; flex-direction: column; gap: 10px;
    width: 100%; max-width: 540px;
    margin: 14px 0 18px;
  }
  .mission {
    background: linear-gradient(180deg, #2b1a0e 0%, #1a0e07 100%);
    border: 2px solid #6a4422;
    border-radius: 10px;
    padding: 12px 14px;
    display: flex; flex-direction: column; gap: 8px;
  }
  .mission.done { border-color: #6acf6a; }
  .mission .m-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
  .mission .m-desc { color: #ffeead; font-weight: bold; }
  .mission .m-reward { color: #ffd84a; }
  .mission .m-bar { height: 8px; background: #1a0e07; border-radius: 4px; overflow: hidden; }
  .mission .m-bar-fill { height: 100%; background: linear-gradient(90deg, #c8851f, #ffd96b); transition: width 0.3s; }
  .mission .m-claim {
    background: linear-gradient(180deg, #c8851f 0%, #8a4f10 100%);
    border: 2px solid #ffd96b;
    border-radius: 6px;
    color: #fff; font-weight: bold;
    padding: 5px 14px; cursor: pointer; font-size: 13px;
    text-shadow: 1px 1px 0 #000;
  }
  .mission .m-claim:disabled { opacity: 0.5; cursor: not-allowed; background: #444; border-color: #666; }
  .mission .m-claim.ready { animation: glow 1.2s ease-in-out infinite; }
  @keyframes glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,217,107,0.6); }
    50% { box-shadow: 0 0 0 6px rgba(255,217,107,0); }
  }
  .mission.claimed { opacity: 0.55; }

  .profile-stats {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 8px 18px;
    margin: 14px 0 18px;
    font-size: 14px; color: #ffeead;
    background: rgba(0,0,0,0.4);
    border: 1px solid #5a3825;
    border-radius: 8px;
    padding: 14px 20px;
  }
  .profile-stats div { display: flex; justify-content: space-between; }
  .profile-stats .label { color: #b9a880; }

  /* Mobile portrait: bigger text-friendly overlays */
  @media (orientation: portrait) and (max-width: 900px) {
    .overlay h1 { font-size: 38px; }
    .overlay h2 { font-size: 22px; }
    .overlay p { font-size: 14px; }
    .controls-grid { font-size: 13px; gap: 6px 12px; }
    .key { min-width: 60px; padding: 3px 7px; font-size: 12px; }
    button.btn { font-size: 20px; padding: 12px 32px; }
    button.btn.small { font-size: 14px; padding: 7px 14px; }
    .shop-grid { grid-template-columns: 1fr; max-height: 50vh; }
    .profile-stats { grid-template-columns: 1fr; font-size: 13px; }
    .profile-strip { font-size: 13px; gap: 10px; padding: 5px 10px; }
  }

  /* Loading bar */
  #loading-bar-wrap {
    width: 70%; max-width: 320px;
    height: 18px;
    background: rgba(0,0,0,0.5);
    border: 2px solid #d4a857;
    border-radius: 12px;
    overflow: hidden;
    margin-top: 20px;
  }
  #loading-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #c8851f, #ffd96b);
    transition: width 0.2s;
  }

  /* Mobile touch controls */
  #touch {
    position: absolute; bottom: 0; left: 0; right: 0;
    height: 32%;
    display: none;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 16px 18px;
    pointer-events: none;
    z-index: 6;
  }
  .touch-group { display: flex; gap: 14px; pointer-events: auto; }
  .touch-group.right { flex-direction: column-reverse; align-items: flex-end; }
  .tbtn {
    width: 68px; height: 68px;
    border-radius: 50%;
    background: rgba(255, 217, 107, 0.28);
    border: 3px solid rgba(255, 217, 107, 0.75);
    color: #ffd96b;
    font-size: 30px;
    font-weight: bold;
    display: flex; align-items: center; justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    backdrop-filter: blur(3px);
    touch-action: none;
  }
  .tbtn.attack {
    background: rgba(255, 100, 100, 0.35);
    border-color: rgba(255, 150, 100, 0.85);
    color: #ffeacc;
  }
  .tbtn.jump {
    background: rgba(120, 220, 255, 0.3);
    border-color: rgba(150, 230, 255, 0.85);
    color: #cef0ff;
  }
  .tbtn:active, .tbtn.active {
    background: rgba(255, 217, 107, 0.55);
    transform: scale(0.92);
  }
  .tbtn.attack:active, .tbtn.attack.active { background: rgba(255, 100, 100, 0.65); }
  .tbtn.jump:active, .tbtn.jump.active { background: rgba(120, 220, 255, 0.6); }

  /* Show touch on any touch device */
  @media (hover: none) and (pointer: coarse) {
    #touch { display: flex; }
  }
  /* Portrait: bigger buttons, stacked attack+jump on right */
  @media (orientation: portrait) and (max-width: 900px) {
    #touch {
      display: flex;
      height: 36%;
      padding: 0 18px 22px;
    }
    .tbtn {
      width: 78px; height: 78px;
      font-size: 34px;
      border-width: 3px;
    }
    .touch-group { gap: 18px; }
  }
  /* Landscape mobile */
  @media (orientation: landscape) and (max-width: 900px) {
    #touch { height: 28%; padding: 0 14px 14px; }
    .tbtn { width: 64px; height: 64px; font-size: 28px; }
  }

  .pulse { animation: pulse 1.6s ease-in-out infinite; }
  @keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
  }

  /* ==================== EPIC TITLE SCREEN ==================== */
  .title-screen { padding: 0 !important; background: #000 !important; backdrop-filter: none !important; overflow: hidden; }
  .title-bg-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    z-index: 0;
  }
  .title-vignette {
    position: absolute; inset: 0;
    background:
      radial-gradient(ellipse at center 75%, transparent 30%, rgba(0,0,0,0.55) 75%, rgba(0,0,0,0.95) 100%),
      linear-gradient(180deg, rgba(80,20,40,0.3) 0%, transparent 30%, transparent 70%, rgba(20,5,10,0.6) 100%);
    pointer-events: none;
    z-index: 1;
  }
  .title-content {
    position: relative;
    z-index: 2;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    width: 100%; height: 100%;
    padding: 20px;
    overflow-y: auto;
  }
  .title-hero-row {
    display: flex; align-items: center; gap: 24px;
    margin-bottom: 14px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .title-hero {
    width: 200px; height: 240px;
    position: relative;
    filter: drop-shadow(0 8px 16px rgba(140, 60, 200, 0.55));
  }
  .title-hero canvas { width: 100%; height: 100%; }
  .title-text { display: flex; flex-direction: column; align-items: flex-start; }
  .title-text h1.title-glow {
    font-size: clamp(48px, 8vw, 88px);
    font-weight: 900;
    letter-spacing: 5px;
    margin: 0;
    background: linear-gradient(180deg, #fff5d0 0%, #ffd96b 30%, #c8851f 70%, #6a3a10 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow:
      0 0 30px rgba(255, 217, 107, 0.4),
      0 4px 0 #2a0e04,
      0 8px 22px #000;
    filter: drop-shadow(0 0 18px rgba(255, 180, 60, 0.45));
    animation: glowPulse 3s ease-in-out infinite;
  }
  @keyframes glowPulse {
    0%, 100% { filter: drop-shadow(0 0 18px rgba(255, 180, 60, 0.45)); }
    50%      { filter: drop-shadow(0 0 32px rgba(255, 180, 60, 0.85)); }
  }
  .title-sub {
    font-size: clamp(16px, 2.4vw, 22px);
    color: #ffeacc;
    margin: 4px 0 10px;
    letter-spacing: 2px;
    text-shadow: 2px 2px 6px rgba(0,0,0,0.8);
  }

  /* Bestiary */
  .bestiary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 720px;
    margin: 14px 0 18px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 4px;
  }
  .bestiary-card {
    background: linear-gradient(180deg, #2b1a0e 0%, #1a0e07 100%);
    border: 2px solid #6a4422;
    border-radius: 10px;
    padding: 10px;
    text-align: center;
    display: flex; flex-direction: column; gap: 4px;
  }
  .bestiary-card .bc-name { color: #ffd96b; font-weight: bold; font-size: 14px; }
  .bestiary-card .bc-stats { color: #b9a880; font-size: 11px; }
  .bestiary-card .bc-tier { color: #a89770; font-size: 10px; margin-top: 4px; font-style: italic; }
  .bestiary-card .bc-swatch {
    width: 60px; height: 60px;
    margin: 0 auto;
    border-radius: 8px;
    background: radial-gradient(circle at 30% 30%, currentColor 0%, transparent 80%);
    position: relative;
  }
  .bestiary-card .bc-swatch::after {
    content: '👤';
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 30px;
    filter: brightness(0.4);
  }

  @media (orientation: portrait) and (max-width: 900px) {
    .title-hero { width: 140px; height: 168px; }
    .title-hero-row { gap: 14px; margin-bottom: 8px; }
    .title-text h1.title-glow { font-size: 48px; letter-spacing: 3px; }
    .title-sub { font-size: 14px; }
    .bestiary-grid { grid-template-columns: 1fr 1fr; max-height: 50vh; }
  }
