/* ════════════════════════════════════════════════════════════════════
   MATCHING GAME - No Outcome ABA visual layer
   Consumes shared design tokens from ../tokens.css (Atkinson Hyperlegible,
   dusty-sage palette, spacing/radii/shadow/motion scales).
   Reskin only: layout mechanics, IDs, and JS-driven class hooks are
   preserved exactly so game.js / fitGrid() behaviour is unchanged.
   ════════════════════════════════════════════════════════════════════ */

/* ── CSS custom properties (layout - read by fitGrid) ──────────────── */
:root {
  --tile-sz:  128px;
  --tile-gap: 12px;
}

/* ── Reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: var(--font-sans);
  background: var(--surface-page);
  color: var(--text-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Shared focus-visible ring for keyboard users */
:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* ── Header ────────────────────────────────────────────────────────── */
#app-header {
  background: var(--surface-header);
  color: var(--text-on-dark);
  padding: 8px clamp(10px, 2vw, 20px);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  flex-shrink: 0;
  border-bottom: 2px solid var(--sage-700);
  cursor: pointer;                /* whole bar toggles the settings panel */
}

/* Title block + persistent brand/version watermark line. */
.app-title {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  margin-right: auto;            /* pushes the rest of the toolbar to the right */
  color: var(--text-on-dark);
}
.app-title-text {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}
.app-title-sub {
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  color: var(--slate-400);
  letter-spacing: var(--tracking-wide);
}

/* Display mode slider - ○ Simple / ◇ Visual, with a brief ghost banner. */
.display-control { position: relative; display: inline-flex; align-items: center; flex-shrink: 0; }
.display-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  width: 58px;
  height: 28px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.12);
  color: var(--text-on-dark);
  cursor: pointer;
  font-size: var(--text-md);
  line-height: 1;
}
.display-ico { position: relative; z-index: 2; opacity: 0.55; transition: opacity var(--duration-fast) var(--ease-standard); }
.display-toggle[aria-checked="false"] .display-ico-simple,
.display-toggle[aria-checked="true"]  .display-ico-visual { opacity: 1; }
.display-knob {
  position: absolute;
  top: 50%;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand-primary);
  transform: translateY(-50%);
  transition: transform var(--duration-base) var(--ease-standard);
  z-index: 1;
}
.display-toggle[aria-checked="true"] .display-knob { transform: translate(30px, -50%); }

.display-ghost {
  position: absolute;
  top: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0;
  pointer-events: none;
  z-index: 50;
}
.display-ghost.show { animation: ghost-fade 1.3s var(--ease-standard) forwards; }
@keyframes ghost-fade {
  0%   { opacity: 0; transform: translate(-50%, -2px); }
  18%  { opacity: 1; transform: translate(-50%, 0); }
  72%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Back - two-tap confirm guards against accidental mid-session exit. */
.btn-back.confirm {
  background: var(--brand-fix);
  border-color: var(--orange-700);
}

/* Prompt now lives in the toolbar. */
#app-header .btn-prompt { flex-shrink: 0; }

/* Minimize toggle - collapses the settings/admin panel to just the toolbar. */
.btn-minimize {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.28);
  color: var(--text-on-dark);
  width: 32px;
  height: 30px;
  border-radius: var(--radius-md);
  font-size: var(--text-lg);
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--duration-fast) var(--ease-standard);
}
.btn-minimize:hover { background: rgba(255,255,255,0.24); }

body.settings-collapsed #settings-bar,
body.settings-collapsed #target-panel,
body.settings-collapsed #extra-panel { display: none !important; }

/* Toolbar scales down on small screens (fluid - not locked to one device). */
@media (max-width: 680px) {
  .app-title-text { font-size: var(--text-lg); }
  .btn-minimize { width: 28px; height: 28px; font-size: var(--text-md); }
}

