
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,500;0,9..40,700;1,9..40,300&family=Playfair+Display:wght@700;900&display=swap');

:root {
  --bg: #1a1a2e;
  --bg2: #16213e;
  --surface: #0f3460;
  --accent: #e94560;
  --accent2: #f5a623;
  --text: #eaeaea;
  --text-dim: #8899aa;
  --shadow: rgba(0,0,0,0.5);
  --grid-line: rgba(255,255,255,0.015);
}

* { margin:0; padding:0; box-sizing:border-box; }

/* ---- Scrollbar (dark theme) ---- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.2); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.22); }
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.12) rgba(0,0,0,0.2); }

/* ---- Number spinner (dark theme) ---- */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  opacity: 1;
  filter: invert(0.85) hue-rotate(180deg);
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}

#toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--bg2);
  border-bottom: 1px solid rgba(233,69,96,0.2);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 1000;
  box-shadow: 0 4px 20px var(--shadow);
  transition: transform 0.3s ease;
}

#toolbar.autohide {
  transform: translateY(-100%);
}

#toolbar.autohide.show {
  transform: translateY(0);
}

.toolbar-spacer {
  flex: 1;
}

.btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 6px 14px;
  border-radius: 6px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--accent); border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: #d63050; }
.btn-icon {
  padding: 6px 8px;
  font-size: 18px;
  line-height: 1;
}

.toolbar-label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

.toolbar-input {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 13px;
  width: 70px;
  font-family: 'DM Sans', sans-serif;
}
.toolbar-input:focus { outline: none; border-color: var(--accent); }

select.toolbar-input {
  cursor: pointer;
  appearance: none;
  width: auto;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238899aa' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px;
}
select.toolbar-input option {
  background: var(--bg2);
  color: var(--text);
}

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

.toolbar-range {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  border: none;
  outline: none;
}
.toolbar-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.toolbar-range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

#selection-circle {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  border: 2px dashed rgba(233, 69, 96, 0.5);
  background: rgba(233, 69, 96, 0.06);
  transform: translate(-50%, -50%);
  display: none;
  z-index: 50;
}

#selection-circle.nudging {
  border-color: rgba(96, 160, 255, 0.6);
  background: rgba(96, 160, 255, 0.08);
}

.remote-selection-circle {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  left: 0;
  top: 0;
}

#toolbar.autohide + #canvas-container {
  top: 0;
}

#canvas-container {
  position: absolute;
  top: 56px; left: 0; right: 0; bottom: 0;
  transition: top 0.3s ease;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  -webkit-touch-callout: none;
  background:
    radial-gradient(circle at 20% 30%, rgba(15,52,96,0.4) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(233,69,96,0.08) 0%, transparent 40%),
    var(--bg);
}

#canvas-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

/* Board background variants */
#canvas-container[data-bg="midnight"] {
  --grid-line: rgba(255,255,255,0.025);
  background: #0d1117;
}
#canvas-container[data-bg="slate"] {
  --grid-line: rgba(255,255,255,0.04);
  background: #3a3d4a;
}
#canvas-container[data-bg="felt"] {
  --grid-line: rgba(255,255,255,0.03);
  background: radial-gradient(circle at 50% 50%, #1f5c35, #1a4a2a);
}
#canvas-container[data-bg="cork"] {
  --grid-line: rgba(0,0,0,0.05);
  background: linear-gradient(135deg, #8b7355, #a08060, #8b7355);
}
#canvas-container[data-bg="light"] {
  --grid-line: rgba(0,0,0,0.04);
  background: #d4d4d4;
}

#puzzle-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}

#info-overlay {
  position: fixed;
  bottom: 16px; left: 16px;
  background: rgba(22,33,62,0.9);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-dim);
  z-index: 999;
  line-height: 1.6;
  backdrop-filter: blur(8px);
  display: none;
}
#info-overlay.visible { display: block; }
#info-overlay kbd {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  font-family: 'DM Sans', sans-serif;
  border: 1px solid rgba(255,255,255,0.12);
}

#progress-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: rgba(255,255,255,0.05);
  z-index: 1001;
}
#progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  width: 0%;
  transition: width 0.4s ease;
}

/* ---- Settings Dropdown ---- */

#settings-anchor {
  position: relative;
}

.settings-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  background: var(--bg2);
  border: 1px solid rgba(233, 69, 96, 0.2);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 8px 30px var(--shadow);
  z-index: 1001;
  flex-direction: column;
  gap: 10px;
}
.settings-panel.open { display: flex; }

.settings-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.settings-label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.settings-info-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  margin-left: 4px;
  vertical-align: middle;
  line-height: 1;
}
.settings-info-btn:hover { color: var(--accent); }

.controls-list h4 {
  margin: 10px 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-family: 'Playfair Display', serif;
}
.controls-list h4:first-child { margin-top: 0; }
.controls-list ul {
  list-style: none;
  padding: 0;
  margin: 0 0 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.controls-list li { font-size: 13px; color: var(--text); }
.controls-list kbd {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  font-family: 'DM Sans', sans-serif;
  border: 1px solid rgba(255,255,255,0.12);
  margin-right: 2px;
}

.settings-input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  width: 100px;
}
.settings-input:focus { outline: none; border-color: var(--accent); }

select.settings-input {
  cursor: pointer;
  appearance: none;
  width: auto;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238899aa' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px;
}
select.settings-input option {
  background: var(--bg2);
  color: var(--text);
}

input[type=color].settings-input {
  width: 40px;
  height: 24px;
  padding: 2px;
  cursor: pointer;
}

.settings-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  border: none;
  outline: none;
}
.settings-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.settings-range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.settings-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 4px 0;
}

.settings-section-heading {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 0;
}

