:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --line: #d9dee5;
  --line-strong: #aab4bf;
  --ink: #20252b;
  --muted: #66717d;
  --accent: #a23b35;
  --blue: #246f92;
  --green: #237b62;
  --shadow: 0 12px 32px rgba(23, 31, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.button-link {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

button:hover,
.button-link:hover {
  filter: brightness(0.96);
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button-row button,
.button-row .button-link,
.page-tabs button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line-strong);
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.topbar-actions {
  display: grid;
  justify-items: end;
  gap: 10px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  letter-spacing: 0;
}

h3 {
  font-size: 16px;
}

.topbar p,
.status-line,
.subtle {
  color: var(--muted);
  font-size: 13px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(88px, 1fr));
  gap: 10px;
}

.summary-strip div {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 12px;
  border-radius: 8px;
  min-width: 88px;
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary-strip strong {
  display: block;
  font-size: 22px;
  margin-top: 4px;
}

.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  user-select: none;
}

.toggle-line input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--blue);
}

.page-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.page-tabs button.is-active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.page-panel {
  display: none;
}

.page-panel.is-active {
  display: block;
}

.rating-layout {
  display: block;
}

.workspace {
  min-width: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.form-grid,
.data-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
}

.data-controls {
  grid-template-columns: minmax(220px, 1.3fr) repeat(3, minmax(130px, 1fr));
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(36, 111, 146, 0.14);
}

.status-line {
  min-height: 18px;
  margin-top: 10px;
}

