  :root {
   --bg: #0b1220;
   --primary: #60a5fa;
   --text: #e5e7eb;
   --cell: 10px;
   --visible-bars: 4;
   --cols-per-bar: 16;
   --bar-dark: #1b2233;
   --bar-light: #222b3f;
   --cell-color: #2f3440;
   --line-soft: rgba(255, 255, 255, 0.08);
   --line-strong: rgba(255, 255, 255, 0.18);
  }
  
  * {
   box-sizing: border-box;
   margin: 0;
   padding: 0;
   font-family: 'Poppins', sans-serif;
  }
  
  html,
  body {
   width: 100%;
   height: 100%;
  }
  
  body {
   background: radial-gradient(circle at top, #1e293b, var(--bg));
   color: var(--text);
   overflow: hidden;
   -webkit-tap-highlight-color: transparent;
   user-select: none;
  }
  
  .start-screen {
   position: fixed;
   inset: 0;
   background: radial-gradient(circle, #1e293b, #020617);
   display: flex;
   align-items: center;
   justify-content: center;
   z-index: 9999;
   text-align: center;
  }
  
  .start-screen h2 {
   margin-bottom: 6px;
  }
  
  .start-screen p {
   opacity: .7;
  }
  
  .start-btn {
   margin-top: 16px;
   padding: 14px 36px;
   font-size: 1.1rem;
   border-radius: 999px;
   background: var(--primary);
   color: #020617;
   font-weight: 600;
   border: none;
   cursor: pointer;
   box-shadow: 0 0 30px rgba(96, 165, 250, .6);
  }
  
  .app {
   width: 100vw;
   height: 100vh;
   display: grid;
   grid-template-rows: auto 1fr auto;
  }
  
  header {
   padding: 18px;
   text-align: center;
  }
  
  header h1 {
   font-size: 1.4rem;
  }
  
  .instrument-selector {
   margin-top: auto;
   display: flex;
   flex-direction: column;
   gap: 10px;
  }
  
  .instrument-list {
   display: grid;
   grid-template-columns: repeat(5, 1fr);
   gap: 8px;
  }
  
  .instrument-item {
   width: 46px;
   height: 46px;
   background: rgba(255, 255, 255, 0.06);
   border: none;
   border-radius: 12px;
   font-size: 24px;
   cursor: pointer;
   display: flex;
   align-items: center;
   justify-content: center;
   transition: background 0.2s ease, transform 0.15s ease;
  }
  
  .instrument-icon {
   width: 32px;
   height: 32px;
   object-fit: contain;
  }
  
  .instrument-item:hover {
   background: rgba(255, 255, 255, 0.18);
   transform: scale(1.1);
  }
  
  .instrument-item.active {
   background: rgba(255, 255, 255, 0.18);
   border: 1px solid rgba(255, 241, 214, 0.8);
   color: #0f172a;
   transform: scale(1.1);
  }
  
  .block-note {
   display: grid;
   grid-template-columns: repeat(5, 54px);
   gap: 8px;
  }
  
  .note {
   width: 54px;
   height: 54px;
   background: linear-gradient(180deg,
     rgba(255, 255, 255, .08),
     rgba(255, 255, 255, .02));
   border: 1px solid rgba(255, 255, 255, .15);
   border-radius: 14px;
   display: flex;
   justify-content: center;
   align-items: center;
   font-weight: 600;
   cursor: pointer;
   position: relative;
   transition: .10s ease;
   -webkit-user-select: none;
   user-select: none;
   touch-action: none;
  }
  
  .note.circle::after {
   content: "";
   width: 36px;
   height: 36px;
   border-radius: 50%;
   border: 1px solid rgba(255, 255, 255, .45);
   position: absolute;
  }
  
  .note.diamond::after {
   content: "";
   width: 30px;
   height: 30px;
   border: 1px solid rgba(255, 255, 255, .45);
   transform: rotate(45deg);
   position: absolute;
  }
  
  .note.special::before {
   content: "";
   width: 40px;
   height: 40px;
   border: 1px solid rgba(255, 255, 255, .35);
   transform: rotate(45deg);
   position: absolute;
  }
  
  .note {
   transform-style: preserve-3d;
  }
  
  .note.active {
   background: rgba(255, 241, 214, 0.6);
  }
  
  footer {
   text-align: center;
   padding: 12px;
   font-size: .75rem;
   opacity: .6;
  }
  
  @media (min-width: 900px) {
   .block-note {
    grid-template-columns: repeat(5, 90px);
   }
   
   .note {
    border-radius: 24px;
    width: 90px;
    height: 90px;
    font-size: 1.1rem;
   }
  }
  
  .song-panel {
   position: fixed;
   left: 0;
   top: 50%;
   transform: translateY(-50%);
   display: flex;
   align-items: center;
   z-index: 999;
  }
  
  .panel-body {
   position: relative;
   width: 310px;
   padding: 14px;
   background: rgba(15, 23, 42, 0.9);
   color: #e5e7eb;
   display: flex;
   flex-direction: column;
   gap: 12px;
   border-radius: 16px;
   margin-left: -310px;
   transition: margin 0.3s ease;
   border: 1px solid rgba(56, 189, 248, 0.28);
  }
  
  .panel-toggle {
   bottom: 88px;
   width: 44px;
   height: 72px;
   background: rgba(56, 189, 248, 0.28);
   color: #e5e7eb;
   border: none;
   border-radius: 0 14px 14px 0;
   font-size: 28px;
   font-weight: bold;
   cursor: pointer;
   display: flex;
   align-items: center;
   justify-content: center;
   position: relative;
   overflow: hidden;
  }
  
  .song-panel.open .panel-body {
   margin-left: 0;
  }
  
  .timeline-container {
   position: relative;
   width: 100vw;
   overflow: hidden;
   box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  }
  
  .timeline-container::after {
   content: "";
   position: absolute;
   top: 0;
   bottom: 0;
   left: 50%;
   transform: translateX(-0.5px);
   width: 1px;
   background: linear-gradient(to bottom,
     rgba(96, 165, 250, 0),
     rgba(96, 165, 250, .9),
     rgba(96, 165, 250, 0));
   
   pointer-events: none;
   z-index: 999;
  }
  
  .timeline-viewport {
   background: var(--bg);
   width: 100vw;
   margin: 0 auto;
   padding: 10px 50vw;
   width: calc(var(--cell) * var(--cols-per-bar) * var(--visible-bars));
   overflow-x: auto;
   overflow-y: hidden;
   scrollbar-width: thin;
   scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
   box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  }
  
  .timeline-viewport::after {
   content: "";
   position: absolute;
   top: 0;
   bottom: 0;
   left: 50%;
   transform: translateX(-0.5px);
   width: 1px;
   background: linear-gradient(to bottom,
     rgba(96, 165, 250, 0),
     rgba(96, 165, 250, 0.8),
     rgba(96, 165, 250, 0));
   pointer-events: none;
   z-index: 10;
  }
  
  .timeline-wrapper {
   width: 100vw;
   overflow-x: auto;
   overflow-y: hidden;
   padding: 12px;
   box-sizing: border-box;
   scroll-behavior: smooth;
   -webkit-overflow-scrolling: touch;
  }
  
  .timeline-wrapper::-webkit-scrollbar {
   height: 6px;
  }
  
  .timeline-wrapper::-webkit-scrollbar-track {
   background: transparent;
  }
  
  .timeline-wrapper::-webkit-scrollbar-thumb {
   background: rgba(255, 255, 255, 0.15);
   border-radius: 999px;
  }
  
  .timeline-grid {
   --cols: 16;
   display: grid;
   grid-template-columns: repeat(var(--cols), var(--cell));
   grid-template-rows: repeat(15, var(--cell));
   width: max-content;
   overflow-x: auto;
   overflow-y: hidden;
   background: var(--bg);
   transform: translateZ(0);
   will-change: transform;
   contain: layout paint style;
   border: 1px solid rgba(255, 255, 255, 0.07);
  }
  
  .cell {
   width: var(--cell);
   height: var(--cell);
   background: transparent;
   border-right: 1px solid rgba(255, 255, 255, 0.07);
  }
  
  .cell:nth-child(16n + 4),
  .cell:nth-child(16n + 8),
  .cell:nth-child(16n + 12),
  .cell:nth-child(16n + 16) {
   border-right: 1px solid var(--line-strong);
  }
  
  .cell.active {
   background: #60a5fa;
   box-shadow: 0 0 4px rgba(96, 165, 250, 0.9);
  }
  
  #trailOverlay {
   position: absolute;
   top: 0;
   height: 100%;
   pointer-events: none;
   z-index: 5;
   background: rgba(255, 255, 255, 0.07);
   border-left: 1px solid rgba(255, 255, 255, 0.2);
   border-right: 1px solid rgba(255, 255, 255, 0.2);
   opacity: 0;
   transition: opacity 0.12s linear;
  }
  
  .cell {
   position: relative;
   cursor: pointer;
  }
  
  .cell.marked::after {
   content: "";
   position: absolute;
   width: 10px;
   height: 10px;
   background: #ffffff;
   top: 50%;
   left: 50%;
   transform: translate(-50%, -50%);
   border-radius: 2px;
   box-shadow: 0 0 4px rgba(255, 255, 255, .8);
  }
  
  .bottom-layout {
   display: grid;
   grid-template-columns: auto 1fr auto;
   align-items: center;
   gap: 16px;
   width: 100%;
   box-sizing: border-box;
  }
  
  .practice-wrapper {
   position: relative;
   width: 100%;
   display: flex;
   align-items: center;
   justify-content: center;
   min-width: 0;
  }
  
  .right-controls,
  .trail-controls {
   align-items: center;
   white-space: nowrap;
   display: grid;
   grid-template-columns: repeat(3, 1fr);
   gap: 6px;
   padding: 8px;
  }
  
  .right-controls button,
  .trail-controls button {
   all: unset;
   cursor: pointer;
   min-width: 62px;
   height: 46px;
   display: flex;
   align-items: center;
   justify-content: center;
   font-size: 14px;
   font-weight: 500;
   color: #d6dbff;
   background: rgba(255, 255, 255, 0.06);
   border-radius: 10px;
   transition:
    background 0.15s ease,
    transform 0.1s ease,
    box-shadow 0.15s ease;
  }
  
  .right-controls button:hover,
  .trail-controls button:hover {
   background: rgba(255, 255, 255, 0.12);
  }
  
  .right-controls button:active,
  .trail-controls button:active {
   transform: translateY(1px);
   background: rgba(255, 255, 255, 0.18);
  }
  
  #trailBtn.recording {
   background: rgba(255, 90, 90, 0.9);
   color: #fff;
   box-shadow: 0 0 0 2px rgba(255, 90, 90, 0.4);
  }
  
  .playBtn {
   background: rgba(80, 180, 120, 0.85);
   color: #fff;
  }
  
  .playBtn:hover {
   background: rgba(80, 200, 130, 1);
  }
  
  #stepLeft,
  #stepRight {
   font-size: 16px;
   font-weight: bold;
  }
  
  #copyTrailBtn {
   background: rgba(120, 120, 255, 0.8);
   color: #fff;
  }
  
  #copyTrailBtn:hover {
   background: rgba(140, 140, 255, 1);
  }
  
  #pasteTrailBtn {
   background: rgba(90, 150, 255, 0.8);
   color: #fff;
  }
  
  #pasteTrailBtn:hover {
   background: rgba(110, 170, 255, 1);
  }
  
  #deleteMarkerBtn {
   background: rgba(255, 90, 90, 0.9);
   color: #fff;
  }
  
  .trail-controls button[onclick="undo()"],
  .trail-controls button[onclick="redo()"] {
   opacity: 0.75;
   font-size: 13px;
  }
  
  .trail-controls button[onclick="undo()"]:hover,
  .trail-controls button[onclick="redo()"]:hover {
   opacity: 1;
  }
  
  .bpm-slider {
   position: relative;
   width: 180px;
   height: 42px;
   touch-action: none;
   user-select: none;
  }
  
  .bpm-track {
   position: absolute;
   inset: 0;
   border-radius: 999px;
   background: rgba(255, 255, 255, 0.15);
   overflow: hidden;
  }
  
  .bpm-fill {
   height: 100%;
   width: 50%;
   background: linear-gradient(to right,
     #7aa2ff,
     #9ec1ff);
   border-radius: 999px;
   transition: width 0.05s linear;
  }
  
  .bpm-center {
   position: absolute;
   inset: 0;
   display: flex;
   flex-direction: column;
   align-items: center;
   justify-content: center;
   pointer-events: none;
   font-family: system-ui;
  }
  
  .bpm-value {
   font-size: 16px;
   font-weight: 700;
   color: #fff;
  }
  
  .bpm-label {
   font-size: 9px;
   color: rgba(255, 255, 255, 0.6);
  }
  
  .export-panel {
   display: flex;
   flex-direction: column;
   gap: 8px;
   padding: 12px;
   width: 220px;
   
   background: rgba(255, 255, 255, 0.04);
   border-radius: 10px;
  }
  
  .export-label {
   font-size: 12px;
   font-weight: 600;
   color: rgba(255, 255, 255, 0.7);
  }
  
  .export-panel input {
   padding: 7px 10px;
   font-size: 12px;
   color: #eaeaea;
   background: rgba(0, 0, 0, 0.35);
   border: 1px solid rgba(255, 255, 255, 0.12);
   border-radius: 6px;
   outline: none;
  }
  
  .export-panel input::placeholder {
   color: rgba(255, 255, 255, 0.4);
  }
  
  .export-panel input:focus {
   border-color: rgba(120, 180, 255, 0.8);
  }
  
  .export-btn {
   margin-top: 6px;
   padding: 8px;
   font-size: 12px;
   font-weight: 600;
   color: #fff;
   
   background: linear-gradient(135deg, #4da3ff, #6cbcff);
   border: none;
   border-radius: 6px;
   cursor: pointer;
  }
  
  .export-btn:active {
   opacity: 0.85;
  }
  
  .export-modal {
   position: fixed;
   inset: 0;
   background: rgba(0, 0, 0, 0.15);
   backdrop-filter: blur(2px);
   display: flex;
   align-items: center;
   justify-content: center;
   opacity: 0;
   pointer-events: none;
   transition: opacity 0.25s ease;
   z-index: 9999;
  }
  
  .export-modal.show {
   opacity: 1;
   pointer-events: auto;
  }
  
  .export-modal-box {
   width: 260px;
   padding: 16px;
   border-radius: 12px;
   background: #0c111b;
   box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
   text-align: center;
   transform: translateY(12px) scale(0.96);
   opacity: 0;
   transition:
    transform 0.3s cubic-bezier(.2, .8, .2, 1),
    opacity 0.3s ease;
  }
  
  .export-modal.show .export-modal-box {
   transform: translateY(0) scale(1);
   opacity: 1;
  }
  
  .export-modal-box h3 {
   margin: 0 0 6px;
   font-size: 14px;
   color: #fff;
  }
  
  .export-modal-box p {
   font-size: 12px;
   color: rgba(255, 255, 255, 0.7);
  }
  
  #exportFileName {
   color: #7aa2ff;
   font-weight: 600;
  }
  
  .export-actions button {
   flex: 1;
   padding: 8px;
   font-size: 12px;
   border-radius: 6px;
   cursor: pointer;
  }
  
  .confirmBtn {
   background: linear-gradient(135deg, #4da3ff, #6cbcff);
   border: none;
   color: #fff;
  }

  .export-loading {
   display: flex;
   flex-direction: column;
   align-items: center;
   gap: 10px;
   margin: 12px 0;
  }
  
  .spinner {
   width: 34px;
   height: 34px;
   border-radius: 50%;
   border: 3px solid rgba(255, 255, 255, 0.15);
   border-top-color: #60a5fa;
   animation: spin 0.8s linear infinite;
  }
  
  @keyframes spin {
   to {
    transform: rotate(360deg);
   }
  }
  
  .export-loading p {
   font-size: 13px;
   opacity: 0.75;
  }
  
  .export-actions {
   display: flex;
   flex-direction: column;
   gap: 8px;
   margin-top: 10px;
   transition: opacity .2s ease, transform .2s ease;
  }
  
  .export-actions.hidden {
   display: none;
  }
  
  .export-actions button.ghost {
   background: transparent;
   color: rgba(255, 255, 255, .6);
   border: 1px solid rgba(255, 255, 255, 0.15);
  }
  
  .file-name {
   font-size: 12px;
   opacity: .7;
  }
  
  @media (orientation: portrait) {
   .bottom-layout {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    gap: 4px;
   }
   
   .trail-controls,
   .right-controls {
    justify-content: center;
   }
   
   .trail-controls {
    order: 2;
   }
   
   .right-controls {
    order: 2;
   }
   
   .practice-wrapper {
    margin-top: 6px;
    order: 1;
    width: 100%;
    justify-content: center;
   }
  }