/* ── CSS custom properties ─────────────────────────────────────────── */
:root {
  --tile-sz:  160px;
  --tile-gap: 12px;
}

.btn-primary {
  margin-left: auto;
  background: #3182ce;
  color: #fff;
  border: none;
  padding: 8px 24px;
  border-radius: 8px;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover  { background: #2b6cb0; }
.btn-primary:active { transform: scale(0.97); }

/* ── FFC-specific target grouping ──────────────────────────────────── */
.target-group {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 10px;
}
.target-group-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  border-bottom: 1px dashed #e2e8f0;
  padding-bottom: 4px;
}
.target-group-title {
  flex: 1 1 auto;
  font-weight: 700;
  color: #2d3748;
  font-size: 0.85rem;
}
.target-group-head button {
  padding: 2px 6px;
  border: 1px solid #cbd5e0;
  background: #f7fafc;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #4a5568;
  cursor: pointer;
}
.target-group-head button:hover { background: #edf2f7; }
.target-group-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

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

.area-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #718096;
  margin-bottom: 8px;
  text-align: center;
}

/* ── Sample / carrier phrase card ──────────────────────────────────── */
#sample-section { display: flex; flex-direction: column; align-items: center; }

#sample-card {
  min-width: 260px;
  max-width: 640px;
  width: auto;
  min-height: 72px;
  height: auto;
  background: linear-gradient(145deg, #5e3a8c, #8c5ec5);
  border-radius: 14px;
  box-shadow: 0 4px 18px rgba(94,58,140,0.30);
  border: 2px solid #a57cd7;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 14px 30px;
}

#sample-word {
  font-weight: 800;
  color: #ffffff;
  text-align: center;
  line-height: 1.25;
  letter-spacing: -0.01em;
  overflow-wrap: normal;
  word-break: normal;
}

/* 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;
}

/* ── 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: 12px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  border: none;
  box-shadow: 0 4px 18px rgba(0,0,0,0.28);
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: 0.02em;
}
.btn-watermark:hover  { opacity: 0.93; transform: scale(1.04); }
.btn-watermark:active { transform: scale(0.97); }

.btn-watermark-next {
  background: rgba(47, 133, 90, 0.92);
  color: #fff;
}
.btn-watermark-retry {
  background: rgba(192, 86, 33, 0.88);
  color: #fff;
}

/* ── Tile ──────────────────────────────────────────────────────────── */
.tile-wrapper {
  transition: transform 0.25s ease;
}
.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 cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

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

.tile-face {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 2px solid #e2e8f0;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,0.10);
  overflow: hidden;
}

