  <style>
    body {
      background: #f7f7f7;
      color: #222;
      font-family: 'Space Mono', monospace;
      margin: 0;
      padding: 0;
    }
    #main-wrap {
      max-width: 900px;
      margin: 32px auto;
      background: #fff;
      border-radius: 16px;
      box-shadow: 0 2px 32px 0 #1112, 0 0 0 8px #e0e0e0 inset;
      overflow: hidden;
    }
    header {
      background: #fff;
      border-bottom: 2px solid #ffe600;
      padding: 18px 36px 10px 36px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    h1 {
      font-family: 'Space Mono', monospace;
      letter-spacing: 0.07em;
      font-size: 2.2em;
      color: #222;
    }
    #mode-toggle {
      display: flex;
      flex-wrap: wrap;
    }
    #mode-toggle button {
      background: #ececec;
      border: none;
      border-radius: 12px 12px 0 0;
      margin-left: 2px;
      font-family: inherit;
      font-size: 1em;
      padding: 8px 20px 6px 20px;
      color: #888;
      cursor: pointer;
      outline: none;
      transition: background 0.15s, color 0.15s;
    }
    #mode-toggle .active {
      background: #ffe600;
      color: #111;
      font-weight: bold;
    }
    main {
      padding: 36px;
      background: #f7f7f7;
    }
    section {
      margin-bottom: 40px;
    }
    .input-group {
      display: flex;
      align-items: center;
      gap: 9px;
      margin-bottom: 7px;
      flex-wrap: wrap;
    }
    .label {
      font-weight: bold;
      color: #222;
      margin-right: 5px;
    }
    .mono {
      font-family: "Space Mono", monospace;
      font-size: 1.09em;
      color: #444;
      margin-right: 7px;
      word-break: break-all;
      user-select: all;
    }
    .copy-status {
      color: #2a5;
      font-size: 0.95em;
      min-width: 50px;
    }
    .btn {
      background: #ececec;
      color: #222;
      border: none;
      border-radius: 6px;
      font-size: 1em;
      font-family: inherit;
      padding: 7px 16px;
      cursor: pointer;
      margin-right: 8px;
      margin-bottom: 7px;
      transition: background 0.15s;
    }
    .btn:active, .btn:focus {
      background: #ffe600;
      color: #222;
      outline: none;
    }
    /* PIANO */
    #piano-wrap {
      margin-bottom: 18px;
      position: relative;
      user-select: none;
    }
    .piano {
      display: flex;
      position: relative;
      height: 120px;
      margin-bottom: 16px;
      user-select: none;
    }
    .piano-key {
      border-radius: 6px;
      margin-right: 2px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: flex-end;
      font-size: 0.93em;
      box-shadow: 0 2px 4px #aaa2;
      cursor: pointer;
      user-select: none;
      position: relative;
      transition: transform 0.11s;
    }
    .piano-key.white {
      width: 36px;
      height: 110px;
      background: #fff;
      border: 1px solid #ffe600;
      color: #222;
    }
    .piano-key.black {
      width: 22px;
      height: 72px;
      background: #1a1a1a;
      color: #ffe600;
      position: absolute;
      z-index: 2;
      margin-left: -11px;
      border: 1.5px solid #ffe600;
      top: 0;
    }
    .piano-key.active {
      background: #ffe600 !important;
      color: #222 !important;
      transform: scale(1.1);
    }
    .piano-key .key-label {
      font-size: 0.93em;
      margin-top: 4px;
    }
    .piano-key .key-note {
      font-size: 0.8em;
      color: #999;
    }
    #octave-indicator {
      margin: 8px 0 0 0;
      font-weight: bold;
      font-size: 1.1em;
      color: #888;
    }
    #melody-bar {
      min-height: 24px;
      margin-bottom: 12px;
    }
    .melody-note {
      display: inline-block;
      background: #ffe600;
      color: #111;
      font-family: inherit;
      font-size: 1em;
      padding: 2px 10px;
      border-radius: 7px;
      margin-right: 2px;
      margin-bottom: 2px;
      transition: background 0.14s, color 0.14s;
    }
    .melody-note.playing {
      background: #222;
      color: #ffe600;
    }
    /* LED GRID */
    #led-grid-wrap {
      display: flex;
      justify-content: center;
      margin: 0.6em 0 1em 0;
    }
    .led-grid {
      display: grid;
      grid-template-columns: repeat(8, 30px); /* 8x8 grid */
      grid-template-rows: repeat(8, 30px);    /* 8x8 grid */
      gap: 4px;
      background: #fff;
      padding: 12px;
      border-radius: 10px;
      box-shadow: 0 1px 7px #ffe60044;
      border: 2px solid #ffe600;
      width: max-content;
      margin-bottom: 20px;
    }
    .led-cell {
      width: 30px;
      height: 30px;
      border-radius: 5px;
      background: #ececec;
      border: 1.5px solid #ffe600;
      box-shadow: 0 0 4px #ffe60044 inset;
      cursor: pointer;
      transition: background 0.18s, border-color 0.19s;
      position: relative;
      z-index: 1;
    }
    .led-cell.on {
      background: #ffe600;
      border-color: #222;
      box-shadow: 0 0 12px #ffe60077, 0 0 7px #ffe60044 inset;
    }
    .led-cell.anim {
      animation: led-blink 0.4s;
    }
    .led-cell.rest {
      background: #f0f0f0;
      border-color: #ccc;
    }
    .led-cell.rest.anim {
      animation: rest-pulse 1.2s infinite;
    }
    @keyframes led-blink {
      0% { filter: brightness(1.0);}
      50% { filter: brightness(2.2);}
      100% { filter: brightness(1.0);}
    }
    @keyframes rest-pulse {
      0% { opacity: 0.4; }
      50% { opacity: 0.8; }
      100% { opacity: 0.4; }
    }
    .hide { display: none !important; }
    #decode-out { font-size: 1.12em; color: #222; margin-top: 0.4em; }
    #encode-out { font-size: 1.12em; color: #222; margin-top: 0.4em; }
    
    /* BPM Controls */
    .bpm-controls {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-top: 12px;
    }
    .bpm-controls label {
      font-weight: bold;
      color: #444;
    }
    .bpm-controls input {
      width: 60px;
      padding: 4px 8px;
      border-radius: 4px;
      border: 1px solid #ffe600;
      font-family: inherit;
      font-size: 0.95em;
    }
    
    /* Survey Says Game */
    #survey-section {
      display: none;
      padding: 20px;
      background: #fff;
      border: 2px solid #ffe600;
      border-radius: 12px;
      margin-top: 20px;
    }
    #survey-grid {
      display: grid;
      grid-template-columns: repeat(8, 40px); /* 8x8 grid */
      grid-template-rows: repeat(8, 40px);    /* 8x8 grid */
      gap: 6px;
      margin: 20px auto;
      width: fit-content;
    }
    .survey-cell {
      width: 40px;
      height: 40px;
      border-radius: 6px;
      background: #e0e0e0;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: bold;
      font-size: 1.0em;
      cursor: pointer;
      transition: all 0.2s;
      border: 2px solid #ccc;
    }
    .survey-cell.active {
      background: #ffe600;
      transform: scale(1.05);
      box-shadow: 0 0 10px rgba(255, 230, 0, 0.5);
    }
    #survey-result {
      text-align: center;
      font-size: 1.2em;
      margin-top: 15px;
      font-weight: bold;
      min-height: 30px;
    }
    
    /* Quantization controls */
    .quantization-controls {
      margin: 15px 0;
      padding: 10px;
      background: #f0f0f0;
      border-radius: 8px;
    }
    .quantization-controls label {
      font-weight: bold;
      margin-right: 10px;
    }
    .quantization-controls select {
      padding: 5px 10px;
      border-radius: 4px;
      border: 1px solid #ffe600;
      font-family: inherit;
    }
    
    .rhythm-visualizer {
      margin-top: 15px;
      padding: 10px;
      background: #f8f8f8;
      border-radius: 8px;
      border: 1px solid #eee;
    }
    .rhythm-visualizer .label {
      display: block;
      margin-bottom: 8px;
    }
@keyframes led-blink {
  0% { filter: brightness(1.0);}
  50% { filter: brightness(2.2);}
  100% { filter: brightness(1.0);}
}

@keyframes rest-pulse {
  0% { opacity: 0.4; }
  50% { opacity: 0.8; }
  100% { opacity: 0.4; }
}

.hide { display: none !important; }