.settings-image-info {
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Toggle Switch ---- */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 18px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(255, 255, 255, 0.15);
  transition: background 0.2s;
  border-radius: 18px;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  height: 14px;
  width: 14px;
  left: 2px;
  top: 2px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
}
.toggle-switch input:focus-visible + .toggle-slider {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Action buttons inside settings panel */
.settings-btn-row {
  display: flex;
  gap: 6px;
}
.settings-action-btn {
  flex: 1;
  text-align: left;
}

/* ---- Reference Image Overlay ---- */

.ref-overlay {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  padding: 12px;
}
.ref-overlay img {
  width: 100%;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
.ref-overlay.corner-top-left     { top: 0; left: 0; }
.ref-overlay.corner-top-right    { top: 0; right: 0; }
.ref-overlay.corner-bottom-left  { bottom: 0; left: 0; }
.ref-overlay.corner-bottom-right { bottom: 0; right: 0; }

.toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 3000;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ---- AI Generate Modal ---- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }

.modal-card {
  background: var(--bg2);
  border: 1px solid rgba(233, 69, 96, 0.2);
  border-radius: 12px;
  width: 420px;
  max-width: 90vw;
  max-height: 90vh;
  max-height: 90dvh;
  box-shadow: 0 8px 40px var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.modal-title {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}

.modal-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.modal-input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  width: 100%;
}
.modal-input:focus { outline: none; border-color: var(--accent); }
.modal-input::placeholder { color: var(--text-dim); opacity: 0.6; }

select.modal-input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238899aa' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
select.modal-input option {
  background: var(--bg2);
  color: var(--text);
}
select.modal-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.modal-field-status {
  font-size: 11px;
  color: var(--text-dim);
  min-height: 14px;
  line-height: 14px;
}
.modal-field-status.error { color: var(--accent); }
.modal-field-status.success { color: #2a9d4a; }

.comfyui-url-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.comfyui-url-row > input {
  flex: 1;
  min-width: 0;
}

.modal-spoiler-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 2px;
}
.modal-spoiler {}

.modal-spoiler summary {
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  user-select: none;
}
.modal-spoiler summary::-webkit-details-marker { display: none; }
.modal-spoiler summary::before {
  content: '\25b6';
  font-size: 8px;
  transition: transform 0.15s;
}
.modal-spoiler[open] summary::before {
  transform: rotate(90deg);
}

.modal-prompt-preview {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.4;
  padding: 8px 0 2px;
}

.modal-reroll {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  border-radius: 5px;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.modal-reroll:hover { color: var(--accent); border-color: var(--accent); }

.modal-ai-generate-btn {
  width: 100%;
  padding: 8px;
  font-size: 13px;
  margin-top: 4px;
}

#ai-preview-spoiler > summary {
  display: flex;
  align-items: center;
}
.ai-preview-status {
  color: #2ecc71;
  font-size: 11px;
  font-weight: 500;
  margin-left: auto;
}

.modal-generate-btn {
  margin-top: 8px;
  width: 100%;
  padding: 10px;
  font-size: 14px;
}

.modal-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  padding: 12px 0;
  color: var(--text-dim);
  font-size: 13px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.modal-error {
  color: var(--accent);
  font-size: 12px;
  padding: 8px 12px;
  background: rgba(233, 69, 96, 0.1);
  border-radius: 6px;
  border: 1px solid rgba(233, 69, 96, 0.2);
}

.modal-source-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-separator {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 8px 0;
}

.modal-subheader {
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.65;
  margin: 4px 0 2px;
}

.interface-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.story-piece-mode {
  border: none;
  padding: 0;
  margin: 0 0 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.story-piece-mode .radio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  padding: 2px 0;
}
.story-piece-mode .radio-row input[type="radio"] {
  margin: 0;
  cursor: pointer;
}

.tiling-description {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
  margin: 4px 0 2px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
}

.prototile-preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}
.prototile-preview:empty { display: none; }
.prototile-preview .slot {
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
  min-width: 0;
}
.prototile-preview .svg-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.prototile-preview .svg-wrap svg {
  width: 100%;
  height: 100%;
  max-height: 100%;
}
.prototile-preview .label {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  text-align: center;
}

.modal-upload-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
}
.modal-upload-preview img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
}
.modal-upload-preview span {
  font-size: 12px;
  color: var(--text-dim);
}

input[type="file"].modal-input {
  padding: 8px;
  cursor: pointer;
}
input[type="file"].modal-input::file-selector-button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 4px 12px;
  border-radius: 5px;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  cursor: pointer;
  margin-right: 8px;
}

/* ---- Multiplayer ---- */

.mp-modal-card {
  width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.mp-modal-card .modal-body {
  overflow-y: auto;
  flex: 1;
}

.mp-status-active {
  color: #2ecc71 !important;
  font-weight: 500;
}
.mp-status-connected {
  color: var(--accent2) !important;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.mp-browser-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.btn-icon-prefix {
  display: inline-block;
  margin-right: 4px;
  font-size: 13px;
  line-height: 1;
  opacity: 0.85;
}

.mp-create-form {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}
.mp-create-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.mp-session-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
}

.mp-loading {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 20px;
}

.mp-session-card {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 10px;
  transition: border-color 0.15s;
  min-height: 110px;
}
.mp-session-card:hover {
  border-color: rgba(233, 69, 96, 0.3);
}
.mp-card-row {
  display: flex;
  gap: 12px;
}

.mp-card-thumb {
  flex-shrink: 0;
  position: relative;
  align-self: stretch;
  width: 140px;
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.mp-card-thumb[data-no-thumb] { cursor: default; }
.mp-card-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.mp-card-thumb .mp-no-thumb {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mp-no-thumb {
  font-size: 11px;
  color: var(--text-dim);
}

.mp-card-expanded-thumb {
  display: none;
  margin-top: 10px;
  border-radius: 6px;
  overflow: hidden;
}
.mp-card-expanded-thumb img {
  width: 100%;
  display: block;
  border-radius: 6px;
}
.mp-session-card.expanded .mp-card-expanded-thumb {
  display: block;
}

.mp-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.mp-card-title {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.mp-card-meta {
  font-size: 11px;
  color: var(--text-dim);
}
.mp-card-users {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
.mp-user-stat {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 3px;
}
.mp-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.mp-active-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2ecc71;
  flex-shrink: 0;
}
.mp-inactive-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  opacity: 0.4;
  flex-shrink: 0;
}

.mp-session-header {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  margin-bottom: 8px;
}

.mp-session-users {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.mp-session-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
}
.mp-user-pieces {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-dim);
}

/* ---- Competitive mode: create-form radio ---- */

.mp-mode-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  margin-bottom: 4px;
}
.mp-mode-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.mp-mode-option:hover {
  border-color: rgba(233, 69, 96, 0.3);
}
.mp-mode-option input[type="radio"] {
  margin-top: 2px;
}
.mp-mode-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.3;
}
.mp-mode-label strong {
  font-size: 12px;
  color: var(--text);
}
.mp-mode-label small {
  font-size: 11px;
  color: var(--text-dim);
}