/* Front face */
.tile-front {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.tile-front img {
  max-width: 95%;
  max-height: 95%;
  object-fit: contain;
  pointer-events: none;
  display: block;
}
.tile-label {
  display: none;
  font-weight: 700;
  color: #2d3748;
  text-align: center;
  padding: 8px;
  word-break: break-word;
  line-height: 1.2;
}
.tile-label-visible { display: block; }
.tile:not(.tile-disabled):hover .tile-front {
  border-color: #8c5ec5;
  box-shadow: 0 4px 12px rgba(140,94,197,0.28);
}
.tile.tile-disabled { cursor: default; }

/* Back face */
.tile-back {
  transform: rotateY(180deg);
  background: linear-gradient(135deg, #4a5568, #718096);
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile-back.back-correct {
  background: linear-gradient(135deg, #276749, #38a169);
}
.ok-text {
  font-size: 2.6rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.25);
  letter-spacing: 0.03em;
}

/* ── Tile animations ───────────────────────────────────────────────── */
@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; }

@keyframes flash-red {
  0%   { background: #fff; }
  20%  { background: #fed7d7; }
  50%  { background: #fc8181; }
  100% { background: #fff; }
}
.tile-wrapper.flash-red .tile-front { animation: flash-red 0.5s ease; }

/* ── Prompt effects ────────────────────────────────────────────────── */
@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: #d69e2e !important;
}

.tile.prompt-outline .tile-front {
  border: 3px solid #38a169 !important;
  box-shadow: 0 0 0 3px rgba(56,161,105,0.38), 0 3px 8px rgba(0,0,0,0.1) !important;
  background: rgba(56,161,105,0.05);
}

/* ── Bottom bar ────────────────────────────────────────────────────── */
#bottom-bar {
  background: #fff;
  border-top: 2px solid #e7dfee;
  padding: 9px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.btn-prompt {
  background: #dd6b20;
  color: #fff;
  border: none;
  padding: 5px 14px;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-prompt:hover { background: #c05621; }

.btn-print {
  background: #4a5568;
  color: #fff;
  border: none;
  padding: 7px 18px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-print:hover { background: #2d3748; }

.btn-clear-data {
  background: #c53030;
  color: #fff;
  border: none;
  padding: 7px 18px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-clear-data:hover { background: #9b2c2c; }

.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; }

@media print {
  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; }
}

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

  #game-area { flex-direction: column; align-items: center; justify-content: flex-start; gap: 16px; padding: 16px 12px; }
  #sample-card { min-width: 180px; padding: 10px 18px; }
}

@media (max-width: 480px) {
  :root { --tile-sz: 90px; --tile-gap: 6px; }
  .ok-text { font-size: 2rem; }
}

@media (max-width: 680px) {
  html, body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: contain;
  }
  body { min-height: 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: 0.68rem; }

  #sample-section { flex: 0 0 auto; width: 100%; align-items: center; }
  #sample-card {
    min-width: 0;
    max-width: 100%;
    width: auto;
    min-height: 56px;
    padding: 10px 16px;
  }

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

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

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

@media (orientation: landscape) and (max-height: 500px) {
  html, body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: contain;
  }
  body { min-height: 0; }

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

  #sample-section { flex: 0 0 auto; }
  #sample-card { max-width: 240px; min-width: 0; min-height: 0; padding: 8px 12px; }

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

/* ── Token Board ───────────────────────────────────────────────────── */
.token-board-simple {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
  border-bottom: 1px solid #bbf7d0;
  min-height: 44px;
  padding: 10px 20px;
  flex-shrink: 0;
}

.token-board-simple.goal-reached {
  background: linear-gradient(135deg, #dcfce7 0%, #c6f6d5 100%);
  border-bottom-color: #86efac;
}

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

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

#token-settings {
  background: #f0fdf4;
  border-left: 3px solid #86efac;
  padding: 12px;
  border-radius: 4px;
}

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

/* ══════════════════════════════════════════════════════════════════
   Session setup panel (Frame 07 - gated session targets)
   Sage clinical palette mirrors design_handoff_admin_redesign Frame 07.
   ══════════════════════════════════════════════════════════════════ */
.btn-session {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f3f6ee;
  border: 1px solid #dfe6d2;
  color: #4d5840;
  border-radius: 9px;
  padding: 8px 13px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;            /* let press-hold work cleanly on touch */
  transition: background 0.15s, box-shadow 0.15s;
}
.btn-session:hover { background: #eaf0e0; }
.btn-session.is-holding { box-shadow: 0 0 0 3px rgba(77,88,64,0.22); }
.btn-session.is-open { background: #4d5840; color: #fff; border-color: #4d5840; }

#session-panel {
  max-width: 880px;
  margin: 14px auto 6px;
  background: #fff;
  border: 1px solid #e2e6d9;
  border-radius: 16px;
  box-shadow: 0 16px 42px rgba(44,51,31,0.16);
  overflow: hidden;
  font-family: 'Segoe UI', Inter, -apple-system, sans-serif;
  color: #1a1f14;
}

.session-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px 14px;
}
.session-eyebrow { font-size: 10px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: #a3ad92; }
.session-title { font-size: 18px; font-weight: 700; color: #1a1f14; margin-top: 2px; }
.session-head-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.session-set-picker select {
  background: #f3f6ee; border: 1px solid #dfe6d2; color: #4d5840;
  border-radius: 9px; padding: 7px 10px; font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.session-gate-pill {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 5px 11px; font-size: 11.5px; font-weight: 700;
  background: #eef1e8; border: 1px solid #dfe3d6; color: #7a8568;
}
#session-panel[data-editing="true"] .session-gate-pill { background: #fef3c7; border-color: #fae3a0; color: #92722a; }
#session-panel[data-editing="true"] .session-gate-pill::before { content: "🔓"; }
#session-panel[data-editing="true"] .session-gate-pill { font-size: 0; }
#session-panel[data-editing="true"] .session-gate-pill::after { content: "Editing"; font-size: 11.5px; }
.session-close {
  background: transparent; border: none; color: #9aa589; font-size: 22px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.session-close:hover { color: #5d6a4d; }

.session-body { padding: 0 20px 18px; display: flex; gap: 18px; align-items: flex-start; }

/* Left · items in play */
.session-pool {
  width: 288px; flex-shrink: 0; border: 1px solid #eef0e9; border-radius: 12px;
  overflow: hidden; display: flex; flex-direction: column;
}
.session-pool-head {
  display: flex; align-items: center; gap: 8px; padding: 11px 13px;
  background: #fbfcf9; border-bottom: 1px solid #eef0e9;
}
.session-pool-title { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: #7a8568; }
.session-pool-count { font-size: 11px; font-weight: 700; color: #4d5840; background: #eef1e8; border-radius: 999px; padding: 1px 8px; }
.session-search { padding: 10px 11px 0; }
.session-search > div, .session-search { display: block; }
.session-search { position: relative; }
.session-search span { position: absolute; left: 21px; top: 18px; font-size: 12px; opacity: 0.5; pointer-events: none; }
.session-search input {
  width: 100%; background: #f4f6ef; border: 1px solid #e7ebe0; border-radius: 8px;
  padding: 7px 11px 7px 30px; font: inherit; font-size: 12.5px; color: #2c331f;
}
.session-pool-list { padding: 9px 9px 4px; display: flex; flex-direction: column; gap: 3px; max-height: 320px; overflow-y: auto; }
.session-pool-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 9px; border-radius: 9px;
  cursor: pointer; border: none; background: transparent; width: 100%; text-align: left; font: inherit;
}
.session-pool-row:hover { background: #f7f9f3; }
.session-pool-row.is-selected { background: #f3f6ee; box-shadow: inset 3px 0 0 #4d5840; }
.session-pool-row .pool-emoji { font-size: 21px; width: 26px; text-align: center; flex-shrink: 0; }
.session-pool-row img.pool-emoji { width: 26px; height: 26px; object-fit: contain; border-radius: 5px; }
.session-pool-row .pool-meta { flex: 1; min-width: 0; }
.session-pool-row .pool-name { font-size: 13px; font-weight: 700; color: #2c331f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-pool-row:not(.is-selected) .pool-name { font-weight: 600; color: #3c4533; }
.session-pool-row .pool-sub { font-size: 10.5px; color: #8a9678; }
.session-pool-row.is-out { opacity: 0.45; }
.session-pool-foot { padding: 8px 11px 12px; }
.session-add-btn, .session-pool-row.is-add {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: transparent; border: 1.5px dashed #c7cdb6; color: #5d6a4d; border-radius: 9px;
  padding: 9px; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
}
.session-add-btn:hover { background: #f7f9f3; }

/* Right · active targets */
.session-targets { flex: 1; min-width: 0; }
.session-empty { font-size: 13px; color: #9aa589; padding: 20px 4px; }
.session-sel-head { display: flex; align-items: center; gap: 11px; margin-bottom: 4px; }
.session-sel-emoji { width: 40px; height: 40px; border-radius: 10px; background: #f4f6ef; display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.session-sel-emoji img { width: 30px; height: 30px; object-fit: contain; }
.session-sel-name { font-size: 16px; font-weight: 700; color: #1a1f14; }
.session-sel-note { font-size: 11.5px; color: #9aa589; }
.session-trait-group-head { display: flex; align-items: center; gap: 8px; margin: 14px 0 8px; }
.session-trait-group-head .gh-label { font-size: 10px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: #a3ad92; }
.session-trait-group-head .gh-rule { height: 1px; flex: 1; background: #eef0e9; }
.session-trait-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.session-pill {
  font-size: 12.5px; font-weight: 600; padding: 6px 12px; border-radius: 999px;
  background: #fff; border: 1px solid #dfe3d6; color: #aab199; cursor: pointer; font-family: inherit;
}
.session-pill:hover { border-color: #c7cdb6; }
.session-pill.is-on { font-weight: 700; background: #4d5840; border-color: #4d5840; color: #fff; }
.session-pill.is-on::before { content: "✓ "; }
.session-trait-hint { margin-top: 11px; font-size: 11px; color: #9aa589; }

/* Session band */
.session-band {
  padding: 15px 20px; background: #fbfcf9; border-top: 1px solid #eef0e9;
  display: flex; gap: 26px; align-items: flex-start; flex-wrap: wrap;
}
.session-band-label { font-size: 11px; font-weight: 700; color: #5d6a4d; margin-bottom: 6px; }
.session-band-sub { font-size: 10.5px; color: #a3ad92; margin-top: 5px; }
.session-stepper { display: inline-flex; align-items: center; gap: 2px; background: #f4f6ef; border: 1px solid #e7ebe0; border-radius: 9px; padding: 3px; }
.session-step { width: 30px; height: 30px; border: none; background: #fff; border-radius: 7px; font-size: 17px; color: #5d6a4d; cursor: pointer; box-shadow: 0 1px 2px rgba(44,51,31,0.08); }
.session-step:hover { background: #eef1e8; }
.session-step-val { width: 34px; text-align: center; font-size: 15px; font-weight: 700; color: #1a1f14; }
.session-types { display: flex; gap: 6px; }
.session-type-pill { font-size: 12.5px; font-weight: 600; padding: 6px 13px; border-radius: 999px; background: #fff; border: 1px solid #dfe3d6; color: #aab199; cursor: pointer; font-family: inherit; }
.session-type-pill.is-on { font-weight: 700; background: #4d5840; border-color: #4d5840; color: #fff; }
.session-type-pill.is-on::before { content: "✓ "; }
.session-prompting { background: #fff; border: 1px solid #e2e6d9; border-radius: 9px; padding: 8px 12px; font: inherit; font-size: 12.5px; font-weight: 700; color: #1a1f14; cursor: pointer; }

/* Footer */
.session-foot { display: flex; align-items: center; gap: 12px; padding: 16px 20px; }
.btn-session-start { flex: 1; background: #4d5840; color: #fff; border: none; border-radius: 10px; padding: 12px; font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; }
.btn-session-start:hover { background: #3f4a35; }
.btn-session-save { background: transparent; color: #5d6a4d; border: 1px solid #e2e6d9; border-radius: 10px; padding: 11px 14px; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.btn-session-save:hover { background: #f4f6ef; }
.btn-session-reset { background: transparent; color: #8a9678; border: none; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; text-decoration: underline; }

/* Gating - when locked, the editable controls are inert + muted */
#session-panel[data-editing="false"] .session-pill,
#session-panel[data-editing="false"] .session-type-pill,
#session-panel[data-editing="false"] .session-step,
#session-panel[data-editing="false"] .session-add-btn,
#session-panel[data-editing="false"] .session-prompting,
#session-panel[data-editing="false"] .session-search input,
#session-panel[data-editing="false"] .btn-session-save,
#session-panel[data-editing="false"] .btn-session-reset {
  pointer-events: none;
  opacity: 0.55;
}

@media (max-width: 720px) {
  .session-body { flex-direction: column; }
  .session-pool { width: 100%; }
}
