:root {
  --bg: #efe5d2;
  --card: rgba(255, 252, 244, 0.95);
  --ink: #2b2118;
  --muted: #6f5d4c;
  --line: #d7c5ad;
  --accent: #b87427;
  --accent-soft: #f4dcc0;
  --melody: #cf4e43;
  --accompaniment: #2f5ebd;
  --beat: #22805b;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 251, 241, 0.92), transparent 36%),
    radial-gradient(circle at bottom right, rgba(196, 154, 94, 0.22), transparent 30%),
    linear-gradient(140deg, #e8dcc7 0%, #efe5d2 45%, #e0cfb2 100%);
}

.language-nav {
  display: flex;
  justify-content: flex-end;
  width: min(1040px, calc(100% - 28px));
  margin: 0 auto;
  padding-top: 12px;
}

.language-nav a {
  color: #85521d;
  font-weight: 700;
}

.container {
  width: min(1040px, calc(100% - 28px));
  margin: 26px auto 50px;
}

.card {
  background: var(--card);
  border: 1px solid rgba(141, 104, 56, 0.18);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 18px 50px rgba(95, 68, 34, 0.08);
  backdrop-filter: blur(8px);
}

.hero {
  padding: 22px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2 {
  margin: 0 0 12px;
}

p {
  margin: 0 0 10px;
  line-height: 1.5;
}

.progress {
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 700;
}

.stack > * + * {
  margin-top: 12px;
}

label {
  display: block;
  font-weight: 600;
}

input[type="text"],
input[type="number"],
select,
textarea,
button {
  font: inherit;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
}

button {
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #fffaf2;
  padding: 10px 16px;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.04);
}

.submit-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.secondary-button {
  border-color: rgba(141, 104, 56, 0.38);
  background: rgba(255, 248, 235, 0.95);
  color: var(--accent);
}

.hint {
  color: var(--muted);
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--muted);
}

.trial-legend {
  margin-bottom: 14px;
}

.legend-chip {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 3px;
  vertical-align: -1px;
}

.legend-chip.melody { background: var(--melody); }
.legend-chip.accompaniment { background: var(--accompaniment); }
.legend-chip.beat { background: var(--beat); }

.roll-wrap {
  position: relative;
  width: 100%;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf7;
  overflow: hidden;
}

.playback-toolbar {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.toolbar-group {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  min-width: 78px;
}

.mode-button {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  padding: 8px 12px;
}

.mode-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.toolbar-pill {
  display: inline-block;
  padding: 7px 10px;
  border: 1px solid rgba(34, 128, 91, 0.32);
  border-radius: 999px;
  color: #1e6a4c;
  background: rgba(236, 250, 244, 0.96);
  font-size: 13px;
  font-weight: 800;
}

.download-link {
  padding: 8px 12px;
  font-size: 14px;
}

.shift-panel {
  margin: 12px 0 14px;
  padding: 12px;
}

.shift-panel .hint {
  margin: 0 0 8px;
}

.shift-grid-compact {
  grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
  gap: 6px;
  margin-bottom: 0;
}

.shift-grid-compact .shift-option span {
  padding: 8px 0;
}

.cand-roll {
  display: block;
  width: 100%;
  height: 260px;
}

.playhead-overlay {
  position: absolute;
  top: 0;
  width: 2px;
  background: #f26f3e;
  left: 0;
  pointer-events: none;
}

.bar-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin: 14px 0 8px;
}

.bar-timeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(28px, 1fr));
  gap: 5px;
}

.bar-tick {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  padding: 6px 0;
  font-size: 12px;
}

.bar-tick.current {
  outline: 2px solid #f26f3e;
}

.bar-tick.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.pickup-tick {
  grid-column: span 2;
  border-color: rgba(34, 128, 91, 0.36);
  color: #1e6a4c;
  background: rgba(236, 250, 244, 0.96);
  font-weight: 800;
}

.bar-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.question-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.question-block legend {
  padding: 0 6px;
  font-weight: 700;
}

