:root {
  color-scheme: dark;
  --bg: #070b0f;
  --panel: rgba(15, 21, 27, 0.78);
  --panel-strong: rgba(18, 25, 32, 0.9);
  --text: #edf5f2;
  --muted: #9aa9a5;
  --line: rgba(221, 238, 233, 0.12);
  --accent: #b8a4d6;
  --accent-dark: #9f8ac4;
  --accent-soft: rgba(184, 164, 214, 0.16);
  --button-purple: #b8a4d6;
  --button-purple-dark: #9f8ac4;
  --button-purple-soft: rgba(184, 164, 214, 0.18);
  --warn: #f0b64b;
  --sorted: rgba(184, 164, 214, 0.12);
  --sorted-strong: rgba(184, 164, 214, 0.22);
  --normal: #9bc89a;
  --normal-bg: rgba(155, 200, 154, 0.055);
  --normal-bg-strong: rgba(155, 200, 154, 0.13);
  --hard: #d7bd78;
  --hard-bg: rgba(215, 189, 120, 0.06);
  --hard-bg-strong: rgba(215, 189, 120, 0.14);
  --extreme: #d69a9a;
  --extreme-bg: rgba(214, 154, 154, 0.055);
  --extreme-bg-strong: rgba(214, 154, 154, 0.13);
  --real: #b8a4d6;
  --real-bg: rgba(184, 164, 214, 0.06);
  --real-bg-strong: rgba(184, 164, 214, 0.14);
  --glass-border: rgba(255, 255, 255, 0.12);
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 16% 6%, rgba(45, 212, 191, 0.14), transparent 30%),
    radial-gradient(circle at 88% 0%, rgba(193, 156, 255, 0.12), transparent 28%),
    linear-gradient(180deg, #090d12 0%, #0b1118 52%, #070b0f 100%);
  font-family: Inter, "Noto Sans SC", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button,
a,
input {
  transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.app-shell {
  display: grid;
  min-height: 100vh;
}

body[data-view="list"] .app-shell {
  display: block;
}

body[data-view="list"] .preview-panel,
body[data-view="chart"] .control-panel {
  display: none;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 20px;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 12px;
  z-index: 10;
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  padding: 14px 16px;
  background: rgba(16, 23, 31, 0.72);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px) saturate(150%);
}

.brand-actions,
.preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand p,
.status-text {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.search-area,
.selection-area {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  color: var(--text);
  background: rgba(9, 14, 20, 0.74);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

input:focus {
  outline: 3px solid rgba(45, 212, 191, 0.16);
  border-color: var(--accent);
  background: rgba(12, 19, 27, 0.96);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

button {
  min-height: 40px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 8px 14px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(45, 212, 191, 0.18);
}

button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

#searchButton,
#listButton {
  border-color: rgba(184, 164, 214, 0.72);
  color: #f7f2ff;
  background: rgba(184, 164, 214, 0.72);
  box-shadow: 0 8px 18px var(--button-purple-soft);
}

#searchButton:hover,
#listButton:hover {
  border-color: var(--button-purple);
  background: var(--button-purple-dark);
  box-shadow: 0 10px 22px rgba(184, 164, 214, 0.22);
}

button:disabled {
  border-color: var(--line);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.08);
  cursor: not-allowed;
}

.song-results {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(145%);
}

.no-results {
  padding: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  font-size: 13px;
}

.song-table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  table-layout: fixed;
}

.song-table th,
.song-table td {
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
}

.song-table th.level-column,
.song-table td.level-column {
  text-align: center;
}

.song-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom-color: var(--line);
  background: rgba(20, 28, 36, 0.94);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(14px) saturate(150%);
}

.song-table th.normal {
  background: var(--normal-bg-strong);
}

.song-table th.hard {
  background: var(--hard-bg-strong);
}

.song-table th.extreme {
  background: var(--extreme-bg-strong);
}

.song-table th.real {
  background: var(--real-bg-strong);
}

.song-table th.normal .table-sort-button {
  color: var(--normal);
}

.song-table th.hard .table-sort-button {
  color: var(--hard);
}

.song-table th.extreme .table-sort-button {
  color: var(--extreme);
}

.song-table th.real .table-sort-button {
  color: var(--real);
}

.song-table th.sorted .table-sort-button::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  vertical-align: middle;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.song-table th.sorted[data-direction="asc"] .table-sort-button::after {
  border-bottom: 6px solid currentColor;
}

.song-table th.sorted[data-direction="desc"] .table-sort-button::after {
  border-top: 6px solid currentColor;
}

.song-table td.normal {
  background: var(--normal-bg);
}

.song-table td.hard {
  background: var(--hard-bg);
}

.song-table td.extreme {
  background: var(--extreme-bg);
}

.song-table td.real {
  background: var(--real-bg);
}

.song-table tbody tr:hover {
  background: rgba(20, 160, 133, 0.055);
}

.song-table tbody tr:hover td.normal {
  background: rgba(155, 200, 154, 0.095);
}

.song-table tbody tr:hover td.hard {
  background: rgba(215, 189, 120, 0.1);
}

.song-table tbody tr:hover td.extreme {
  background: rgba(214, 154, 154, 0.095);
}

.song-table tbody tr:hover td.real {
  background: rgba(184, 164, 214, 0.1);
}

.song-table tbody tr:last-child td {
  border-bottom: 0;
}

.title-column {
  width: 40%;
}

.artist-column {
  width: 30%;
}

.level-column {
  width: 7.5%;
  text-align: center;
}

