#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  padding: 20px 24px 24px;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  animation: fadeInUp 0.35s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Difficulty-select and loading screens read better as a centered column;
   the in-game screen below intentionally breaks out of this to fill the width. */
.page-wrap {
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.screen-intro {
  color: var(--text-dim);
  line-height: 1.55;
}

/* Base .btn / .btn-ghost / .btn-accent live in the shared /styles.css - only
   this game's own submit-button variant is defined here. */

.btn-submit {
  background: var(--border);
  border-color: var(--border);
  color: var(--text-dim);
  font-weight: 600;
}

.btn-submit.ready {
  background: var(--green);
  border-color: var(--green);
  color: var(--on-green);
  cursor: pointer;
  opacity: 1;
  animation: readyPulse 0.6s ease-out;
}

@keyframes readyPulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 55%, transparent); }
  100% { box-shadow: 0 0 0 12px transparent; }
}

/* ---------- Difficulty select ---------- */

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  margin: 22px 0;
}

.difficulty-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.difficulty-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.difficulty-card:active { transform: translateY(0) scale(0.98); }

.difficulty-card img {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.difficulty-card .name {
  font-weight: 600;
  font-size: 1rem;
  display: block;
}

.difficulty-card .count {
  color: var(--text-dim);
  font-size: 0.82rem;
  font-family: var(--font-mono);
}

.custom-toggle {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 6px 0;
}

.custom-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-top: 10px;
  box-shadow: var(--shadow-sm);
  animation: fadeInUp 0.25s ease;
}

.field { margin-bottom: 20px; }

.field-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  margin-bottom: 6px;
}

.field-value { color: var(--accent); font-weight: 600; }

.field-hint {
  color: var(--text-dim);
  font-size: 0.78rem;
  margin: 6px 0 0;
  line-height: 1.4;
}

.custom-preview {
  color: var(--text-dim);
  font-size: 0.85rem;
  min-height: 1.2em;
}

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

/* Dual-range slider: two overlapping inputs sharing one track */
.dual-range { position: relative; height: 28px; }

.dual-range .track-bg {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  transform: translateY(-50%);
}

.dual-range .track-fill {
  position: absolute;
  top: 50%;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  transform: translateY(-50%);
}

.dual-range input[type="range"] {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  margin: 0;
  height: 28px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  pointer-events: none;
}

.dual-range input[type="range"]::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  background: transparent;
  height: 28px;
}

.dual-range input[type="range"]::-moz-range-track {
  background: transparent;
  height: 28px;
}

.dual-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  margin-top: 6px;
  cursor: pointer;
}

.dual-range input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
}

/* ---------- Loading ---------- */

#screen-loading {
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Game layout: left "Your List" panel + right tabbed panel,
   each filling the full height/width of its side. ---------- */

.game-layout {
  display: flex;
  gap: 18px;
  flex: 1;
  min-height: 0;
}

.list-panel,
.tabs-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.list-panel {
  flex: 0 0 clamp(300px, 34vw, 440px);
}