#btn-back {
  display: inline-flex;
  align-items: center;
  padding: 5px 13px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: var(--radius-md);
  color: var(--text-on-dark);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard);
  flex-shrink: 0;
}
#btn-back:hover { background: rgba(255,255,255,0.24); }
#btn-back:active { transform: scale(0.97); }

/* Timer */
#timer-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

#timer-display {
  font-family: var(--font-mono);
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  background: rgba(0,0,0,0.32);
  color: var(--text-on-dark);
  padding: 3px 12px;
  border-radius: var(--radius-md);
  min-width: 76px;
  text-align: center;
  letter-spacing: 0.05em;
}

.btn-timer {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.28);
  color: var(--text-on-dark);
  padding: 5px 12px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard);
  min-width: 70px;
  text-align: center;
}
.btn-timer:hover { background: rgba(255,255,255,0.24); }
.btn-timer:active { transform: scale(0.96); }

/* ── Settings bar ──────────────────────────────────────────────────── */
#settings-bar {
  background: var(--surface-card);
  border-bottom: 1px solid var(--border-default);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.setting-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.setting-group > label:first-child {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  white-space: nowrap;
}

.setting-group select,
.setting-group input[type="number"] {
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  font-family: var(--font-sans);
  background: var(--surface-sunken);
  color: var(--text-primary);
  transition: border-color var(--duration-fast) var(--ease-standard),
              box-shadow var(--duration-fast) var(--ease-standard);
}
.setting-group select:focus-visible,
.setting-group input[type="number"]:focus-visible {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

.setting-group input[type="number"] { width: 58px; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-body);
  cursor: pointer;
  white-space: nowrap;
}
.checkbox-label input[type="checkbox"] { cursor: pointer; accent-color: var(--brand-primary); }

.btn-primary {
  margin-left: auto;
  background: var(--brand-primary);
  color: var(--brand-primary-text);
  border: none;
  padding: 8px 26px;
  border-radius: var(--radius-lg);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background var(--duration-fast) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard),
              box-shadow var(--duration-fast) var(--ease-standard);
}
.btn-primary:hover  { background: var(--brand-primary-hover); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: scale(0.97); }

/* ── Target picker ─────────────────────────────────────────────────── */
.btn-targets {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard),
              border-color var(--duration-fast) var(--ease-standard);
}
.btn-targets:hover       { background: var(--slate-200); }
.btn-targets.is-open     { background: var(--sage-50); border-color: var(--sage-500); }
.btn-targets.is-filtered { border-color: var(--sage-500); color: var(--sage-700); }
.btn-targets .targets-count {
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  background: var(--slate-200);
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
}
.btn-targets.is-filtered .targets-count {
  background: var(--sage-100);
  color: var(--sage-700);
}

#target-panel {
  background: var(--surface-page);
  border-bottom: 1px solid var(--border-default);
  padding: 10px 20px;
  max-height: 40vh;
  overflow-y: auto;
}
.target-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.target-panel-title {
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  font-size: var(--text-md);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
}
.target-panel-actions {
  display: flex;
  gap: 6px;
}
.target-panel-actions button {
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface-card);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-body);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard);
}
.target-panel-actions button:hover { background: var(--surface-sunken); }
.btn-targets-close {
  border: none !important;
  background: transparent !important;
  font-size: var(--text-xl) !important;
  line-height: 1;
  padding: 2px 8px !important;
  color: var(--text-muted);
}
.target-panel-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 4px 12px;
}
.target-panel-empty {
  padding: 12px;
  color: var(--text-muted);
  font-style: italic;
}
.target-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  font-size: var(--text-sm);
  color: var(--text-body);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--duration-fast) var(--ease-standard);
}
.target-row:hover { background: var(--surface-sunken); }
.target-row input[type="checkbox"] { cursor: pointer; accent-color: var(--brand-primary); }
.target-thumb {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--surface-sunken);
}
.target-row-label { flex: 1 1 auto; }