/* ---- Competitive mode: session card badge ---- */

.mp-mode-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.mp-mode-coop {
  background: rgba(70, 150, 230, 0.18);
  color: #7ab5ef;
  border: 1px solid rgba(70, 150, 230, 0.35);
}
.mp-mode-race {
  background: rgba(233, 69, 96, 0.18);
  color: #ff7a90;
  border: 1px solid rgba(233, 69, 96, 0.4);
}
.mp-mode-story {
  background: rgba(46, 204, 113, 0.18);
  color: #7fdf9e;
  border: 1px solid rgba(46, 204, 113, 0.4);
}

.mp-race-stat.done { color: #2ecc71; }
.mp-race-stat.paused { opacity: 0.6; }

/* ---- Competitive mode: session modal player table rows ---- */

.mp-race-row {
  display: grid;
  grid-template-columns: 14px 1fr auto auto auto;
  gap: 10px;
  align-items: center;
}
.mp-race-row.done { border: 1px solid rgba(46, 204, 113, 0.35); }
.mp-race-row.paused { opacity: 0.7; }
.mp-race-row .mp-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  opacity: 0.4;
}
.mp-race-row .mp-dot.active { background: #2ecc71; opacity: 1; }
.mp-race-row.done .mp-dot.active { background: #2ecc71; }
.mp-race-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.mp-race-pieces { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.mp-race-time {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.mp-race-status {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  min-width: 56px;
  text-align: right;
}
.mp-race-row.done .mp-race-status { color: #2ecc71; }
.mp-race-row.paused .mp-race-status { color: #c49750; }

/* ---- Competitive mode: in-game progress overlay ---- */

.mp-race-overlay {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  display: grid;
  grid-template-columns: max-content 1fr 8ch;
  gap: 4px 10px;
  pointer-events: none;
  z-index: 60;
}
.mp-race-bar {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  align-items: center;
  padding: 4px 10px;
  background: rgba(10, 15, 25, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.mp-race-bar.paused { opacity: 0.55; }
.mp-race-bar.done { border-color: rgba(46, 204, 113, 0.5); }
.mp-race-bar-name {
  font-weight: 600;
  white-space: nowrap;
}
.mp-race-bar-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
}
.mp-race-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #e94560 0%, #ff7a90 100%);
  transition: width 0.25s ease-out;
}
.mp-race-bar.done .mp-race-bar-fill {
  background: linear-gradient(90deg, #2ecc71 0%, #55e090 100%);
}
.mp-race-bar-time {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--text-dim);
  min-width: 8ch;
  text-align: right;
}
.mp-race-bar.done .mp-race-bar-time { color: #2ecc71; }

/* Hide the single-player progress bar while in a race session */
body.mp-race-active #progress-bar { display: none; }

/* "Hide Progress Bars" user setting — hides both single-player and race bars in all modes */
body.hide-progress-bars #progress-bar,
body.hide-progress-bars .mp-race-overlay { display: none !important; }

/* ---- Remote Cursors ---- */

.remote-cursor {
  position: absolute;
  pointer-events: none;
  z-index: 100;
  transition: left 0.1s linear, top 0.1s linear;
}
.remote-cursor svg {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}
.cursor-label {
  position: absolute;
  left: 14px;
  top: 14px;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* ---- Mobile Menu ---- */

#mobile-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 16px;
  width: 260px;
  background: var(--bg2);
  border: 1px solid rgba(233, 69, 96, 0.2);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 8px 30px var(--shadow);
  flex-direction: column;
  gap: 10px;
  z-index: 1001;
}
#mobile-menu.open { display: flex; }
#mobile-menu .btn { width: 100%; text-align: center; }
#mobile-menu .toolbar-spacer { display: none; }
#mobile-menu .toolbar-slider-group { width: 100%; }
#mobile-menu .toolbar-range { flex: 1; }

.menu-row {
  display: flex;
  gap: 10px;
}
.menu-row .btn { flex: 1; }

/* ---- Hamburger Button ---- */

#btn-menu {
  background: none;
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 18px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}

/* ---- Touch-friendly tap targets ---- */

@media (pointer: coarse) {
  .btn { min-height: 44px; min-width: 44px; padding: 10px 16px; font-size: 14px; }
  .btn-icon { min-height: 44px; min-width: 44px; padding: 10px; font-size: 20px; }
  .btn-sm { min-height: 40px; padding: 8px 14px; font-size: 13px; }
  .modal-close { min-height: 44px; min-width: 44px; font-size: 28px; display: flex; align-items: center; justify-content: center; }
  .toolbar-range::-webkit-slider-thumb { width: 24px; height: 24px; }
  .toolbar-range::-moz-range-thumb { width: 24px; height: 24px; }
  .settings-range::-webkit-slider-thumb { width: 24px; height: 24px; }
  .settings-range::-moz-range-thumb { width: 24px; height: 24px; }
  .modal-input { padding: 10px 12px; font-size: 14px; }
  .modal-generate-btn { padding: 12px; font-size: 15px; }
  #toolbar { gap: 8px; }
}

/* ---- Tablet (481-767px) ---- */

@media (max-width: 767px) {
  #toolbar { gap: 8px; padding: 0 10px; }
  .toolbar-range { width: 80px; }
  #toolbar > .toolbar-spacer { display: none; }
}

/* ---- Phone (<=480px) ---- */

@media (max-width: 480px) {
  #toolbar {
    height: 50px;
    padding: 0 8px;
    gap: 6px;
    flex-wrap: nowrap;
  }

  #canvas-container { top: 50px; }
  #toolbar.autohide + #canvas-container { top: 0; }

  #mobile-menu {
    top: 50px;
    left: 0;
    right: 0;
    width: auto;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid rgba(233,69,96,0.2);
    padding: 12px;
    box-shadow: 0 4px 20px var(--shadow);
  }

  .toolbar-spacer { flex: 1; }

  /* Settings as bottom sheet on phone */
  .settings-panel {
    position: fixed !important;
    top: auto !important;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100% !important;
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px 12px 0 0;
    z-index: 2001;
  }

  /* Modals full-width */
  .modal-card, .mp-modal-card { max-width: 95vw; }
  .modal-body { padding: 16px; }

  /* Info overlay: wrap lines */
  #info-overlay {
    left: 8px;
    right: 8px;
    bottom: 8px;
    font-size: 11px;
    line-height: 1.8;
  }

  /* Remote cursors: smaller on mobile */
  .cursor-label {
    font-size: 8px;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Toast below compact toolbar */
  .toast { top: 58px; }
}

/* ============================================================
   VR MODE
   ============================================================ */

#btn-vr {
  font-size: 13px;
  padding: 6px 12px;
  white-space: nowrap;
}

#vr-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
}

.vr-active #mobile-menu,
.vr-active #piece-info,
.vr-active #btn-fit-view,
.vr-active #settings-anchor,
.vr-active #selection-size-group {
  display: none !important;
}

/* ============================================================
   LIBRARY GRID
   ============================================================ */

.library-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.story-source-toolbar #story-breadcrumb {
  flex: 1;
  font-size: 13px;
  color: var(--text-dim);
  align-self: flex-end;
  padding-bottom: 2px;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
  padding: 2px;
}