.tabs-panel {
  flex: 1 1 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.panel-header h2 {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

.panel-header .mono { font-size: 0.8rem; color: var(--text-dim); }

.rank-column {
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.rank-slot {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  min-height: 54px;
  flex-shrink: 0;
  transition: border-color 0.35s ease, background 0.35s ease;
}

.rank-slot.filled { border-style: solid; }
.rank-slot.drag-over { border-color: var(--accent); background: var(--bg); }
.rank-slot.selectable { border-color: var(--accent); cursor: pointer; }

.rank-slot.diff-0 { border-color: var(--green); background: color-mix(in srgb, var(--green) 16%, var(--bg-card)); }
.rank-slot.diff-1 { border-color: var(--yellow); background: color-mix(in srgb, var(--yellow) 16%, var(--bg-card)); }
.rank-slot.diff-near { border-color: var(--orange); background: color-mix(in srgb, var(--orange) 16%, var(--bg-card)); }
.rank-slot.diff-far { border-color: var(--red); background: color-mix(in srgb, var(--red) 18%, var(--bg-card)); }

.rank-slot .points-pop {
  position: absolute;
  top: -9px;
  right: 6px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  animation: popIn 0.3s ease-out;
}

@keyframes popIn {
  0% { transform: scale(0.3) translateY(4px); opacity: 0; }
  70% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); }
}

.rank-slot.diff-0 .points-pop { color: var(--green); border-color: var(--green); }
.rank-slot.diff-1 .points-pop { color: var(--yellow); border-color: var(--yellow); }
.rank-slot.diff-near .points-pop { color: var(--orange); border-color: var(--orange); }
.rank-slot.diff-far .points-pop { color: var(--red); border-color: var(--red); }

.rank-slot .rank-label {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  min-width: 46px;
  font-size: 0.85rem;
}

.rank-slot .rank-content { flex: 1; min-width: 0; }

.rank-slot .placeholder { color: var(--text-dim); font-size: 0.85rem; }

.list-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-shrink: 0;
}

.list-actions .btn { flex: 1; }

.panel-hint {
  color: var(--text-dim);
  font-size: 0.78rem;
  margin: 10px 0 0;
  line-height: 1.4;
  flex-shrink: 0;
}

/* ---------- Tabs panel ---------- */

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  flex-shrink: 0;
}

.tab-btn {
  font: inherit;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-btn:disabled { cursor: not-allowed; opacity: 0.55; }
.tab-btn:not(:disabled):hover { color: var(--text); }

.tab-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  animation: fadeIn 0.25s ease;
}

/* Cards are stacked in a single-column list, not a grid, and sized generously
   in the pool so thumbnails and names are easy to read at a glance. */
.pool-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 60px;
  border-radius: var(--radius);
  transition: background 0.15s ease;
}

.pool-grid.drag-over { background: var(--bg); }

.card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.card:hover:not(.dragging) { border-color: var(--accent); transform: translateY(-1px); }
.card.selected { outline: 2px solid var(--accent); outline-offset: 1px; animation: selectPulse 0.25s ease; }
.card.dragging { opacity: 0.35; }

@keyframes selectPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.card .thumb-wrap {
  position: relative;
  width: 130px;
  aspect-ratio: 16 / 9;
  flex-shrink: 0;
  background: #000;
  border-radius: 5px;
  overflow: hidden;
}

.card .thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.card .play-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  color: white;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.card .play-btn:hover { background: rgba(0, 0, 0, 0.8); transform: translate(-50%, -50%) scale(1.08); }

.card .card-body { flex: 1; min-width: 0; padding: 0 4px; }

.card .card-name {
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Compact variant for cards sitting inside a rank slot (left panel) - the
   pool list above is the one that should be big and easy to scan. */
.rank-slot .card {
  padding: 4px;
  gap: 8px;
  border: none;
  background: none;
  box-shadow: none;
}

.rank-slot .card:hover { transform: none; }
.rank-slot .card .thumb-wrap { width: 58px; border-radius: 4px; }
.rank-slot .card .play-btn { width: 22px; height: 22px; font-size: 0.65rem; border-width: 1px; }
.rank-slot .card .card-body { padding: 0; }
.rank-slot .card .card-name { font-size: 0.82rem; -webkit-line-clamp: 2; }
.rank-slot.filled .card { animation: dropPop 0.22s ease; }

@keyframes dropPop {
  0% { transform: scale(0.92); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- Correct List tab ---------- */

.reveal-banner {
  font-size: 0.92rem;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  min-height: 1.3em;
  color: var(--text-dim);
}

.correct-column { display: flex; flex-direction: column; gap: 7px; }

.correct-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  min-height: 44px;
  transition: border-color 0.4s ease, box-shadow 0.4s ease, transform 0.4s ease, background 0.4s ease;
}

.correct-row.empty {
  background: transparent;
  border-style: dashed;
}

.correct-row .rank-label {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  min-width: 46px;
  font-size: 0.85rem;
}

.correct-row .row-name {
  flex: 1;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.correct-row .placeholder { color: var(--text-dim); }

.correct-row.filling {
  transform: translateY(-4px);
  box-shadow: 0 0 0 2px var(--accent);
  animation: revealPop 0.4s ease;
}

@keyframes revealPop {
  0% { transform: scale(0.95) translateY(2px); opacity: 0.6; }
  60% { transform: scale(1.015) translateY(-4px); opacity: 1; }
  100% { transform: scale(1) translateY(-4px); }
}

.correct-tab-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  flex-shrink: 0;
}

.score-live { font-size: 1.05rem; font-weight: 700; display: inline-block; }
.score-live.bump { animation: scoreBump 0.3s ease; }

@keyframes scoreBump {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); color: var(--accent); }
  100% { transform: scale(1); }
}