/* ── Extra settings panel ──────────────────────────────────────────── */
.btn-extra {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard),
              border-color var(--duration-fast) var(--ease-standard);
}
.btn-extra:hover   { background: var(--slate-200); }
.btn-extra.is-open { background: var(--sage-50); border-color: var(--sage-500); }

#extra-panel {
  background: var(--surface-page);
  border-bottom: 1px solid var(--border-default);
  padding: 10px 20px;
  max-height: 40vh;
  overflow-y: auto;
}
.extra-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.extra-panel-title {
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  font-size: var(--text-md);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
}
.btn-extra-close {
  border: none !important;
  background: transparent !important;
  font-size: var(--text-xl);
  line-height: 1;
  padding: 2px 8px;
  cursor: pointer;
  color: var(--text-muted);
}
.extra-panel-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px 20px;
  align-items: center;
}
.extra-panel-body .checkbox-label { padding: 4px 0; }
.extra-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.extra-row select {
  padding: 4px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  background: var(--surface-sunken);
  color: var(--text-primary);
}

/* ── Game area ─────────────────────────────────────────────────────── */
#game-area {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  padding: 24px 28px;
  align-items: flex-start;
  justify-content: center;
}

.area-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--text-muted);
  margin-bottom: 8px;
  text-align: center;
}

/* Sample card - the discriminative stimulus; deliberately the most salient
   element on screen (larger than the choice tiles, stronger framing). */
#sample-section { display: flex; flex-direction: column; align-items: center; }

#sample-section .area-label {
  font-size: var(--text-sm);
  color: var(--brand-accent);
}

#sample-card {
  width: clamp(220px, 26vw, 360px);
  height: clamp(220px, 26vw, 360px);
  background: var(--surface-card);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg), 0 0 0 4px var(--sage-100);
  border: 2px solid var(--sage-200);
  border-top: 4px solid var(--brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#sample-img {
  max-width: 88%;
  max-height: 88%;
  object-fit: contain;
  display: block;
}

/* Comparison grid */
#comp-section { display: flex; flex-direction: column; align-items: center; position: relative; }

#comp-grid {
  display: grid;
  gap: var(--tile-gap);
  grid-template-columns: repeat(var(--grid-cols, 4), var(--tile-sz));
  justify-content: center;
}

/* ── Tile ──────────────────────────────────────────────────────────── */
.tile-wrapper {
  /* Expand animation lives here so it doesn't conflict with 3D flip */
  transition: transform var(--duration-base) var(--ease-standard);
}
.tile-wrapper.expanding {
  transform: scale(1.12);
}

.tile {
  width: var(--tile-sz);
  height: var(--tile-sz);
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.55s var(--ease-standard);
  cursor: pointer;
}

.tile.flipped {
  transform: rotateY(180deg);
}

.tile-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-xl);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 2px solid var(--border-default);
  background: var(--surface-card);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* Front face */
.tile-front {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--duration-fast) var(--ease-standard),
              box-shadow var(--duration-fast) var(--ease-standard),
              background var(--duration-fast) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard);
}
.tile-front img {
  max-width: 95%;
  max-height: 95%;
  object-fit: contain;
  pointer-events: none;
  display: block;
}
.tile:not(.tile-disabled):hover .tile-front {
  border-color: var(--sage-500);
  box-shadow: 0 6px 16px rgba(106, 118, 89, 0.28);
  transform: translateY(-2px);
}
.tile.tile-disabled { cursor: default; }

