  * { margin: 0; padding: 0; box-sizing: border-box; }
  html, body { height: 100%; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  body {
    background: #0a0a0c;
    color: #e8e8e8;
    font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang HK', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    user-select: none;
    /* Push content below iOS Safari URL bar (56px buffer) + notch/home indicator */
    padding: calc(env(safe-area-inset-top) + 56px) 0 calc(env(safe-area-inset-bottom) + 16px);
  }
  .hud {
    width: min(700px, 92vw);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
    margin-bottom: 18px;
    gap: 4px;
    flex-wrap: nowrap;
  }
  .level-indicator { display: flex; align-items: baseline; gap: 10px; text-transform: uppercase; }
  .level-label { font-size: 10px; letter-spacing: 0.4em; color: #555; }
  .level-num   { font-size: clamp(20px, 6vw, 28px); font-weight: 200; color: #fff; }
  .level-sep   { font-size: clamp(10px, 2.8vw, 12px); color: #444; }
  .level-name  { font-size: clamp(8px, 2.4vw, 11px); color: #888; letter-spacing: 0.2em; margin-left: 4px; transition: opacity 0.4s; text-transform: uppercase; }

  .hearts { display: flex; gap: 6px; }
  .heart { width: clamp(16px, 5vw, 22px); height: clamp(16px, 5vw, 22px); transition: all 0.35s ease; transform-origin: center; }
  .heart path { fill: #ff4a6b; transition: fill 0.35s; }
  .heart.lost { transform: scale(0.85); filter: grayscale(1) brightness(0.45); }
  .heart.lost path { fill: #2a2a2e; }
  .heart.losing { animation: heartBreak 0.5s ease-out; }
  @keyframes heartBreak {
    0% { transform: scale(1); }
    30% { transform: scale(1.5); }
    60% { transform: scale(0.7); }
    100% { transform: scale(0.85); }
  }

  canvas {
    display: block;
    cursor: pointer;
    border-radius: 14px;
    background: #14141a;
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  }
  /* Game canvas: square, scales to fit viewport while keeping internal 700x700 resolution */
  #game {
    width: min(700px, min(92vw, 60dvh));
    height: min(700px, min(92vw, 60dvh));
  }
  .stats {
    margin-top: 18px;
    font-size: 10px;
    color: #444;
    letter-spacing: 0.3em;
    text-transform: uppercase;
  }
  .stats span { color: #e8e8e8; font-weight: 500; }

  .game-over {
    position: fixed; inset: 0;
    background: rgba(10, 10, 12, 0.85);
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    z-index: 10; animation: fadeIn 0.4s ease;
  }
  .game-over.hidden { display: none; }
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  .game-over-card {
    background: #16161a; padding: 44px 56px; border-radius: 18px; text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
    animation: cardPop 0.5s cubic-bezier(.2,1.4,.4,1);
  }
  @keyframes cardPop {
    0% { transform: scale(0.7); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
  }
  .game-over-card h2 {
    font-weight: 200; font-size: 34px; margin-bottom: 6px;
    color: #ff4a6b; letter-spacing: 0.04em;
  }
  .game-over-sub {
    color: #777; font-size: 11px; letter-spacing: 0.3em;
    text-transform: uppercase; margin-bottom: 32px;
  }
  .btn-retry {
    background: #fff; color: #0a0a0c; border: none;
    padding: 14px 38px; font-size: 12px; font-weight: 600;
    letter-spacing: 0.25em; text-transform: uppercase;
    border-radius: 100px; cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: inherit;
  }
  .btn-retry:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(255, 255, 255, 0.18);
  }

  .audio-hint {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #444;
    font-size: 10px;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    animation: pulse 2s ease-in-out infinite;
  }
  .audio-hint.hidden { display: none; }
  @keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50%      { opacity: 0.9; }
  }

  /* ===== Common ===== */
  .hidden { display: none !important; }

  /* ===== Start Page ===== */
  .start-page {
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at center, #14141a 0%, #0a0a0c 70%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    overflow: hidden;
  }
  .start-bg {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.18;
  }
  .start-snake {
    position: absolute;
    width: min(380px, 70vw);
    height: min(380px, 70vw);
  }
  .start-snake   { top: 5%;   left: 5%;   transform: rotate(-12deg); }
  .start-snake-2 { top: 60%;  right: 5%;  transform: rotate(28deg); }
  .start-snake-3 { bottom: 5%; left: 40%; transform: rotate(-6deg); }

  .start-content {
    position: relative;
    text-align: center;
    z-index: 2;
  }
  .start-title {
    font-weight: 100;
    font-size: 88px;
    letter-spacing: 0.06em;
    line-height: 1;
    margin-bottom: 18px;
    color: #fff;
  }
  .start-title span {
    background: linear-gradient(135deg, #7ee8b3 0%, #c39bff 50%, #ff9b6e 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }
  .start-tagline {
    color: #555;
    font-size: 11px;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    margin-bottom: 50px;
  }
  .start-buttons {
    display: flex;
    gap: 18px;
    justify-content: center;
  }
  .btn {
    border: none;
    padding: 16px 42px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    border-radius: 100px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    font-family: inherit;
  }
  .btn-primary {
    background: #fff;
    color: #0a0a0c;
  }
  .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(255, 255, 255, 0.22);
  }
  .btn-secondary {
    background: transparent;
    color: #e8e8e8;
    border: 1px solid rgba(255, 255, 255, 0.18);
  }
  .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.32);
    transform: translateY(-2px);
  }

  /* ===== Level Select ===== */
  .level-select {
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at center, #14141a 0%, #0a0a0c 70%);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 50px 30px 30px;
    z-index: 100;
    overflow-y: auto;
  }
  .select-header {
    width: 100%;
    max-width: 720px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
  }
  .select-header h2 {
    font-weight: 200;
    font-size: 26px;
    color: #fff;
    letter-spacing: 0.05em;
  }
  .btn-back {
    background: transparent;
    color: #888;
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 10px 22px;
    border-radius: 100px;
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
    letter-spacing: 0.2em;
    transition: all 0.2s;
  }
  .btn-back:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
  }
  .level-grid {
    width: 100%;
    max-width: 720px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
  }
  .level-card {
    aspect-ratio: 1;
    background: #16161a;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    overflow: hidden;
    padding: 14px;
  }
  .level-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  }
  .level-card.cleared {
    border-color: rgba(126, 232, 179, 0.5);
    background: linear-gradient(135deg, #16161a 0%, #1a2420 100%);
  }
  .level-card.cleared::after {
    content: '✓';
    position: absolute;
    top: 10px;
    right: 12px;
    color: #7ee8b3;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 0 0 8px rgba(126, 232, 179, 0.6);
  }
  .level-card-num {
    font-size: 38px;
    font-weight: 200;
    color: #fff;
    margin-bottom: 6px;
  }
  .level-card-name {
    font-size: 11px;
    color: #888;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    text-align: center;
    margin-bottom: 8px;
  }
  .level-card-grid {
    width: 60%;
    aspect-ratio: 1;
    display: block;
  }
  .level-card.cleared .level-card-num { color: #7ee8b3; }
  .select-hint {
    margin-top: 24px;
    color: #444;
    font-size: 10px;
    letter-spacing: 0.3em;
    text-transform: uppercase;
  }

  /* ===== Game UI shell ===== */
  .game-ui {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-height: 100vh;
    padding: 30px 0;
  }
  .btn-menu {
    position: fixed;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #888;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
    z-index: 5;
  }
  .btn-menu:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
  }

  /* HUD right-side actions (hearts + buttons together) */
  .hud-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
  }
  .hud-buttons {
    display: flex;
    gap: 6px;
  }
  .btn-hud {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #b8b8b8;
    padding: clamp(5px, 1.5vw, 8px) clamp(8px, 2.5vw, 14px);
    border-radius: 100px;
    cursor: pointer;
    font-family: inherit;
    font-size: clamp(9px, 2.8vw, 11px);
    font-weight: 500;
    letter-spacing: 0.12em;
    transition: all 0.2s;
    white-space: nowrap;
  }
  .btn-hud:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
  }

  /* Mobile HUD: hide long level name, shrink buttons further to prevent overflow */
  @media (max-width: 500px) {
    .hud { gap: 2px; padding: 0 2px; }
    .hud-actions { gap: 8px; }
    .hud-buttons { gap: 4px; }
    .btn-hud { padding: 4px 8px; }
    .hearts { gap: 4px; }
  }

  /* ===== Mute button (Phase D1) ===== */
  .btn-mute {
    position: relative;
    min-width: 44px;     /* iOS tap target */
    padding: 6px 10px;
    color: rgba(255, 255, 255, 0.85);
  }
  .btn-mute .icon {
    width: 18px;
    height: 18px;
    display: block;
  }
  .btn-mute .icon-off { display: none; }
  .btn-mute.muted .icon-on { display: none; }
  .btn-mute.muted .icon-off { display: block; }
  .btn-mute.muted {
    color: #ff6b6b;       /* visual cue when sound is off */
    background: rgba(255, 107, 107, 0.08);
    border-color: rgba(255, 107, 107, 0.3);
  }

  /* In-game fixed Home button: hidden on start page (which has its own), shown during gameplay */
  #btnHomeGame { display: none; }
  body.game-active #btnHomeGame { display: inline-flex; }

  .game-over-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
  }
  .btn-retry-secondary {
    background: transparent;
    color: #aaa;
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 14px 32px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
  }
  .btn-retry-secondary:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
  }
  /* ===== Back to Home Button ===== */
  .btn-home {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 9999;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #aaa;
    font-size: 14px;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.2s, color 0.2s;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }
  .btn-home:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
  }
  .btn-home::before {
    content: '←';
    font-size: 16px;
  }