.choice-row {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 500;
  margin-bottom: 10px;
}

.shift-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.shift-option {
  position: relative;
}

.shift-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.shift-option span {
  display: block;
  padding: 10px 0;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
}

.shift-option input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.custom-shift-toggle {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 600;
  margin-top: 6px;
}

.custom-shift-wrap {
  margin-top: 12px;
}

.custom-shift-wrap input {
  width: 180px;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
}

.bar-panel {
  margin-top: 14px;
}

.clue-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.clue-box {
  min-height: 150px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
}

.decision-clue {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid #b8d8cc;
  border-left: 4px solid var(--beat);
  background: #eef8f4;
}

.decision-clue-warning {
  border-color: #e5bc88;
  border-left-color: var(--accent);
  background: #fff7eb;
}

.decision-clue small {
  flex-basis: 100%;
  color: var(--muted);
}

.clue-box h3 {
  margin: 0 0 10px;
}

.clue-chip,
.qa-flag {
  display: inline-block;
  margin: 4px 4px 4px 0;
  padding: 6px 9px;
  border: 1px solid rgba(184, 116, 39, 0.38);
  border-radius: 999px;
  color: var(--accent);
  background: rgba(255, 248, 235, 0.95);
  font-size: 13px;
  font-weight: 700;
}

.clue-chip.warn,
.qa-flag {
  border-color: rgba(207, 78, 67, 0.38);
  color: #a63a32;
  background: rgba(255, 238, 235, 0.96);
}

.candidate-time-chip {
  margin: 0 6px 8px 0;
  border-color: rgba(34, 128, 91, 0.42);
  background: rgba(236, 250, 244, 0.96);
  color: #1e6a4c;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  line-height: 1.15;
}

.candidate-time-chip small {
  color: inherit;
  font-size: 0.72em;
  font-weight: 700;
  opacity: 0.78;
}

.candidate-time-chip.selected,
.candidate-time-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  box-shadow: 0 0 0 2px rgba(184, 116, 39, 0.18);
}

.candidate-chip-row {
  margin: 8px 0 10px;
}

.warn-text {
  color: #a63a32;
  font-weight: 800;
}

.clue-label,
.field-help,
.position-preview {
  display: block;
}

.clue-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.field-help,
.position-preview {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.position-preview {
  color: #1e6a4c;
}

.qa-flag-wrap {
  margin-top: 12px;
}

.segmented-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
  gap: 8px;
}

.inline-field {
  margin-top: 12px;
}

.inline-actions,
.editable-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}

.editable-rows {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.editable-row button {
  width: 100%;
}

.structure-row {
  display: grid;
  grid-template-columns: minmax(92px, 0.7fr) repeat(3, minmax(110px, 1fr)) minmax(130px, 1fr) minmax(115px, 0.8fr);
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.58);
}

.structure-row button {
  width: 100%;
}

.chord-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.chord-table-wrap {
  display: grid;
  gap: 12px;
  max-height: 520px;
  overflow: auto;
  margin-bottom: 12px;
  padding-right: 4px;
}

.chord-bar-row {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.62);
}

.chord-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.chord-bar-number {
  color: var(--accent);
  font-size: 1.05rem;
  font-weight: 800;
}

.chord-hint-section,
.chord-more-hints,
.chord-edit-grid {
  min-width: 0;
}