.api-credit {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.api-credit a {
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

.api-credit a:hover {
  text-decoration: underline;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

.data-table {
  min-width: 1260px;
}

.recommend-table {
  min-width: 1020px;
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  vertical-align: middle;
}

th {
  background: #eef1f4;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

td {
  background: #fff;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr.clickable-row {
  cursor: pointer;
}

tbody tr.clickable-row:hover td,
tbody tr.clickable-row.is-selected td {
  background: #eef7fb;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
  padding: 40px 12px;
}

.rating-svg-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
}

.rating-svg-wrap.muted-box {
  min-height: 180px;
}

.rating-object-svg {
  display: block;
  width: 100%;
  min-width: 980px;
  height: auto;
}

.rating-svg-row {
  cursor: pointer;
  outline: none;
}

.rating-svg-row:hover rect:first-child,
.rating-svg-row:focus rect:first-child {
  fill: #eef7fb;
  stroke-width: 2;
}

.level-badge,
.source-badge {
  display: inline-flex;
  min-width: 34px;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
  background: var(--surface-2);
  white-space: nowrap;
}

.source-badge.excel {
  color: var(--green);
  border-color: rgba(35, 123, 98, 0.28);
  background: rgba(35, 123, 98, 0.08);
}

.source-badge.fumen {
  color: #8a5a12;
  border-color: rgba(138, 90, 18, 0.28);
  background: rgba(138, 90, 18, 0.08);
}

.source-badge.encoder {
  color: var(--blue);
  border-color: rgba(36, 111, 146, 0.28);
  background: rgba(36, 111, 146, 0.08);
}

.recommend-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.recommend-controls {
  display: grid;
  grid-template-columns: minmax(180px, 260px) repeat(2, max-content);
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.recommend-toggle {
  min-height: 38px;
  padding-bottom: 1px;
}

.recommend-toggle:has(input:disabled) {
  opacity: 0.55;
}

.recommend-chip,
.recommend-band {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.recommend-chip strong {
  color: var(--ink);
  margin-right: 4px;
}

.recommend-band.same {
  color: var(--blue);
  border-color: rgba(36, 111, 146, 0.28);
  background: rgba(36, 111, 146, 0.08);
}

.recommend-band.high {
  color: #8a5a12;
  border-color: rgba(138, 90, 18, 0.28);
  background: rgba(138, 90, 18, 0.08);
}

.recommend-band.low {
  color: var(--green);
  border-color: rgba(35, 123, 98, 0.28);
  background: rgba(35, 123, 98, 0.08);
}

.detail-panel {
  min-height: 96px;
}

.muted-box {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: var(--surface-2);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
}

.detail-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.detail-item strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.filter-rows {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.filter-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 110px minmax(160px, 1.2fr) auto;
  gap: 8px;
  align-items: end;
}

.filter-row button {
  min-width: 70px;
  background: #fff;
  color: var(--ink);
  border-color: var(--line-strong);
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 12px;
}

.pagination button {
  min-width: 38px;
  height: 34px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  border-color: var(--line-strong);
}

.pagination button.is-active {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.pagination button:disabled {
  cursor: not-allowed;
  color: var(--muted);
  background: var(--surface-2);
  opacity: 0.62;
}

.pagination-gap {
  color: var(--muted);
  padding: 0 2px;
}

.numeric {
  font-variant-numeric: tabular-nums;
}

body.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 32, 0.46);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: min(1120px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 56px rgba(15, 23, 32, 0.24);
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.modal-head span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.modal-head h2 {
  overflow-wrap: anywhere;
}

.modal-close {
  background: #fff;
  color: var(--ink);
  border-color: var(--line-strong);
  flex: 0 0 auto;
}

.modal-body {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.modal-section {
  display: grid;
  gap: 10px;
}

.feedback-section {
  border-top: 1px solid var(--line);
  padding-top: 4px;
}

.feedback-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.feedback-head span,
.feedback-counts {
  color: var(--muted);
  font-size: 12px;
}

.feedback-grid {
  display: grid;
  gap: 8px;
}

.feedback-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto minmax(120px, auto);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.feedback-row strong,
.feedback-row span {
  display: block;
}

.feedback-row span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.feedback-buttons {
  display: flex;
  gap: 8px;
}

.feedback-buttons button {
  min-height: 32px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  border-color: var(--line-strong);
}

.feedback-buttons button.is-selected {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.feedback-detail-item {
  display: grid;
  gap: 8px;
}

.feedback-inline {
  display: grid;
  gap: 6px;
}

.feedback-inline .feedback-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.feedback-inline .feedback-buttons button {
  width: 100%;
  min-height: 30px;
  padding: 0 8px;
}

.preview-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  align-items: start;
}

.preview-figure {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.preview-figure img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
}

.local-preview-figure {
  grid-column: 1 / -1;
}

.local-preview-frame {
  max-height: 720px;
  overflow: auto;
  background: #f7f8fa;
}

.local-preview-svg {
  display: block;
  width: 100%;
  min-width: 820px;
  height: auto;
}

.chart-player-figure {
  grid-column: 1 / -1;
}

.chart-player {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #f7f8fa;
}

.chart-player-canvas {
  display: block;
  width: 100%;
  height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.chart-player-controls {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto auto auto;
  gap: 10px;
  align-items: center;
}

.chart-player-controls button,
.chart-player-controls select {
  min-height: 34px;
  background: #fff;
  color: var(--ink);
  border-color: var(--line-strong);
}

.chart-player-controls input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

.chart-player-time {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.preview-figure figcaption {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.preview-empty {
  min-height: 80px;
  display: grid;
  place-items: center;
}

.curve-modal-panel,
.export-modal-panel {
  width: min(1040px, 100%);
}

.curve-figure {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.curve-figure img {
  display: block;
  width: 100%;
  height: auto;
}

.curve-figure figcaption,
.export-help {
  color: var(--muted);
  font-size: 13px;
}

.curve-figure figcaption {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.rule-copy {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.72;
}

.rule-copy h3 {
  margin-top: 2px;
  color: var(--ink);
}

.export-actions {
  justify-content: flex-start;
}

.export-preview {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

@media (max-width: 1100px) {
  .topbar {
    flex-direction: column;
  }

  .topbar-actions {
    justify-items: stretch;
    width: 100%;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid,
  .data-controls,
  .recommend-controls,
  .detail-grid,
  .filter-row {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-tabs,
  .rating-actions,
  .export-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .rating-actions button:first-child,
  .export-actions .button-link {
    grid-column: 1 / -1;
  }

  .page-tabs button,
  .button-row button,
  .button-row .button-link {
    width: 100%;
    min-height: 42px;
    padding: 0 10px;
  }

  .panel {
    padding: 12px;
    margin-bottom: 12px;
  }

  .rating-svg-wrap,
  .table-wrap,
  .local-preview-frame {
    -webkit-overflow-scrolling: touch;
  }

  .rating-object-svg {
    min-width: 760px;
  }

  .data-table {
    min-width: 1120px;
  }

  .recommend-table {
    min-width: 920px;
  }

  .local-preview-svg {
    min-width: 720px;
  }

  .chart-player-canvas {
    height: 230px;
  }

  .chart-player-controls {
    grid-template-columns: 1fr 1fr;
  }

  .feedback-head,
  .feedback-row {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .feedback-head {
    display: grid;
  }

  .feedback-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .chart-player-controls input[type="range"],
  .chart-player-time {
    grid-column: 1 / -1;
  }

  .modal-backdrop {
    padding: 0;
  }

  .modal-panel {
    width: 100%;
    min-height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .modal-head {
    align-items: stretch;
    flex-direction: column;
  }

  .preview-images {
    grid-template-columns: 1fr;
  }

  .preview-figure figcaption {
    flex-direction: column;
  }

  h1 {
    font-size: 28px;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding: 10px;
  }

  h1 {
    font-size: 24px;
  }

  .summary-strip strong {
    font-size: 20px;
  }

  .rating-actions,
  .export-actions {
    grid-template-columns: 1fr;
  }
}
