:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #66727a;
  --line: #d8ded9;
  --paper: #f4f6f2;
  --surface: #ffffff;
  --teal: #0f766e;
  --teal-dark: #0c5953;
  --coral: #d85f45;
  --gold: #c9971a;
  --sage: #e9efe6;
  --shadow: 0 18px 48px rgba(23, 32, 38, 0.1);
  --soft-shadow: 0 8px 22px rgba(23, 32, 38, 0.07);
  --focus: 0 0 0 3px rgba(15, 118, 110, 0.2);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
  background: var(--paper);
}

button,
input,
select {
  font: inherit;
}

button,
.button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  font-weight: 700;
  text-decoration: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease, background 140ms ease;
}

button:hover,
.button:hover {
  border-color: #a9b6ae;
  box-shadow: 0 6px 16px rgba(23, 32, 38, 0.08);
  transform: translateY(-1px);
}

button:focus-visible,
.button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
  box-shadow: none;
}

.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.primary:hover {
  border-color: var(--teal-dark);
  background: var(--teal-dark);
}

.danger {
  border-color: #e7c8c1;
  color: #9f3521;
}

input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.app-shell {
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding: 18px 0 38px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto minmax(320px, 430px);
  align-items: center;
  gap: 18px;
  padding: 8px 0 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-canvas {
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 24px rgba(23, 32, 38, 0.1);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 3.4vw, 3.25rem);
  line-height: 0.96;
  letter-spacing: 0;
}

h2 {
  font-size: 1.45rem;
  line-height: 1.15;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--coral);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  gap: 8px;
  width: min(430px, 100%);
}

.stat-strip div,
.quiz-score div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  padding: 8px 11px;
}

.stat-strip span,
.quiz-score span {
  display: block;
  color: var(--ink);
  font-size: 1.22rem;
  font-weight: 850;
  line-height: 1;
}

small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

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

.view-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(112px, 1fr));
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 4px;
  box-shadow: var(--soft-shadow);
}

.view-tab {
  min-height: 42px;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-weight: 850;
}

.view-tab:hover {
  border-color: transparent;
  box-shadow: none;
  transform: none;
}

.view-tab.is-active {
  background: var(--ink);
  color: #ffffff;
}

.app-main {
  min-height: 70vh;
}

.view-panel[hidden] {
  display: none;
}

.play-view {
  min-height: calc(100vh - 142px);
  display: grid;
  align-items: start;
  padding-top: 8px;
}

.play-grid {
  display: grid;
  grid-template-columns: minmax(0, 920px);
  justify-content: center;
  gap: 14px;
  width: 100%;
}

.play-copy {
  order: 2;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 2px 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  box-shadow: none;
}

.play-copy h2 {
  max-width: none;
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1.1;
}

.play-copy .eyebrow {
  color: var(--coral);
}

.play-copy button {
  flex: 0 0 auto;
  width: fit-content;
  min-height: 36px;
}

.library-view {
  max-width: 1320px;
  margin: 0 auto;
}

.library-panel,
.quiz-panel {
  padding: 20px;
}

.quiz-panel {
  position: static;
}

.panel-heading,
.toolbar,
.section-heading,
.batch-bar,
.button-row,
.quiz-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-heading,
.toolbar,
.section-heading {
  justify-content: space-between;
}

.library-heading {
  margin-bottom: 14px;
}

h3 {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.15;
}

.library-section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.library-section + .library-section,
.library-section + .batch-bar,
.batch-bar + .table-wrap {
  margin-top: 14px;
}

.upload-section {
  background: #ffffff;
}

.review-section {
  background: #f7f9f5;
}

.backup-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.backup-actions button,
.backup-actions .button {
  min-height: 34px;
  padding: 7px 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.button-row {
  flex-wrap: wrap;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--teal);
  box-shadow: var(--focus);
}

.toggle-field {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  align-self: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  padding: 8px 10px;
}