/* Back face - neutral default; green only when outcome is Correct */
.tile-back {
  transform: rotateY(180deg);
  background: linear-gradient(135deg, var(--slate-600), var(--slate-500));
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile-back.back-correct {
  background: linear-gradient(135deg, var(--green-800), var(--green-700));
}
.ok-text {
  font-size: 2.6rem;
  font-weight: var(--weight-heavy);
  color: var(--white);
  text-shadow: 0 2px 6px rgba(0,0,0,0.25);
  letter-spacing: 0.03em;
}

/* ── Tile animations ───────────────────────────────────────────────── */

/* Jiggle on wrong click */
@keyframes jiggle {
  0%   { transform: translateX(0)        rotate(0deg); }
  15%  { transform: translateX(-8px)     rotate(-3deg); }
  30%  { transform: translateX(8px)      rotate(3deg); }
  45%  { transform: translateX(-6px)     rotate(-2deg); }
  60%  { transform: translateX(6px)      rotate(2deg); }
  75%  { transform: translateX(-3px)     rotate(-1deg); }
  90%  { transform: translateX(3px)      rotate(1deg); }
  100% { transform: translateX(0)        rotate(0deg); }
}
.tile-wrapper.jiggle { animation: jiggle 0.5s ease; }

/* Red flash on wrong click */
@keyframes flash-red {
  0%   { background: var(--surface-card); }
  20%  { background: var(--red-100); }
  50%  { background: var(--red-300); }
  100% { background: var(--surface-card); }
}
.tile-wrapper.flash-red .tile-front { animation: flash-red 0.5s ease; }

/* Visual display mode - correct answer pinwheels the sample + match off-screen
   in a random direction. Direction/spin are set per-element via custom props. */
.pinwheel-off {
  animation: pinwheel-off 0.72s var(--ease-standard) forwards;
  z-index: 30;
  pointer-events: none;
}
@keyframes pinwheel-off {
  to {
    transform: translate(var(--fly-x, 0), var(--fly-y, 0))
               rotate(var(--spin, 720deg)) scale(0.35);
    opacity: 0;
  }
}

/* ── Prompt effects ────────────────────────────────────────────────── */

/* Sparkle */
@keyframes sparkle-pulse {
  0%   { box-shadow: 0 0 6px 3px #ffd700,
                     0 0 14px 6px rgba(255,215,0,0.55),
                     0 0 24px 10px rgba(255,165,0,0.25); }
  50%  { box-shadow: 0 0 12px 6px #ffd700,
                     0 0 28px 12px rgba(255,215,0,0.65),
                     0 0 44px 20px rgba(255,140,0,0.35); }
  100% { box-shadow: 0 0 6px 3px #ffd700,
                     0 0 14px 6px rgba(255,215,0,0.55),
                     0 0 24px 10px rgba(255,165,0,0.25); }
}
.tile.prompt-sparkle .tile-front {
  animation: sparkle-pulse 1s ease-in-out infinite;
  border-color: var(--amber-500) !important;
}

/* Outline */
.tile.prompt-outline .tile-front {
  border: 3px solid var(--green-700) !important;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.38), var(--shadow-sm) !important;
  background: rgba(22, 163, 74, 0.06);
}

/* ── Trial overlay: Next + Retry watermark buttons ─────────────────── */
#trial-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  pointer-events: none;
  z-index: 20;
}

.btn-watermark {
  pointer-events: all;
  padding: 11px 30px;
  border-radius: var(--radius-xl);
  font-size: var(--text-xl);
  font-weight: var(--weight-heavy);
  cursor: pointer;
  border: none;
  box-shadow: var(--shadow-modal);
  transition: opacity var(--duration-fast) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard);
  letter-spacing: 0.02em;
  color: var(--white);
}
.btn-watermark:hover  { opacity: 0.93; transform: scale(1.04); }
.btn-watermark:active { transform: scale(0.97); }

.btn-watermark-next {
  background: var(--green-700);
}
.btn-watermark-retry {
  background: var(--orange-600);
}

/* ── Bottom bar ────────────────────────────────────────────────────── */
#bottom-bar {
  background: var(--surface-card);
  border-top: 1px solid var(--border-default);
  padding: 9px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.btn-prompt {
  background: var(--brand-fix);
  color: var(--white);
  border: none;
  padding: 5px 14px;
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard);
}
.btn-prompt:hover { background: var(--orange-700); }
.btn-prompt:active { transform: scale(0.97); }

