* { box-sizing: border-box; }
  :root {
    --sticky-offset: 0px;
    --index-width: 72px;
  }
  body {
    margin: 0;
    min-height: 100vh;
    background: #f6f7f8;
    color: #161616;
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  }
  header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(246, 247, 248, 0.94);
    border-bottom: 1px solid #d7dadd;
    backdrop-filter: blur(12px);
    padding: 22px 24px 28px;
  }
  h1 {
    margin: 0 0 22px;
    font-size: 22px;
    font-weight: 700;
  }
  .controls {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 220px;
    gap: 10px;
  }
  input, select {
    width: 100%;
    border: 1px solid #c8ccd0;
    border-radius: 6px;
    background: #fff;
    color: #161616;
    font: inherit;
    padding: 8px 10px;
  }
  main { padding: 18px 24px 32px; }
  .summary {
    margin-bottom: 12px;
    color: #565f68;
    font-size: 13px;
  }
  table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #d7dadd;
  }
  th, td {
    border-bottom: 1px solid #e5e7e9;
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
  }
  tbody tr:nth-child(even) td { background: #f6f8fa; }
  tbody tr:nth-child(odd) td { background: #fff; }
  th {
    position: sticky;
    top: var(--sticky-offset);
    z-index: 1;
    background: #eef0f2;
    font-size: 12px;
    color: #4d5660;
    white-space: nowrap;
  }
  .sortable {
    appearance: none;
    display: inline-flex;
    align-items: center;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 700;
    padding: 0;
    cursor: pointer;
  }
  .sortable:hover { color: #111; }
  .sort-hint {
    display: flex;
    align-items: center;
    margin-left: 4px;
  }
  .sort-hint img {
    height: 0.9em;
    width: auto;
    display: block;
    opacity: 0.4;
  }
  .sortable.active .sort-hint img {
    opacity: 0.85;
  }
  .title { font-weight: 700; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
  .muted { color: #6a737d; font-size: 12px; margin-top: 4px; }
  .tags {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 6px;
  }
  .tag {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: flex-start;
    border: 1px solid #c8ccd0;
    border-radius: 999px;
    padding: 2px 8px;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.2;
    background: #f7f8f9;
    color: inherit;
    white-space: nowrap;
    cursor: pointer;
    width: auto;
    height: auto;
  }
  .tag:hover { background: #eef2f6; border-color: #9aa3ad; }
  .empty {
    padding: 32px;
    text-align: center;
    color: #6a737d;
    background: #fff;
    border: 1px solid #d7dadd;
  }
  .sections {
    position: relative;
    border: 1px solid #d7dadd;
    background: #fff;
  }
  .section-header {
    position: sticky;
    top: var(--sticky-offset);
    z-index: 3;
    display: grid;
    grid-template-columns: var(--index-width) minmax(0, 1fr);
    background: #eef0f2;
    border-bottom: 1px solid #d7dadd;
  }
  .section-header-spacer {
    min-width: 0;
    border-right: 1px solid #d7dadd;
  }
  .section-header-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(130px, 0.6fr) 74px minmax(180px, 0.8fr);
    gap: 12px;
    padding: 10px 12px;
    color: #4d5660;
    font-size: 12px;
    white-space: nowrap;
  }
  .db-section {
    display: grid;
    grid-template-columns: var(--index-width) minmax(0, 1fr);
    border-bottom: 1px solid #e5e7e9;
    position: relative;
    scroll-margin-top: calc(var(--sticky-offset) + var(--section-header-height, 34px));
  }
  .db-section:last-child { border-bottom: 0; }
  .db-section::before {
    content: '';
    position: absolute;
    left: calc(var(--index-width) - 1px);
    top: 0;
    bottom: 0;
    width: 1px;
    background: #d7dadd;
    z-index: 1;
    pointer-events: none;
  }
  .section-index {
    position: sticky;
    top: calc(var(--sticky-offset) + var(--section-header-height, 34px));
    align-self: start;
    padding: 8px;
    color: #4d5660;
    font-weight: 800;
    font-size: 15px;
    background: #eef0f2;
    min-height: 44px;
    overflow: visible;
    z-index: 2;
    border-right: 1px solid #d7dadd;
  }
  .index-trigger {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    min-width: 32px;
    padding: 5px 6px;
  }
  .index-trigger:hover {
    background: #fff;
    border-color: #c8ccd0;
  }
  .index-menu {
    position: absolute;
    left: calc(100% + 8px);
    top: 6px;
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    width: 220px;
    max-width: min(320px, calc(100vw - 120px));
    padding: 8px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid #c8ccd0;
    border-radius: 10px;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
    z-index: 10;
  }
  .section-index.open {
    z-index: 5;
  }
  .section-index.open .index-menu {
    display: flex;
  }
  .index-menu button {
    appearance: none;
    border: 1px solid #c8ccd0;
    border-radius: 999px;
    background: #f7f8f9;
    color: #4d5660;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    padding: 6px 9px;
  }
  .index-menu button:hover {
    border-color: #8b949e;
    color: #111;
    background: #eef2f6;
  }
  .section-rows { min-width: 0; }
  .section-row {
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7e9;
    gap: 8px;
  }
  .section-row { background: #fff; }
  .section-row.alt { background: #f6f8fa; }
  .section-row:last-child { border-bottom: 0; }
  .header-icons {
    position: absolute;
    top: 14px;
    right: 24px;
    display: flex;
    gap: 8px;
  }
  .icon-btn {
    appearance: none;
    border: 1px solid #c8ccd0;
    border-radius: 50%;
    background: #fff;
    color: #4d5660;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    font-size: 22px;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }
  .icon-btn img { width: 24px; height: 24px; display: block; filter: invert(1); opacity: 0.7; }
  .icon-btn:hover { background: #eef2f6; border-color: #9aa3ad; }
  .icon-btn.fav-active { color: #e53935; }
  .fav-btn {
    appearance: none;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 2px;
    font-size: 16px;
    line-height: 1;
    color: #c8ccd0;
    transition: transform 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
  }
  .fav-btn:hover { color: #e57373; }
  .fav-btn.active { color: #e53935; }
  .fav-btn.pop {
    animation: fav-pop 0.35s ease;
  }
  @keyframes fav-pop {
    0% { transform: scale(1); }
    30% { transform: scale(1.35); }
    60% { transform: scale(0.9); }
    100% { transform: scale(1); }
  }
  .copy-btn {
    appearance: none;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 0 2px;
    font-size: 26px;
    line-height: 1;
    color: #b0b6be;
    transition: color 0.15s ease;
    flex-shrink: 0;
  }
  .copy-btn:hover { color: #4d5660; }
  .toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(22, 22, 22, 0.88);
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 13px;
    z-index: 200;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
  }
  .toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  .section-row, .table-row-wrap {
    display: flex;
    align-items: flex-start;
  }
  .section-row-content {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(130px, 0.6fr) 74px minmax(180px, 0.8fr);
    gap: 12px;
    flex: 1;
    min-width: 0;
  }
  .overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    justify-content: center;
    align-items: center;
  }
  .overlay.open { display: flex; }
  .dialog {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    max-width: 420px;
    width: calc(100% - 32px);
    box-shadow: 0 12px 32px rgba(0,0,0,0.18);
  }
  .dialog h2 { margin: 0 0 16px; font-size: 18px; text-align: center; }
  .dialog dt { font-weight: 700; margin-top: 12px; }
  .dialog dt:first-child { margin-top: 0; }
  .dialog dd { margin: 4px 0 0 0; color: #565f68; font-size: 14px; }
  .dialog-close {
    appearance: none;
    border: 1px solid #c8ccd0;
    border-radius: 8px;
    background: #f7f8f9;
    color: inherit;
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    padding: 8px 20px;
    margin-top: 20px;
    display: block;
    width: 100%;
  }
  .dialog-close:hover { background: #eef2f6; }
  .fav-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; }
  .fav-list li {
    padding: 10px 0;
    border-bottom: 1px solid #e5e7e9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .fav-list li:last-child { border-bottom: 0; }
  .fav-list .fav-title {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
  }
  .fav-list .fav-artist { color: #565f68; font-size: 13px; }
  .fav-list .fav-remove {
    appearance: none;
    border: 0;
    background: transparent;
    color: #e53935;
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    flex-shrink: 0;
  }
  .fav-empty { color: #6a737d; text-align: center; padding: 24px 0; }
  body.dark {
    background: #1a1a1a;
    color: #e0e0e0;
  }
  body.dark header {
    background: rgba(26, 26, 26, 0.94);
    border-bottom-color: #333;
  }
  body.dark input, body.dark select {
    background: #2a2a2a;
    color: #e0e0e0;
    color-scheme: dark;
    border-color: #444;
  }
  body.dark .summary { color: #999; }
  body.dark table, body.dark .sections { background: #222; border-color: #333; }
  body.dark th, body.dark .section-header { background: #2a2a2a; }
  body.dark th, body.dark .section-header-row { color: #999; }
  body.dark th { border-bottom-color: #333; }
  body.dark td { border-bottom-color: #333; }
  body.dark tbody tr:nth-child(even) td { background: #252525; }
  body.dark tbody tr:nth-child(odd) td { background: #222; }
  body.dark .section-header { border-bottom-color: #333; }
  body.dark .section-header-spacer { border-right-color: #333; }
  body.dark .db-section { border-bottom-color: #333; }
  body.dark .db-section::before { background: #333; }
  body.dark .section-index { background: #2a2a2a; color: #999; border-right-color: #333; }
  body.dark .index-trigger:hover { background: #333; border-color: #555; }
  body.dark .index-menu { background: rgba(40, 40, 40, 0.98); border-color: #555; box-shadow: 0 8px 18px rgba(0,0,0,0.4); }
  body.dark .index-menu button { background: #333; color: #ccc; border-color: #555; }
  body.dark .index-menu button:hover { background: #444; color: #fff; border-color: #777; }
  body.dark .section-row { background: #222; }
  body.dark .section-row.alt { background: #252525; }
  body.dark .section-row { border-bottom-color: #333; }
  body.dark .tag { background: #333; color: #ccc; border-color: #555; }
  body.dark .tag:hover { background: #444; border-color: #777; }
  body.dark .empty { background: #222; color: #999; border-color: #333; }
  body.dark .icon-btn { background: #2a2a2a; color: #ccc; border-color: #555; }
  body.dark .icon-btn:hover { background: #333; border-color: #777; }
  body.dark .icon-btn img { filter: none; opacity: 0.8; }
  body.dark .fav-btn { color: #555; }
  body.dark .fav-btn:hover { color: #e57373; }
  body.dark .copy-btn { color: #555; }
  body.dark .copy-btn:hover { color: #ccc; }
  body.dark .muted { color: #888; }
  body.dark .sortable:hover { color: #fff; }
  body.dark .dialog { background: #2a2a2a; color: #e0e0e0; }
  body.dark .dialog dd { color: #999; }
  body.dark .dialog-close { background: #333; border-color: #555; color: #e0e0e0; }
  body.dark .dialog-close:hover { background: #444; }
  body.dark .overlay.open { background: rgba(0,0,0,0.6); }
  body.dark .fav-list li { border-bottom-color: #333; }
  body.dark .fav-list .fav-artist { color: #888; }
  body.dark .toast { background: rgba(255,255,255,0.9); color: #1a1a1a; }
  @media (max-width: 760px) {
    :root {
      --sticky-offset: 0px;
      --index-width: 52px;
    }
    body { font-size: 14px; }
    header {
      position: static;
      padding: 14px 12px 20px;
    }
    h1 {
      margin-bottom: 10px;
      font-size: 19px;
    }
    main { padding: 12px; }
    .controls { grid-template-columns: 1fr; }
    input, select {
      min-height: 40px;
      font-size: 16px;
    }
    table, thead, tbody, tr, th, td {
      display: block;
      width: 100%;
    }
    thead {
      position: sticky;
      top: 0;
      z-index: 4;
    }
    th {
      position: static;
      top: auto;
    }
    thead tr {
      display: grid;
      grid-template-columns: repeat(3, auto);
      justify-content: start;
      gap: 14px;
      padding: 10px 12px;
      background: #eef0f2;
      border: 1px solid #d7dadd;
      border-bottom: 0;
    }
    th {
      padding: 0;
      border-bottom: 0;
      background: transparent;
    }
    th:nth-child(4) { display: none; }
    tbody tr {
      padding: 10px 12px;
      border: 1px solid #e5e7e9;
      border-top: 0;
    }
    tbody tr:nth-child(even) { background: #f6f8fa; }
    tbody tr:nth-child(odd) { background: #fff; }
    tbody tr:nth-child(even) td,
    tbody tr:nth-child(odd) td { background: transparent; }
    td {
      border-bottom: 0;
      padding: 2px 0;
    }
    th:nth-child(2), td:nth-child(2),
    th:nth-child(3), td:nth-child(3) { display: block; }
    .db-section { grid-template-columns: var(--index-width) minmax(0, 1fr); }
    .section-header {
      position: sticky;
      top: 0;
      z-index: 4;
      grid-template-columns: var(--index-width) minmax(0, 1fr);
    }
    .section-index {
      position: sticky;
      top: 37px;
      z-index: 3;
      padding: 8px 5px;
    }
    .section-header-row {
      grid-template-columns: repeat(3, auto);
      justify-content: start;
      gap: 14px;
      padding: 10px 12px;
      overflow-x: auto;
    }
    .sort-hint {
      margin-left: 3px;
    }
    .sort-hint img {
      height: 1em;
    }
    .section-header-row > span:last-child { display: none; }
    .index-menu {
      left: 6px;
      top: 40px;
      width: min(260px, calc(100vw - 32px));
    }
    .section-row {
      padding: 10px 12px;
    }
    .section-row-content {
      grid-template-columns: 1fr;
      gap: 4px;
    }
    .section-row-content > div:nth-child(2),
    .section-row-content > div:nth-child(3) {
      color: #565f68;
      font-size: 12px;
    }
    .tags { margin-top: 2px; }
    .tag {
      padding: 4px 9px;
    }
    .header-icons {
      top: 10px;
      right: 12px;
      gap: 6px;
    }
    .icon-btn {
      width: 34px;
      height: 34px;
      font-size: 17px;
    }
    .icon-btn img { width: 17px; height: 17px; }
    .fav-btn { font-size: 24px; }
    .copy-btn { font-size: 32px; }
    body.dark tbody tr { border-color: #333; }
    body.dark tbody tr:nth-child(even) { background: #252525; }
    body.dark tbody tr:nth-child(odd) { background: #222; }
    body.dark tbody tr:nth-child(even) td,
    body.dark tbody tr:nth-child(odd) td { background: transparent; }
    body.dark thead tr { background: #2a2a2a; border-color: #333; }
    body.dark table { border-color: #333; }
  }