.toggle-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.search-field {
  width: min(360px, 100%);
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.filter-chip {
  min-height: 34px;
  border-radius: 999px;
  padding: 7px 12px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.filter-chip.is-active {
  border-color: #bfd1ca;
  background: #e8f3f0;
  color: var(--teal-dark);
}

.batch-bar {
  margin: 14px 0;
  padding: 12px;
  border: 1px solid #cbd8d0;
  border-radius: 8px;
  background: var(--sage);
  flex-wrap: wrap;
}

.batch-bar[hidden] {
  display: none;
}

.batch-bar .compact {
  width: min(220px, 100%);
}

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

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: fixed;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef2ec;
  color: #344149;
  font-size: 0.78rem;
  font-weight: 850;
}

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

tbody tr.is-selected {
  background: #f1faf8;
}

.select-col {
  width: 64px;
}

.status-col {
  width: 132px;
}

.ai-col {
  width: 134px;
}

.thumb-col {
  width: 92px;
}

.thumb {
  width: 70px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2f4ef;
  object-fit: contain;
  display: block;
}

.inline-input {
  width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  padding: 8px 9px;
}

.inline-input:hover,
.inline-input:focus {
  border-color: var(--line);
  background: #ffffff;
  outline: none;
}

.status-pill {
  display: inline-flex;
  min-width: 90px;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 8px;
  background: #edf5f3;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-pill.needs-tags {
  background: #fff1df;
  color: #9b6400;
}

.ai-button {
  min-height: 36px;
  width: 100%;
  padding: 7px 10px;
}

.ai-note {
  display: inline-flex;
  margin-top: 6px;
  border-radius: 999px;
  background: #eef3ee;
  padding: 4px 7px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 44px 16px;
  color: var(--muted);
}

.empty-state canvas {
  width: min(260px, 82vw);
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.quiz-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin: 18px 0 14px;
}

.quiz-controls input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.quiz-controls label {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fbfcfa;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.quiz-controls label + input + label {
  border-left: 1px solid var(--line);
}

.quiz-controls input:checked + label {
  background: var(--ink);
  color: #ffffff;
}

.quiz-controls input:focus-visible + label {
  box-shadow: inset var(--focus);
}

.quiz-score {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.quiz-setup-row {
  display: grid;
  grid-template-columns: minmax(170px, 0.62fr) minmax(260px, 1fr);
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.quiz-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 360px;
  height: clamp(360px, 52svh, 620px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10181c;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(23, 32, 38, 0.03);
}

.quiz-stage.is-portrait {
  height: clamp(440px, 62svh, 700px);
}

.quiz-stage.is-landscape {
  height: clamp(320px, 48svh, 560px);
}

.quiz-stage canvas {
  position: absolute;
  inset: 14px;
  width: calc(100% - 28px);
  height: calc(100% - 28px);
  object-fit: contain;
}

.quiz-stage img {
  position: absolute;
  inset: 14px;
  display: none;
  width: calc(100% - 28px);
  height: calc(100% - 28px);
  object-fit: contain;
  object-position: center;
  border-radius: 6px;
}

.quiz-stage.has-image img {
  display: block;
}

.quiz-stage.has-image canvas {
  display: none;
}

.question-text {
  min-height: 60px;
  padding: 18px 0 12px;
  font-size: clamp(1.18rem, 2vw, 1.65rem);
  line-height: 1.2;
  font-weight: 850;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.answer-grid button {
  width: 100%;
  min-height: 58px;
  justify-content: flex-start;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  font-size: 1.02rem;
  padding: 13px 14px;
}

.answer-grid button.correct {
  border-color: var(--teal);
  background: #e5f4f1;
  color: var(--teal-dark);
}

.answer-grid button.wrong {
  border-color: #edc5ba;
  background: #fff1ee;
  color: #9f3521;
}

.quiz-actions {
  justify-content: space-between;
  margin-top: 12px;
}

.quiz-actions button {
  min-width: 130px;
}

.feedback {
  min-height: 24px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 750;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  max-width: min(560px, calc(100% - 24px));
  transform: translate(-50%, 120%);
  border: 1px solid rgba(23, 32, 38, 0.1);
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  box-shadow: 0 18px 45px rgba(23, 32, 38, 0.25);
  padding: 12px 16px;
  font-weight: 750;
  opacity: 0;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .view-switch {
    width: 100%;
  }

  .play-grid {
    grid-template-columns: 1fr;
    max-width: 820px;
    margin: 0 auto;
  }

  .play-copy h2 {
    max-width: none;
    font-size: 1.05rem;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: 100%;
    padding: 8px 10px 26px;
  }

  .panel-heading,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 6px 0 10px;
  }

  .brand-lockup {
    align-items: center;
    gap: 9px;
  }

  .brand-canvas {
    width: 44px;
    height: 44px;
  }

  h1 {
    font-size: 1.55rem;
    line-height: 1;
  }

  h2 {
    font-size: 1.28rem;
  }

  .eyebrow {
    font-size: 0.68rem;
  }

  .stat-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .quiz-score {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .stat-strip {
    gap: 6px;
  }

  .stat-strip div,
  .quiz-score div {
    padding: 6px 8px;
  }

  .stat-strip span,
  .quiz-score span {
    font-size: 1rem;
  }

  small {
    font-size: 0.72rem;
  }

  .view-switch {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    box-shadow: none;
  }

  .view-tab {
    min-height: 38px;
  }

  .app-main {
    min-height: 0;
  }

  .play-view {
    min-height: 0;
    align-items: start;
  }

  .play-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: none;
  }

  .play-copy {
    order: 2;
    flex-direction: column;
    align-items: stretch;
    gap: 9px;
    padding: 4px 2px 0;
  }

  .play-copy h2 {
    font-size: 1.25rem;
  }

  .play-copy button {
    width: 100%;
  }

  .library-panel,
  .quiz-panel {
    padding: 12px;
    box-shadow: 0 10px 28px rgba(23, 32, 38, 0.08);
  }

  .quiz-panel {
    order: 1;
  }

  .panel-heading {
    gap: 8px;
  }

  .quiz-panel .panel-heading {
    display: grid;
    grid-template-columns: 1fr;
  }

  .quiz-panel .panel-heading .primary {
    width: 100%;
    min-height: 46px;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .library-section {
    padding: 12px;
  }

  .backup-actions,
  .backup-actions button,
  .backup-actions .button {
    width: auto;
  }

  .backup-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .backup-actions button,
  .backup-actions .button {
    min-height: 34px;
    font-size: 0.78rem;
  }

  .upload-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 14px 0 12px;
  }

  .upload-grid .field:nth-child(3),
  .upload-grid .toggle-field {
    grid-column: 1 / -1;
  }

  .toggle-field {
    width: 100%;
    justify-content: center;
  }

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

  .panel-heading .button-row,
  .toolbar .button-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-field {
    width: 100%;
  }

  .quiz-controls {
    margin: 12px 0 10px;
  }

  .quiz-setup-row {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 10px;
  }

  .quiz-stage {
    min-height: 260px;
    height: clamp(280px, 42svh, 430px);
  }

  .quiz-stage.is-portrait {
    height: clamp(360px, 56svh, 560px);
  }

  .quiz-stage.is-landscape {
    height: clamp(250px, 38svh, 390px);
  }

  .question-text {
    min-height: 0;
    padding: 12px 0 9px;
    font-size: 1.12rem;
  }

  .answer-grid {
    grid-template-columns: 1fr;
  }

  .answer-grid button {
    min-height: 56px;
    padding: 14px;
  }

  .quiz-actions {
    gap: 10px;
    margin: 12px -4px 0;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(244, 246, 242, 0.94);
    backdrop-filter: blur(10px);
  }

  .quiz-actions button {
    flex: 1 1 0;
    min-width: 0;
  }

  .batch-bar {
    position: sticky;
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 4;
    align-items: stretch;
    margin: 12px 0;
    box-shadow: var(--shadow);
  }

  .batch-bar .compact,
  .batch-bar button {
    width: 100%;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
  }

  table,
  tbody {
    display: block;
    width: 100%;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody tr:not(.empty-row) {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 10px 12px;
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
  }

  tbody tr.is-selected {
    border-color: #9fc9c2;
    background: #f1faf8;
  }

  tbody tr:not(.empty-row) td {
    display: block;
    border-bottom: 0;
    padding: 0;
  }

  .thumb-col {
    grid-column: 1;
    grid-row: 1 / span 4;
    width: auto;
  }

  .thumb {
    width: 112px;
    border-radius: 8px;
  }

  .title-cell,
  .artist-cell,
  .museum-cell,
  .status-cell,
  .ai-cell {
    grid-column: 2;
  }

  .pick-cell {
    grid-column: 1;
    grid-row: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfa;
  }

  .title-cell::before,
  .artist-cell::before,
  .museum-cell::before,
  .status-cell::before,
  .ai-cell::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 850;
  }

  .inline-input {
    min-height: 36px;
    border-color: var(--line);
    background: #fbfcfa;
    padding: 7px 9px;
  }

  .status-pill {
    min-width: 0;
  }

  .ai-button {
    min-height: 38px;
  }

  .empty-row,
  .empty-row td {
    display: block;
    width: 100%;
  }

  .empty-state {
    padding: 30px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
  }
}