.library-card {
  background: rgba(255,255,255,0.04);
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  transition: border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.library-card:hover {
  border-color: rgba(233,69,96,0.3);
}

.library-card.selected {
  border-color: var(--accent);
}

.library-card.loading {
  opacity: 0.6;
  pointer-events: none;
}

.library-card-thumb {
  position: relative;
}

.library-card-thumb img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  border-radius: 4px;
  background: rgba(0,0,0,0.2);
}

.library-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.library-card:hover .library-delete-btn {
  opacity: 1;
}

.library-delete-btn:hover {
  color: #fff;
}

.library-card-info {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.3;
}

.library-card-name {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#confirm-modal,
#prompt-modal,
#loading-modal {
  z-index: 2100;
}

.confirm-modal-card,
.prompt-modal-card {
  max-width: 340px;
}

.loading-modal-card { max-width: 360px; }
.loading-modal-body {
  flex-direction: row;
  align-items: center;
  gap: 14px;
  padding: 20px 22px;
}
.loading-modal-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.loading-modal-text .modal-title { font-size: 15px; }
.loading-modal-text .modal-label { margin-top: 0; }
#loading-modal .modal-label:empty { display: none; }

.mp-card-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 4px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1;
  vertical-align: middle;
}
.mp-card-edit-btn:hover { color: var(--text); }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.library-loading,
.library-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ---- Leaderboard modal ---- */
.lb-modal-card {
  max-width: 620px;
  width: 100%;
}

.lb-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 10px;
}

.lb-tab {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 14px;
  border-radius: 6px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.lb-tab:hover {
  border-color: var(--accent);
  color: var(--text);
}

.lb-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.lb-table thead th {
  text-align: left;
  padding: 8px 10px;
  color: var(--text-dim);
  font-weight: 500;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  user-select: none;
}

.lb-table th[data-sort] {
  cursor: pointer;
}

.lb-table th[data-sort]:hover {
  color: var(--text);
}

.lb-table th.active {
  color: var(--accent);
}

.lb-table th.lb-col-rank { width: 40px; text-align: center; }
.lb-table th.lb-col-user { }
.lb-table th.lb-col-num { text-align: right; width: 90px; }

.lb-row td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.lb-rank {
  text-align: center;
  color: var(--text-dim);
}

.lb-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.lb-row:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.lb-row-self td {
  background: rgba(233, 69, 96, 0.12);
  color: var(--text);
  font-weight: 500;
}

.lb-row-self:hover td {
  background: rgba(233, 69, 96, 0.18);
}

.lb-row-self .lb-rank {
  color: var(--accent);
}

.lb-empty {
  text-align: center;
  padding: 24px;
  color: var(--text-dim);
}

/* ---- Admin panel modal ---- */
.admin-modal-card {
  max-width: 820px;
  width: 100%;
}

.admin-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 10px;
  flex-wrap: wrap;
}

.admin-tab {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 14px;
  border-radius: 6px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.admin-tab:hover {
  border-color: var(--accent);
  color: var(--text);
}

.admin-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.admin-pane {
  font-size: 13px;
}

.admin-pane-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.admin-help {
  color: var(--text-dim);
  font-size: 12px;
  margin: 0 0 10px 0;
}

.admin-section-heading {
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  color: var(--accent);
  margin: 0 0 8px 0;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.admin-table thead th {
  text-align: left;
  padding: 6px 8px;
  color: var(--text-dim);
  font-weight: 500;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  user-select: none;
}

.admin-table tbody td {
  padding: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

.admin-table .admin-col-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  width: 70px;
}

.admin-table .admin-col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

.admin-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
}

.admin-cell-label {
  font-weight: 500;
}

.admin-cell-dim {
  color: var(--text-dim);
}

.admin-cell-key {
  font-family: 'Courier New', monospace;
  font-size: 11px;
}

.admin-priv-pill {
  display: inline-block;
  padding: 2px 7px;
  margin: 1px;
  background: rgba(233, 69, 96, 0.12);
  border: 1px solid rgba(233, 69, 96, 0.25);
  border-radius: 10px;
  font-size: 11px;
  color: var(--text);
}

.admin-priv-none {
  color: var(--text-dim);
  font-style: italic;
  font-size: 11px;
}

.admin-icon-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 4px 7px;
  margin-left: 3px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}

