:root {
    --bg: #1a1a2e;
    --text: #eeeeee;
    --accent: #e74c3c;
    --accent-dark: #922b21;
    --surface: #252545;
    --font-display: 'Syne', sans-serif;
    --font-mono: 'Space Mono', monospace;
  }
  
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
  }
  
  html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
 
  /* ─── FORCE LANDSCAPE FOR PLAY UI ONLY ────────────── */
  @media screen and (orientation: portrait) {
    #play-ui {
      position: fixed;
      top: 50%;
      left: 50%;
      width: 100dvh;
      height: 100dvw;
      transform: translate(-50%, -50%) rotate(90deg);
      transform-origin: center center;
    }
  }
 
  /* ─── PLAY UI (fixed landscape-style stack) ───────── */
  .play-ui {
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 2dvh 1.5dvw;
    gap: 3dvh;
  }

  /* ─── BELLOWS (visual only) ───────────────────────── */
  #bellows {
    width: clamp(80px, 22vw, 170px);
    height: clamp(40px, 10dvh, 100px);
    margin-top: 8dvh; /* move higher so keys get more space */
    flex-shrink: 0;
  }
  
  #bellows-inner {
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
      to bottom,
      rgba(231, 76, 60, 0.7) 0px, rgba(231, 76, 60, 0.7) 8px,
      rgba(146, 43, 33, 0.7) 8px, rgba(146, 43, 33, 0.7) 16px
    );
    border-radius: 8px;
    transform: scaleY(0.3);
    transform-origin: bottom;
    transition: transform 0.05s linear, filter 0.2s ease;
    box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  }
  
  /* Push = brighter / Pull = warmer tint */
  #bellows-inner.push {
    filter: brightness(1.15) saturate(1.1);
  }
  #bellows-inner.pull {
    filter: brightness(0.9) saturate(0.9) hue-rotate(20deg);
  }

  /* Minor-quality chords shift hue more dramatically than major. */
  #bellows-inner.chord-minor.push {
    filter: brightness(1.12) saturate(1.25) hue-rotate(-10deg);
  }
  #bellows-inner.chord-minor.pull {
    filter: brightness(0.86) saturate(1.05) hue-rotate(35deg);
  }
  
  /* ─── KEYS CONTAINER ──────────────────────────────── */
  #keys-container {
    width: 100%;
    flex: 1.2; /* give keys slightly more space than bellows */
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: clamp(2px, 0.6dvh, 6px);
    padding-bottom: 0.5dvh;
  }
  
  /* ─── SHARPS ROW ──────────────────────────────────── */
  .row-sharps {
    display: flex;
    width: 100%;
    justify-content: center;
    gap: 0;
    padding: 0 calc(100% / 30); /* half a key width offset for stagger */
  }
  
  .key-slot {
    /* Each slot = same width as a white key so sharps align over the gaps */
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-end;
  }
  
  .key-slot.spacer {
    /* Empty slot where E#/B# don't exist */
    pointer-events: none;
  }
  
  /* ─── WHITES ROW ──────────────────────────────────── */
  .row-whites {
    display: flex;
    width: 100%;
    gap: clamp(2px, 0.4vw, 6px);
  }
  
  /* ─── KEY BASE ────────────────────────────────────── */
  .key {
    border: none;
    cursor: pointer;
    font-family: var(--font-display);
    font-weight: 800;
    transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.08s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    touch-action: none;
  }
  
  /* ─── WHITE KEYS ──────────────────────────────────── */
  .key-white {
    flex: 1;
    /* Shorter so all keys fit on phone */
    height: clamp(44px, 20dvh, 150px);
    border-radius: clamp(4px, 0.8vw, 10px);
    background: linear-gradient(160deg, #f5f5f0, #d8d8d0);
    color: var(--bg);
    font-size: clamp(10px, 2vw, 18px);
    box-shadow: 0 6px 0 rgba(0,0,0,0.5), inset 0 2px 4px rgba(255,255,255,0.6);
  }
  
  .key-white:active,
  .key-white.playing {
    transform: translateY(5px);
    background: var(--accent);
    color: #fff;
    box-shadow: 0 1px 0 rgba(0,0,0,0.5), inset 0 3px 6px rgba(0,0,0,0.4);
  }
  
  /* ─── BLACK KEYS ──────────────────────────────────── */
  .key-black {
    /* Width relative to the slot = slightly narrower than white */
    width: 78%;
    height: clamp(30px, 13dvh, 100px);
    border-radius: clamp(3px, 0.6vw, 8px);
    background: linear-gradient(160deg, #2a2a2a, #111);
    color: #ccc;
    font-size: clamp(7px, 1.3vw, 12px);
    box-shadow: 0 5px 0 rgba(0,0,0,0.8), inset 0 1px 3px rgba(255,255,255,0.15);
  }
  
  .key-black:active,
  .key-black.playing {
    transform: translateY(4px);
    background: var(--accent);
    color: #fff;
    box-shadow: 0 1px 0 rgba(0,0,0,0.8), inset 0 3px 6px rgba(0,0,0,0.5);
  }
  
  /* ─── SMALL LANDSCAPE PHONES TUNING ────────────────── */
  /* When the viewport height is very small (short phones
     in landscape), shrink bellows + meter so all keys
     stay inside the screen while remaining tappable. */
  @media (max-height: 460px) {
    #bellows {
      width: clamp(70px, 14vw, 130px);
      height: clamp(60px, 14dvh, 130px);
    }

    #meter {
      height: clamp(4px, 0.8dvh, 8px);
      width: 90%;
    }

    .key-white {
      height: clamp(46px, 22dvh, 140px);
      font-size: clamp(9px, 2vw, 16px);
    }

    .key-black {
      height: clamp(34px, 16dvh, 110px);
      font-size: clamp(7px, 1.5vw, 11px);
    }

    #recalibrate-btn {
      bottom: 1dvh;
      right: 1.5vw;
    }
  }

  /* ─── RECALIBRATE ─────────────────────────────────── */
  #recalibrate-btn {
    position: fixed;
    bottom: 1.5dvh;
    right: 2vw;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.35);
    font-family: var(--font-mono);
    font-size: clamp(8px, 1.5vw, 12px);
    padding: 0.4em 0.8em;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.3s;
    opacity: 1;
    letter-spacing: 0.05em;
  }
  #recalibrate-btn.hidden {
    opacity: 0;
    pointer-events: none;
  }
  
  /* ─── PERMISSION SCREEN ───────────────────────────── */
  #permission-screen {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
  }
  
  .overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    text-align: center;
    max-width: 360px;
  }
  
  .init-instruction {
    font-family: var(--font-mono);
    font-size: clamp(0.8rem, 3vw, 1rem);
    letter-spacing: 0.05em;
    line-height: 1.8;
    color: rgba(255,255,255,0.6);
    text-transform: uppercase;
  }
  
  /* Stability ring */
  #stability-ring {
    position: relative;
    width: 120px;
    height: 120px;
  }
  
  #stability-ring svg {
    width: 100%;
    height: 100%;
  }
  
  #stability-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.55rem;
    letter-spacing: 0.15em;
    color: var(--accent);
  }
  
  #start-btn {
    padding: 1rem 2.5rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 6px 20px rgba(231,76,60,0.4);
  }
  
  #start-btn:hover {
    transform: scale(1.04);
    box-shadow: 0 10px 28px rgba(231,76,60,0.5);
  }

  /* ─── AMBIENT LIGHT METER ─────────────────────────── */
  #light-meter-container {
    width: 100%;
    max-width: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
  }
  
  #light-meter-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.5);
  }

  #light-meter-track {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
  }

  #light-meter-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.1s ease-out;
  }

  /* ─── DARK ROOM ALERT ─────────────────────────────── */
  #dark-room-alert {
    position: fixed;
    top: 5vh;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(146, 43, 33, 0.9);
    color: white;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    z-index: 2000;
    transition: opacity 0.5s ease-in-out;
    pointer-events: none;
    text-align: center;
  }

  #dark-room-alert.hidden {
    opacity: 0;
  }

  /* ─── VISION MONITOR HUD ──────────────────────────── */
  #vision-monitor {
    position: fixed;
    top: 2dvh;
    left: 2vw;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,0.3);
    padding: 6px 12px;
    border-radius: 20px;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.1);
    pointer-events: none;
    z-index: 100;
  }

  #vision-led {
    width: 8px;
    height: 8px;
    background: #2ecc71;
    border-radius: 50%;
    box-shadow: 0 0 8px #2ecc71;
    transition: opacity 0.05s, transform 0.05s;
  }

  #vision-alpha-label {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: rgba(255,255,255,0.7);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  /* ─── LOBBY SCREEN ──────────────────────────────── */
  #start-screen {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: 2rem;
  }
  #start-screen h1 {
    font-family: var(--font-display);
    font-size: 2rem;
    margin-bottom: 2rem;
    text-align: center;
  }
  .modes {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 300px;
  }
  .modes button {
    padding: 1rem;
    background: var(--surface);
    color: var(--text);
    border: 2px solid var(--accent);
    border-radius: 8px;
    font-family: var(--font-display);
    font-size: 1.2rem;
    cursor: pointer;
    transition: 0.2s;
  }
  .modes button:hover {
    background: var(--accent);
  }
  
  #cello-settings {
    margin-top: 1.5rem;
    width: 100%;
    max-width: 300px;
    background: rgba(0,0,0,0.2);
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  .setting-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 0.9rem;
  }
  .setting-group.checkbox {
    justify-content: center;
  }
  .setting-group select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--accent);
    padding: 0.3rem;
    border-radius: 4px;
    font-family: var(--font-mono);
  }
  #cello-start-btn {
    margin-top: 0.5rem;
    padding: 0.8rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    font-family: var(--font-display);
  }

  /* ─── CELLO FINGERBOARD ─────────────────────── */
  #cello-fingerboard {
    flex: 1.2;
    width: 80%;
    max-width: 150px;
    background: linear-gradient(to right, #2a1610, #4e342e, #2a1610);
    border-radius: 20px;
    position: relative;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.9), 0 10px 30px rgba(0,0,0,0.6);
    overflow: hidden;
    touch-action: none;
    margin-bottom: 2dvh;
  }
  
  #string-visual {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 5px;
    background: linear-gradient(to right, #9e9e9e, #ffffff, #757575);
    transform: translateX(-50%);
    box-shadow: 0 0 8px rgba(255,255,255,0.4);
  }

  #finger-indicator {
    position: absolute;
    left: 50%;
    width: 60px;
    height: 60px;
    background: rgba(231, 76, 60, 0.4);
    border: 2px solid var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    filter: blur(2px);
    opacity: 0;
    transition: opacity 0.1s;
  }

  /* ─── SHARED UI ────────────────────────────────────── */
  #back-to-lobby-btn {
    position: fixed;
    top: 2dvh;
    right: 2vw;
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--accent);
    color: var(--text);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    cursor: pointer;
    z-index: 100;
  }