.chord-hint-title {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.chord-hints {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chord-hints-main {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.chord-candidate-empty,
.chord-alt-button,
.chord-sub-alt-button,
.chord-event-hint-button {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 7px 9px;
  border: 1px solid rgba(34, 128, 91, 0.28);
  border-radius: 10px;
  color: #1e6a4c;
  background: rgba(236, 250, 244, 0.9);
  font-size: 12px;
  font-weight: 800;
  text-align: left;
  white-space: normal;
}

.chord-candidate-empty {
  opacity: 0.62;
}

.chord-alt-button strong,
.chord-sub-alt-button strong,
.chord-event-hint-button strong,
.chord-candidate-empty strong {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.1;
}

.chord-alt-button em,
.chord-sub-alt-button em,
.chord-event-hint-button em,
.chord-candidate-empty em {
  color: inherit;
  font-style: normal;
  font-size: 0.95rem;
  line-height: 1.15;
}

.chord-more-hints {
  padding: 8px 10px;
  border: 1px dashed rgba(184, 116, 39, 0.26);
  border-radius: 10px;
  background: rgba(255, 248, 235, 0.42);
}

.chord-more-hints summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 800;
}

.chord-hint-group {
  margin-top: 10px;
}

.chord-edit-grid {
  display: grid;
  grid-template-columns: minmax(140px, 1.1fr) repeat(2, minmax(86px, 0.65fr)) minmax(92px, 0.75fr) minmax(105px, 0.85fr) minmax(132px, 1fr) minmax(132px, 1fr);
  gap: 8px;
  align-items: end;
}

.chord-edit-grid label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.chord-bar-row input,
.chord-bar-row select,
.play-chord-button,
.split-chord-button,
.add-chord-slot-button,
.remove-chord-slot-button {
  margin-top: 0;
  padding: 8px 9px;
  border-radius: 10px;
}

.chord-row-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(92px, 160px));
  gap: 6px;
}

.chord-slot-rows {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
}

.chord-slot-row {
  display: grid;
  grid-template-columns: 74px repeat(2, minmax(72px, 0.55fr)) minmax(132px, 1fr) minmax(78px, 0.7fr) minmax(90px, 0.8fr) minmax(120px, 1fr) minmax(120px, 1fr) minmax(86px, 0.6fr);
  gap: 8px;
  align-items: center;
  padding: 7px;
  border: 1px dashed rgba(184, 116, 39, 0.36);
  border-radius: 10px;
  background: rgba(255, 248, 235, 0.72);
}

.chord-slot-label {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.irregular-hints {
  margin: 10px 0 12px;
}

.irregular-hints strong {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.irregular-region-row {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.58);
}

.irregular-region-header {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(110px, 0.35fr);
  gap: 10px;
  align-items: end;
}

.irregular-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
  align-items: end;
}

.irregular-grid button {
  width: 100%;
}

.section-number {
  align-self: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 248, 235, 0.95);
  color: var(--accent);
  font-weight: 800;
}

.choice-row-group {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
}

.qa-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.stat-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
}

.stat-card strong {
  display: block;
  font-size: 28px;
  line-height: 1;
  margin-bottom: 6px;
}

.admin-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.action-link {
  display: inline-block;
  padding: 10px 14px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  text-decoration: none;
  background: rgba(255, 248, 235, 0.95);
}

.table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th,
.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.admin-table th {
  color: var(--muted);
  font-size: 13px;
}

.admin-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

.admin-form-grid button {
  min-height: 44px;
}

.admin-table td:last-child {
  display: flex;
  gap: 6px;
  align-items: center;
}

.admin-table td:last-child form {
  display: flex;
  gap: 5px;
  align-items: center;
}

.admin-table .small-button {
  min-height: 36px;
  padding: 7px 10px;
  white-space: nowrap;
}

.admin-table td input,
.admin-table td select {
  min-width: 110px;
  padding: 7px 9px;
}

.auth-card {
  max-width: 560px;
  margin-inline: auto;
}

@media (max-width: 720px) {
  .container {
    width: min(1040px, calc(100% - 16px));
    margin-top: 16px;
  }

  .cand-roll {
    height: 210px;
  }

  .bar-timeline {
    grid-template-columns: repeat(auto-fit, minmax(22px, 1fr));
  }

  .structure-row {
    grid-template-columns: 1fr;
  }

  .chord-bar-row {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .chord-edit-grid {
    grid-template-columns: 1fr;
  }

  .chord-slot-row,
  .chord-row-actions {
    grid-template-columns: 1fr;
  }

  .admin-form-grid {
    grid-template-columns: 1fr;
  }
}