.admin-icon-btn:hover {
  border-color: var(--accent);
}

.admin-icon-btn.admin-danger:hover {
  background: rgba(233, 69, 96, 0.18);
  border-color: var(--accent);
}

.btn.admin-danger {
  background: rgba(233, 69, 96, 0.15);
  border-color: rgba(233, 69, 96, 0.3);
}

.btn.admin-danger:hover {
  background: var(--accent);
}

.admin-new-key-form {
  margin-top: 16px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
}

.admin-label {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  margin: 8px 0 4px;
}

.admin-input {
  width: 100%;
  background: var(--bg1);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  box-sizing: border-box;
}

.admin-input:focus {
  outline: none;
  border-color: var(--accent);
}

.admin-privs-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 6px 0 10px;
}

.admin-privs-list-compact {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.admin-priv-option {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.admin-priv-option input {
  margin: 0;
}

.admin-priv-option-name {
  font-family: 'Courier New', monospace;
  color: var(--text);
  min-width: 130px;
}

.admin-priv-option-summary {
  color: var(--text-dim);
  font-size: 11px;
  flex: 1;
}

.admin-health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.admin-health-stat {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 12px;
}

.admin-health-label {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.admin-health-value {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.admin-edit-form {
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 6px;
}

.admin-key-reveal {
  font-family: 'Courier New', monospace;
  background: rgba(233, 69, 96, 0.08);
  border: 1px solid rgba(233, 69, 96, 0.25);
  border-radius: 6px;
  padding: 12px;
  word-break: break-all;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 12px;
  user-select: all;
}

.admin-cleanup-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.admin-cleanup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0;
}

/* ============================================================
   Story Mode
   ============================================================ */

#story-setup-modal textarea.modal-input {
  resize: vertical;
  min-height: 44px;
  font-family: 'DM Sans', sans-serif;
  line-height: 1.4;
}

.story-log-panel {
  position: fixed;
  top: 56px;
  right: 0;
  bottom: 0;
  width: var(--story-log-width, 340px);
  max-width: 92vw;
  background: var(--bg2);
  border-left: 1px solid rgba(233, 69, 96, 0.2);
  box-shadow: -8px 0 30px var(--shadow);
  /* Below the toolbar (1000) + settings-panel (1001 inside toolbar context)
     so the settings panel can overlay the story log when both are open. */
  z-index: 999;
  transform: translateX(calc(100% + 40px));
  transition: transform 0.3s ease, top 0.3s ease;
  display: flex;
  flex-direction: column;
}
.story-log-panel.open { transform: translateX(0); }

/* When the toolbar auto-hides, stretch the panel to fill the full height.
   Same sibling-selector pattern used by #canvas-container above. */
#toolbar.autohide ~ .story-log-panel { top: 0; }

.story-log-panel.left {
  left: 0;
  right: auto;
  border-left: none;
  border-right: 1px solid rgba(233, 69, 96, 0.2);
  box-shadow: 8px 0 30px var(--shadow);
  transform: translateX(calc(-100% - 40px));
}
.story-log-panel.left.open { transform: translateX(0); }

.story-log-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 6px;
  cursor: ew-resize;
  z-index: 1;
  background: transparent;
  transition: background 0.15s ease;
}
.story-log-panel.left .story-log-resize-handle {
  left: auto;
  right: 0;
}
.story-log-resize-handle:hover,
body.story-log-resizing .story-log-resize-handle {
  background: var(--accent);
  opacity: 0.35;
}
body.story-log-resizing {
  cursor: ew-resize;
  user-select: none;
}
@media (pointer: coarse) {
  .story-log-resize-handle { width: 12px; }
}

.story-log-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.story-log-title {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  line-height: 1.2;
}
.story-log-logline {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.4;
  margin-top: 4px;
}

.story-log-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.story-log-footer {
  padding: 10px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.story-log-footer-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.story-log-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 12px;
}
.story-log-progress-label { flex: 0 0 auto; }
.story-log-progress-bar {
  flex: 1 1 auto;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}
.story-log-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.3s ease;
}

.story-chapters-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.story-chapter-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  position: relative;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, opacity 0.2s;
}
.story-chapter-card:not(.collapsed) { cursor: default; }
.story-chapter-card[data-state="future"]    { opacity: 0.55; }
.story-chapter-card[data-state="current"]   { border-color: var(--accent); background: rgba(233, 69, 96, 0.06); }
.story-chapter-card[data-state="completed"] { border-color: rgba(46, 204, 113, 0.35); }

/* Full title (expanded state): centered above the wrap-around content. */
.story-chapter-title {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  line-height: 1.25;
  text-align: center;
  user-select: none;
}
.story-chapter-card[data-state="completed"] .story-chapter-title::after {
  content: '  \2713';
  color: #2ecc71;
  font-family: 'DM Sans', sans-serif;
}
.story-chapter-card.collapsed .story-chapter-title { display: none; }

/* Compact 2-line heading (collapsed state): flows to the right of the floated
   thumb. Kept at ~60px height so the card doesn't grow taller than the thumb. */
.story-chapter-heading {
  user-select: none;
}
.story-chapter-card:not(.collapsed) .story-chapter-heading { display: none; }

.story-chapter-number {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.25;
  color: var(--text);
}
.story-chapter-card[data-state="completed"] .story-chapter-number::after {
  content: '  \2713';
  color: #2ecc71;
  font-family: 'DM Sans', sans-serif;
}

.story-chapter-name {
  font-family: 'Playfair Display', serif;
  font-weight: 600;
  font-size: 12px;
  line-height: 1.3;
  color: var(--text-dim);
  margin-top: 2px;
}
.story-chapter-name:empty { display: none; }