.btn-print {
  background: var(--slate-600);
  color: var(--white);
  border: none;
  padding: 7px 18px;
  border-radius: var(--radius-lg);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard);
}
.btn-print:hover { background: var(--slate-800); }

.btn-clear-data {
  background: var(--intent-danger);
  color: var(--white);
  border: none;
  padding: 7px 18px;
  border-radius: var(--radius-lg);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard);
}
.btn-clear-data:hover { background: var(--red-700); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 34px;
  padding: 0;
}
.btn-icon svg { width: 20px; height: 20px; fill: currentColor; }

/* ── Reduced motion ────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .tile,
  .tile-wrapper,
  .tile-front,
  .btn-watermark,
  .btn-primary,
  .btn-prompt,
  #btn-back,
  .btn-timer { transition: none !important; }
  .tile-wrapper.jiggle,
  .tile.prompt-sparkle .tile-front,
  .display-ghost.show { animation: none !important; }
  .tile:not(.tile-disabled):hover .tile-front { transform: none; }
  .display-knob { transition: none; }
  .pinwheel-off { animation: none; opacity: 0; }   /* skip the spin, still clears */
}

/* ── Print section (screen: hidden; print: visible) ─────────────────── */
#print-section { display: none; }

@media print {
  /* Hide everything except the print section */
  body > *:not(#print-section) { display: none !important; }

  #print-section {
    display: block;
    padding: 18px 24px;
    font-family: Arial, sans-serif;
    font-size: 11pt;
    color: #000;
  }

  #print-section h2 {
    font-size: 15pt;
    margin-bottom: 4px;
  }

  #print-meta {
    font-size: 9pt;
    color: #444;
    margin-bottom: 14px;
  }

  #results-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 14px;
  }

  #results-table th,
  #results-table td {
    border: 1px solid #666;
    padding: 5px 8px;
    text-align: left;
    vertical-align: top;
  }

  #results-table th {
    background: #e8e8e8;
    font-weight: bold;
    font-size: 9.5pt;
  }

  #results-table tr:nth-child(even) td { background: #f7f7f7; }
  #results-table tr.settings-changed td { background: #e8e8e8 !important; }

  #results-table td.outcome-error      { color: #c0392b; }
  #results-table td.outcome-prompted   { color: #b7791f; }
  #results-table td.outcome-ok         { color: #27ae60; }
  #results-table td.outcome-correction { color: #6b46c1; }

  #print-summary {
    font-size: 9.5pt;
    color: #333;
    border-top: 1px solid #bbb;
    padding-top: 8px;
  }
  #print-summary span { margin-right: 20px; }
}

/* ── Token Board (simple, clean design) ────────────────────────────── */
.token-board-simple {
  background: linear-gradient(to right, #f8fafc, #f0f6f3);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-shrink: 0;
  border-bottom: 1px solid #cbd5e0;
  min-height: 44px;
}

.token-board-simple.goal-reached {
  background: linear-gradient(to right, #e8f5e9, #dff5e0);
  border-bottom-color: #2c6a3f;
}

.token-emoji-simple {
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 60px;
  flex-wrap: wrap;
  max-width: 150px;
  line-height: 1;
}

.token-progress-simple {
  font-size: 1rem;
  font-weight: 600;
  font-family: 'Courier New', monospace;
  color: #2d3748;
  white-space: nowrap;
  letter-spacing: 0.05em;
}

/* Token settings in extra panel */
#token-settings {
  background: #f0f6f3;
  padding: 12px;
  border-radius: 8px;
  border-left: 3px solid #1a2744;
}

.token-board-settings-divider {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #cbd5e0;
}

#token-settings .extra-row {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#token-settings .extra-row:last-child {
  margin-bottom: 0;
}

#token-settings label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #2d3748;
  min-width: 110px;
}