.song-table td.title-column strong {
  display: block;
  display: -webkit-box;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.song-table td.artist-column {
  overflow: hidden;
  color: #bdc9c6;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-sort-button {
  width: 100%;
  min-height: 28px;
  border: 0;
  border-radius: 6px;
  padding: 4px 6px;
  color: var(--text);
  background: transparent;
  text-align: inherit;
  font-size: 12px;
  font-weight: 800;
}

.table-sort-button:hover {
  color: #fff;
  background: var(--accent);
  transform: none;
}

.song-table .level-column .table-sort-button {
  text-align: center;
}

.song-table td.level-column a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgba(6, 10, 14, 0.42);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  margin: 0 auto;
}

.song-table td.normal a {
  border-color: var(--normal);
  color: var(--normal);
}

.song-table td.hard a {
  border-color: var(--hard);
  color: var(--hard);
}

.song-table td.extreme a {
  border-color: var(--extreme);
  color: var(--extreme);
}

.song-table td.real a {
  border-color: var(--real);
  color: var(--real);
}

.song-table td.level-column a:hover {
  border-color: var(--accent);
  background: rgba(45, 212, 191, 0.1);
  box-shadow: 0 0 0 2px rgba(45, 212, 191, 0.16);
  transform: translateY(-1px);
}

.status-text.error {
  color: #a13a2a;
}

.status-text.ok {
  color: var(--accent-dark);
}

.preview-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
  min-width: 0;
  background:
    radial-gradient(circle at 12% 4%, rgba(45, 212, 191, 0.1), transparent 28%),
    linear-gradient(180deg, #070a0f 0%, #05070a 100%);
}

.preview-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(12, 18, 25, 0.92), rgba(7, 10, 15, 0.82));
  backdrop-filter: blur(18px) saturate(150%);
}

.preview-info {
  min-width: 0;
}

.preview-cover {
  grid-row: 1 / span 2;
  width: 54px;
  height: 54px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
}

.preview-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-cover.hidden + .preview-info {
  grid-column: 1 / 3;
}

.preview-cover.hidden ~ .preview-chart-stats {
  grid-column: 1 / 4;
}

.preview-toolbar strong {
  display: block;
  overflow: hidden;
  color: #f5fbfa;
  font-size: 17px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.preview-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  color: #dce7e4;
  background: rgba(255, 255, 255, 0.055);
  font-size: 12px;
  font-weight: 800;
}

.preview-chip.normal {
  border-color: var(--normal);
  color: var(--normal);
}

.preview-chip.hard {
  border-color: var(--hard);
  color: var(--hard);
}

.preview-chip.extreme {
  border-color: var(--extreme);
  color: var(--extreme);
}

.preview-chip.real {
  border-color: var(--real);
  color: var(--real);
}

.preview-actions {
  justify-self: end;
}

.preview-chart-stats {
  grid-column: 2 / 4;
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-stage {
  position: relative;
  overflow: auto;
  padding: 10px;
  background: #05070a;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-right: 0;
  border-left: 0;
  box-shadow: none;
}

#chartImage {
  display: none;
  max-width: 100%;
  width: auto;
  height: auto;
  background: #05070a;
  border-radius: 0;
  box-shadow: none;
}

#chartImage.ready {
  display: block;
}

.empty-state {
  display: grid;
  place-items: center;
  width: min(420px, calc(100% - 32px));
  min-height: 160px;
  margin: 56px auto;
  color: var(--muted);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  background: rgba(15, 21, 27, 0.72);
  backdrop-filter: blur(12px);
}

.empty-state.hidden {
  display: none;
}

.image-state {
  display: grid;
  place-items: center;
  width: min(420px, calc(100% - 32px));
  min-height: 160px;
  margin: 56px auto;
  color: var(--muted);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  background: rgba(15, 21, 27, 0.72);
  backdrop-filter: blur(12px);
}

.image-state.error {
  color: #a13a2a;
}

.hidden {
  display: none;
}

@media (max-width: 900px) {
  .control-panel {
    padding: 12px;
  }

  .brand {
    flex-direction: column;
    top: 8px;
    border-radius: 16px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .song-table {
    min-width: 0;
  }

  .title-column {
    width: 44%;
  }

  .artist-column {
    display: none;
  }

  .level-column {
    width: 14%;
  }

  .song-table th,
  .song-table td {
    padding: 6px 4px;
  }

  .song-table th.title-column,
  .song-table td.title-column {
    position: sticky;
    left: 0;
    z-index: 1;
    background: rgba(18, 25, 32, 0.98);
    box-shadow: 1px 0 0 var(--line);
  }

  .song-table th.title-column {
    z-index: 3;
    background: rgba(20, 28, 36, 0.98);
  }

  .song-table td.title-column strong {
    -webkit-line-clamp: 1;
  }

  .song-table td.level-column a {
    width: 34px;
    height: 32px;
  }

  .preview-cover {
    width: 52px;
    height: 52px;
  }

  .preview-toolbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px 10px;
    padding: 10px 12px;
  }

  .preview-toolbar strong {
    font-size: 15px;
  }

  .preview-meta-row {
    gap: 6px;
    margin-top: 5px;
  }

  .preview-chart-stats {
    grid-column: 1 / 4;
    white-space: normal;
  }

  body[data-view="chart"] {
    overflow: hidden;
  }

  body[data-view="chart"] .preview-panel {
    height: 100svh;
    min-height: 100svh;
  }

  body[data-view="chart"] .image-stage {
    display: block;
    min-height: 0;
    padding: 8px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  body[data-view="chart"] #chartImage {
    width: auto;
    max-width: none;
    height: calc(100% - 16px);
    max-height: none;
  }
}