/* Magazine-style layout: thumbnail floats left, text wraps around + under. */
.story-chapter-content {
  min-width: 0;
}
.story-chapter-content::after {
  content: '';
  display: block;
  clear: both;
}

.story-chapter-thumb {
  float: left;
  margin: 2px 10px 4px 0;
  width: 80px;
  height: 60px;
  border-radius: 5px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 18px;
}
/* Expanded cards get a larger thumbnail as the panel widens — 30% of the card
   content width, clamped to the collapsed size (80px) as a minimum. */
.story-chapter-card:not(.collapsed) .story-chapter-thumb {
  width: max(80px, 30%);
  height: auto;
  aspect-ratio: 4 / 3;
}

.story-chapter-card.collapsed .story-chapter-text,
.story-chapter-card.collapsed .story-chapter-hint,
.story-chapter-card.collapsed .story-chapter-actions {
  display: none;
}
/* Filter on children + overflow:hidden on parent clips the blur halo at the
   thumb's border. Applying the filter directly to .story-chapter-thumb would
   spill beyond the 80x60 box regardless of overflow. */
.story-chapter-img,
.story-chapter-thumb-state {
  filter: blur(var(--story-blur, 0px));
  transition: filter 0.6s ease-out;
}
.story-chapter-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.story-chapter-thumb[data-status="ready"],
.story-chapter-thumb[data-status="ready"] .story-chapter-img {
  cursor: zoom-in;
}
.story-chapter-thumb-state { line-height: 1; }
.story-chapter-thumb-locked { font-size: 22px; font-weight: 700; color: var(--text-dim); }

.story-chapter-text {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.45;
}
.story-chapter-text p {
  margin: 0 0 0.6em;
}
.story-chapter-text p:last-child {
  margin-bottom: 0;
}
.story-chapter-text p + p {
  text-indent: 1.5em;
}
.story-chapter-text-read   { color: var(--text-dim); }
.story-chapter-text-unread { color: #b9c2ca; }
.story-chapter-card[data-state="current"].has-unread .story-chapter-text,
.story-chapter-card[data-state="completed"].has-unread .story-chapter-text {
  cursor: pointer;
}

.story-chapter-hint {
  display: none;
  font-size: 11px;
  font-style: italic;
  color: var(--text-dim);
  text-align: center;
  margin-top: 4px;
  user-select: none;
}
.story-chapter-card[data-state="current"].has-unread:not(.collapsed) .story-chapter-hint,
.story-chapter-card[data-state="completed"].has-unread:not(.collapsed) .story-chapter-hint {
  display: block;
}

.story-chapter-actions {
  margin-top: 2px;
}
.story-chapter-actions .btn {
  font-size: 11px;
  padding: 3px 8px;
}
.story-chapter-actions:empty { display: none; }
.story-chapter-card[data-state="current"] .story-chapter-thumb[data-status="failed"] {
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* Translucent chevron overlay; not a framed button. Horizontally centered in
   both states; absolutely positioned when collapsed so the card height stays
   flush with the thumbnail. */
.story-chapter-toggle {
  background: transparent;
  border: none;
  padding: 2px 10px;
  color: var(--text-dim);
  opacity: 0.45;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  align-self: center;
  transition: opacity 0.15s;
}
.story-chapter-toggle:hover { opacity: 0.9; }
.story-chapter-card.collapsed .story-chapter-toggle::before { content: '\25BE'; }
.story-chapter-card:not(.collapsed) .story-chapter-toggle::before { content: '\25B4'; }
.story-chapter-card.collapsed .story-chapter-toggle {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  margin: 0;
  align-self: auto;
}

.story-advance-gate.story-ready-gate {
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.story-ready-gate .btn.story-ready-self {
  background: rgba(46, 204, 113, 0.18);
  color: #7fdf9e;
  border-color: rgba(46, 204, 113, 0.5);
}
.story-ready-caption {
  font-size: 11px;
  color: var(--text-dim, #8a8f9a);
  font-style: italic;
}
.story-ready-players {
  list-style: none;
  padding: 0;
  margin: 2px 0 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  max-width: 220px;
}
.story-ready-player {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid transparent;
}
.story-ready-player .story-ready-check {
  width: 14px;
  text-align: center;
  color: transparent;
}
.story-ready-player.ready {
  color: #7fdf9e;
  background: rgba(46, 204, 113, 0.1);
  border-color: rgba(46, 204, 113, 0.4);
}
.story-ready-player.ready .story-ready-check {
  color: #7fdf9e;
}
.mp-create-story-picker {
  margin-top: 10px;
  border-top: 1px solid var(--border, rgba(255,255,255,0.08));
  padding-top: 10px;
}
.mp-create-story-picker .library-grid {
  max-height: 260px;
  overflow-y: auto;
  margin: 4px 0 8px;
}
.mp-create-story-piece-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
.mp-create-story-piece-row input {
  max-width: 100px;
}

.story-advance-gate {
  display: flex;
  justify-content: center;
  padding: 4px 0;
}
.story-advance-gate .btn {
  font-size: 12px;
  padding: 6px 14px;
}

.spinner-tiny {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@media (max-width: 480px) {
  .story-log-panel {
    width: 100vw;
    max-width: 100vw;
  }
  .story-log-resize-handle { display: none; }
}

/* ============================================================
   STORY LIBRARY
   ============================================================ */

.story-library-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.story-library-card .library-card-thumb img {
  aspect-ratio: 4/3;
}

.story-card-logline {
  font-style: italic;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.3;
  max-height: 2.6em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin: 2px 0;
}

/* ============================================================
   STORY COMPLETE OVERLAY
   ============================================================ */

.puzzle-complete-overlay {
  z-index: 2050;
  padding: 20px;
}

.puzzle-complete-card {
  position: relative;
  width: min(440px, 92vw);
  padding: 32px 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: linear-gradient(160deg, rgba(22, 33, 62, 0.95), rgba(10, 15, 35, 0.96));
  border: 1px solid rgba(245, 166, 35, 0.3);
  border-radius: 16px;
  box-shadow: 0 12px 50px var(--shadow), 0 0 60px rgba(245, 166, 35, 0.15);
}

.puzzle-complete-card .modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
}

.puzzle-complete-kicker {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent2);
  font-weight: 600;
}

.puzzle-complete-title {
  margin: 0;
  font-size: clamp(1.4rem, 3vw, 2rem);
  line-height: 1.15;
  text-align: center;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.puzzle-complete-stats {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 4px 0 12px;
  width: 100%;
  max-width: 280px;
  font-size: 0.95rem;
}

.puzzle-complete-stats dt {
  color: var(--text-dim);
  font-weight: 500;
}

.puzzle-complete-stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.puzzle-complete-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.story-complete-overlay {
  z-index: 2100;
  padding: 20px;
}

.story-complete-card {
  position: relative;
  width: min(1100px, 95vw);
  max-height: 92vh;
  overflow-y: auto;
  padding: 36px 28px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: linear-gradient(160deg, rgba(22, 33, 62, 0.95), rgba(10, 15, 35, 0.96));
  border: 1px solid rgba(245, 166, 35, 0.3);
  border-radius: 16px;
  box-shadow: 0 12px 50px var(--shadow), 0 0 60px rgba(245, 166, 35, 0.15);
}

.story-complete-card .modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
}

.story-complete-kicker {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent2);
  font-weight: 600;
}

.story-complete-title {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.15;
  text-align: center;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.story-complete-logline {
  font-style: italic;
  color: var(--text-dim);
  text-align: center;
  max-width: 700px;
  line-height: 1.45;
}

.story-complete-fan {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px 16px 12px;
  min-height: 180px;
  flex-wrap: nowrap;
  width: 100%;
}

.story-complete-thumb {
  --tilt: 0deg;
  --lift: 0px;
  --i: 0;
  position: relative;
  flex: 0 0 auto;
  width: clamp(110px, 18vw, 180px);
  aspect-ratio: 4/3;
  margin: 0 -28px;
  border-radius: 8px;
  overflow: hidden;
  border: 3px solid #f3e9d2;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55);
  background: #1a1a2a;
  opacity: 1;
  transform: rotate(var(--tilt)) translateY(var(--lift));
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1), z-index 0s 0.2s, box-shadow 0.3s;
  animation: finale-card-in 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(var(--i) * 90ms);
  cursor: pointer;
}

.story-complete-thumb:hover {
  transform: rotate(0) translateY(-8px) scale(1.08);
  z-index: 10;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.7);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), z-index 0s, box-shadow 0.25s;
}

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