#token-settings select,
#token-settings input[type="number"] {
  padding: 6px 8px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.88rem;
  background: #fff;
  color: #2d3748;
}

#inp-schedule-value {
  width: 60px;
}

#inp-starting-tokens,
#inp-goal-tokens {
  width: 70px;
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  :root { --tile-sz: 96px; --tile-gap: 8px; }

  /* Header */
  #app-header { padding: 8px 12px; gap: 8px; }
  #app-header h1 { font-size: var(--text-xl); }
  #timer-display { font-size: var(--text-2xl); min-width: 62px; padding: 2px 8px; }
  .btn-timer { padding: 4px 9px; font-size: var(--text-xs); }

  /* Settings bar */
  #settings-bar { padding: 6px 12px; gap: 8px; }
  .setting-group > label:first-child,
  .checkbox-label { font-size: var(--text-xs); }
  .setting-group select,
  .setting-group input[type="number"] { font-size: var(--text-sm); padding: 4px 6px; }

  /* Game area - column, anchored to top */
  #game-area {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    padding: 16px 12px;
  }

  /* Sample card */
  #sample-card { width: 150px; height: 150px; }
}

/* Narrow phones: shrink tiles further so 4-column grids still fit */
@media (max-width: 480px) {
  :root { --tile-sz: 72px; --tile-gap: 6px; }
  .ok-text { font-size: 2rem; }
}

/* ── Landscape phones: row layout so tiles fill horizontal space ────── */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --tile-sz: 100px; --tile-gap: 8px; }

  #game-area {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 8px 14px;
  }

  #sample-section { flex-shrink: 0; }

  #sample-card {
    width: 110px;
    height: 110px;
  }

  #comp-section { flex: 1; min-width: 0; }
}

/* ── Mobile: lock viewport, header pinned, game area scrolls ──────── */
@media (max-width: 680px) {
  html, body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: contain;
  }
  body { min-height: 0; }

  #app-header { padding: 6px 10px; gap: 6px; flex-shrink: 0; }
  #app-header h1 { font-size: var(--text-lg); }
  #timer-display { font-size: var(--text-xl); min-width: 56px; padding: 2px 7px; }
  .btn-timer { padding: 3px 8px; font-size: var(--text-2xs); min-width: 0; }
  #btn-back { padding: 4px 9px; font-size: var(--text-xs); }

  #settings-bar { padding: 6px 10px; gap: 6px 8px; flex-shrink: 0; }
  #extra-panel, #target-panel { flex-shrink: 0; }

  #game-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    padding: 10px 10px;
    gap: 10px;
    justify-content: safe center;
    align-items: center;
  }

  .area-label { margin-bottom: 4px; font-size: var(--text-2xs); }

  #sample-section { flex: 0 0 auto; }
  #sample-card { width: 96px; height: 96px; }

  #comp-section { flex: 0 0 auto; width: 100%; align-items: center; position: relative; }

  #comp-grid {
    width: auto;
    max-width: 100%;
  }

  #bottom-bar { padding: 6px 10px; gap: 8px; flex-shrink: 0; }
}

/* Landscape phones: row layout so sample sits beside the grid */
@media (orientation: landscape) and (max-height: 500px) {
  html, body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: contain;
  }
  body { min-height: 0; }

  #app-header { padding: 4px 10px; flex-shrink: 0; }
  #app-header h1 { font-size: var(--text-lg); }
  #settings-bar { padding: 4px 10px; flex-shrink: 0; }

  #game-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    gap: 12px;
  }

  #sample-section { flex: 0 0 auto; }
  #sample-card { width: 80px; height: 80px; }

  #comp-section { flex: 0 0 auto; min-width: 0; align-items: center; }
  #comp-grid { width: auto; max-width: 100%; }

  /* Token board responsive */
  .token-board-simple { padding: 8px 10px; }
  .token-emoji-simple { font-size: 1.2rem; }
  .token-progress-simple { font-size: 0.9rem; }
}