/* ---------- Results (inline, inside Correct List tab) ---------- */

#results-panel {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  animation: fadeInUp 0.35s ease;
}

#results-panel h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.results-summary {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 4px 0 18px;
}

.results-summary .sub {
  display: block;
  font-size: 0.86rem;
  color: var(--text-dim);
  font-weight: 400;
  margin-top: 4px;
}

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

.results-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 4px;
  font-size: 0.85rem;
}

.results-table th,
.results-table td {
  text-align: left;
  padding: 9px 12px;
  white-space: nowrap;
}

.results-table th { color: var(--text-dim); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.4px; padding-top: 0; }

.results-table tbody tr { background: var(--bg-card); border: 1px solid var(--border); }
.results-table tbody tr td:first-child { border-top-left-radius: var(--radius); border-bottom-left-radius: var(--radius); border-left: 1px solid var(--border); }
.results-table tbody tr td:last-child { border-top-right-radius: var(--radius); border-bottom-right-radius: var(--radius); border-right: 1px solid var(--border); }
.results-table tbody tr td { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }

.results-table tr.diff-0 { background: color-mix(in srgb, var(--green) 14%, var(--bg-card)); border-color: var(--green); }
.results-table tr.diff-1 { background: color-mix(in srgb, var(--yellow) 14%, var(--bg-card)); border-color: var(--yellow); }
.results-table tr.diff-near { background: color-mix(in srgb, var(--orange) 14%, var(--bg-card)); border-color: var(--orange); }
.results-table tr.diff-far { background: color-mix(in srgb, var(--red) 16%, var(--bg-card)); border-color: var(--red); }

.results-table td.points-cell { font-family: var(--font-mono); font-weight: 700; }
.results-table tr.diff-0 td.points-cell { color: var(--green); }
.results-table tr.diff-1 td.points-cell { color: var(--yellow); }
.results-table tr.diff-near td.points-cell { color: var(--orange); }
.results-table tr.diff-far td.points-cell { color: var(--red); }

.results-actions {
  display: flex;
  gap: 12px;
  margin-top: 22px;
}

/* ---------- Video modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-content {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  width: min(90vw, 720px);
  box-shadow: var(--shadow-md);
  animation: modalPop 0.2s ease;
}

@keyframes modalPop {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
}

.modal-video-wrap iframe { width: 100%; height: 100%; border: 0; }

.modal-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.modal-close:hover { border-color: var(--accent); transform: scale(1.08); }

.modal-fallback-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.85rem;
}

/* Floating drag ghost */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 200;
  opacity: 0.92;
  transform: translate(-50%, -50%) scale(1.03);
  width: 260px;
  box-shadow: var(--shadow-md);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

@media (max-width: 820px) {
  .game-layout { flex-direction: column; }
  .list-panel { flex: 0 0 auto; max-height: 46vh; }
  .tabs-panel { flex: 1 1 auto; min-height: 300px; }
}