.story-complete-thumb-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 4px 6px;
  font-size: 10px;
  text-align: center;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  letter-spacing: 0.3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.story-complete-thumb:hover .story-complete-thumb-caption {
  opacity: 1;
}

@keyframes finale-card-in {
  from {
    opacity: 0;
    transform: rotate(var(--tilt)) translateY(calc(var(--lift) + 40px)) scale(0.7);
  }
  to {
    opacity: 1;
    transform: rotate(var(--tilt)) translateY(var(--lift)) scale(1);
  }
}

.story-complete-final {
  margin: 8px 0 4px;
  font-style: italic;
  text-align: center;
  max-width: 650px;
  line-height: 1.7;
  color: #d0d8e8;
  font-size: 15px;
  padding: 0 12px;
  white-space: pre-line;
}

.story-complete-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

@media (max-width: 700px) {
  .story-complete-fan {
    flex-wrap: wrap;
    gap: 10px;
    padding: 20px 8px 4px;
  }
  .story-complete-thumb {
    margin: 0;
    width: clamp(130px, 38vw, 170px);
    transform: none;
    animation: finale-card-in-flat 0.5s ease-out both;
    animation-delay: calc(var(--i) * 70ms);
  }
  .story-complete-thumb:hover {
    transform: translateY(-4px) scale(1.05);
  }
  .story-complete-card {
    padding: 28px 14px 18px;
  }
}

@keyframes finale-card-in-flat {
  from { opacity: 0; transform: translateY(20px) scale(0.85); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
 * Discovery Mode
 * ============================================================ */

.discovery-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1500;
  flex-direction: column;
  overflow: hidden;
}
.discovery-screen.open { display: flex; }

.discovery-screen-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--bg2);
  border-bottom: 1px solid rgba(233, 69, 96, 0.2);
  flex-shrink: 0;
}
.discovery-screen-title {
  margin: 0;
  font-size: 22px;
  color: var(--text);
}
.discovery-screen-summary {
  color: var(--text-dim);
  font-size: 14px;
  flex-grow: 1;
}

.discovery-screen-grid {
  flex-grow: 1;
  overflow-y: auto;
  padding: 20px;
}

.discovery-set-section {
  margin-bottom: 32px;
}
.discovery-set-title {
  margin: 0 0 4px;
  font-size: 18px;
  color: var(--accent2);
}
.discovery-set-blurb {
  margin: 0 0 14px;
  color: var(--text-dim);
  font-size: 14px;
}
.discovery-set-section.locked .discovery-set-title,
.discovery-set-section.coming-soon .discovery-set-title {
  color: var(--text-dim);
}
.discovery-set-locked-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-dim);
}
.discovery-set-locked-banner .discovery-lock-icon {
  flex-shrink: 0;
  opacity: 0.4;
}

.discovery-bonus-divider {
  margin: 18px 0 8px;
  font-size: 13px;
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.discovery-card-row {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  padding: 0;
  margin: 0;
}

.discovery-card {
  background: var(--bg2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease;
  outline: none;
}
.discovery-card[role="button"]:hover,
.discovery-card[role="button"]:focus {
  border-color: rgba(233, 69, 96, 0.6);
  transform: translateY(-2px);
  cursor: pointer;
}
.discovery-card[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.7;
}

.discovery-card-image {
  position: relative;
  aspect-ratio: 4 / 3;
  background: rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.discovery-card-img,
.discovery-card-img-placeholder {
  width: 100%;
  height: 100%;
  display: block;
}
.discovery-card-img {
  object-fit: cover;
}
.discovery-card-img-placeholder {
  display: grid;
  place-items: center;
  color: var(--text-dim);
}

/* State filters */
.discovery-card[data-state="unlocked"] .discovery-card-img {
  filter: grayscale(1);
  transition: filter 0.4s ease;
}
.discovery-card[data-state="bonus-unlocked"] .discovery-card-img {
  filter: grayscale(1);
  transition: filter 0.4s ease;
}
.discovery-card[data-state="complete"] .discovery-card-img,
.discovery-card[data-state="bonus-complete"] .discovery-card-img {
  filter: none;
}
.discovery-card[data-state="in-progress"] .discovery-card-img {
  filter: none;
}
.discovery-card[data-state="in-progress"] {
  border-color: rgba(233, 69, 96, 0.5);
  box-shadow: 0 0 0 1px rgba(233, 69, 96, 0.35);
}

.discovery-card-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 6px;
  background: rgba(0, 0, 0, 0.55);
  pointer-events: none;
}
.discovery-card-progress-fill {
  height: 100%;
  background: var(--accent, #4caf50);
  transition: width 200ms ease;
}
.discovery-card-in-progress-label {
  font-size: 11px;
  color: var(--accent);
  margin-top: 2px;
  font-weight: 600;
}

.discovery-card-bonus-star {
  position: absolute;
  top: 8px;
  right: 8px;
  color: var(--accent2);
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}
.discovery-card[data-state="bonus-complete"] .discovery-bonus-star {
  color: gold;
}

.discovery-card-meta {
  padding: 10px 12px 4px;
}
.discovery-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 18px;
}
.discovery-card-artist {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.discovery-card-best-time {
  font-size: 11px;
  color: var(--accent2);
  margin-top: 2px;
}

.discovery-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 12px 12px;
}
.discovery-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.discovery-badge.tiling {
  background: rgba(245, 166, 35, 0.15);
  color: var(--accent2);
}

.discovery-lock-icon {
  color: var(--text-dim);
}

@media (prefers-reduced-motion: reduce) {
  .discovery-card { transition: none; }
  .discovery-card-img { transition: none !important; }
  .discovery-card[role="button"]:hover,
  .discovery-card[role="button"]:focus { transform: none; }
}

/* ---- Intro modal ---- */

.discovery-intro-modal { z-index: 2100; }
.discovery-intro-card {
  width: 480px;
  max-width: 92vw;
  padding: 0;
  position: relative;
}
.discovery-intro-hero {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
.discovery-intro-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.discovery-intro-card .discovery-intro-set,
.discovery-intro-card .discovery-intro-title,
.discovery-intro-card .discovery-intro-artist,
.discovery-intro-card .discovery-intro-attribution,
.discovery-intro-card .discovery-intro-blurb,
.discovery-intro-card .discovery-intro-tiling,
.discovery-intro-card .discovery-intro-modifiers,
.discovery-intro-card .discovery-intro-stats,
.discovery-intro-card .discovery-intro-actions {
  padding: 0 18px;
}
.discovery-intro-set {
  padding-top: 14px !important;
  font-size: 11px;
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.discovery-intro-title {
  margin: 4px 0 2px;
  font-size: 22px;
  color: var(--text);
}
.discovery-intro-artist {
  font-size: 14px;
  color: var(--text-dim);
}
.discovery-intro-attribution {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 6px;
}
.discovery-intro-attribution a { color: var(--accent2); }
.discovery-intro-blurb {
  margin: 14px 0 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}
.discovery-intro-section-label {
  margin-top: 14px;
  font-size: 10px;
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.discovery-intro-tiling-name {
  font-size: 14px;
  color: var(--text);
  margin-top: 2px;
}
.discovery-intro-modifiers {
  margin-top: 14px;
}
.discovery-intro-modifier-row {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(245, 166, 35, 0.1);
  border-left: 3px solid var(--accent2);
  border-radius: 4px;
}
.discovery-intro-modifier-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent2);
}
.discovery-intro-modifier-help {
  font-size: 12px;
  color: var(--text);
  margin-top: 4px;
  line-height: 1.4;
}
.discovery-intro-stats {
  display: flex;
  gap: 14px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-dim);
}
.discovery-intro-best-time { color: var(--accent2); }
.discovery-intro-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 14px !important;
  padding-bottom: 14px !important;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  margin-top: 14px;
}
.discovery-intro-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
}

/* ---- Bonus reveal overlay ---- */

.discovery-bonus-reveal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1700;
  pointer-events: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
}
.discovery-bonus-reveal-overlay.open {
  display: flex;
  pointer-events: auto;
  animation: discovery-bonus-banner-in 0.4s ease forwards;
}
.discovery-bonus-reveal-card {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: #fff;
  padding: 18px 28px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  max-width: 90vw;
}
.discovery-bonus-reveal-icon {
  font-size: 38px;
  margin-bottom: 6px;
}
.discovery-bonus-reveal-title {
  font-size: 22px;
  font-weight: 700;
}
.discovery-bonus-reveal-sub {
  font-size: 13px;
  margin-top: 4px;
  opacity: 0.85;
}

@keyframes discovery-bonus-banner-in {
  from { opacity: 0; transform: translateY(-30px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Per-card stagger when freshly revealed */
.discovery-card.discovery-bonus-revealing {
  opacity: 0;
  transform: translateY(12px);
  animation: discovery-bonus-card-in 0.5s ease forwards;
}
@keyframes discovery-bonus-card-in {
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .discovery-bonus-reveal-overlay.open { animation: none; }
  .discovery-card.discovery-bonus-revealing { animation: none; opacity: 1; transform: none; }
}

/* ---- Fading-preview reference overlay ---- */

.ref-overlay.discovery-fading-preview {
  /* No filter changes — just makes the overlay state explicit so tests
     can assert it's the discovery-driven version, not user-toggled. */
}
