/* Card Sense trainer styles (tools/card-sense.html). Visuals read from the shared shell palette
   (--g-*), so the theme switcher in the menu moves the whole table.
   Nothing here hardcodes a brand color; only one semantic danger tint
   (--tc-bad) is local, used for an invalid selection.

   Layout goal: the whole game fits one viewport, phone or desktop, with
   no page scroll. The board takes every spare pixel and tiles scale to fit. */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
#gameRoot {
  height: 100dvh; height: 100vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
/* The shell centers stage children on their content box (align-items:flex-start)
   and keeps overflow:auto as a safety net. A game that sizes tiles from the
   leftover height needs the column to actually span the stage and nothing to
   scroll, so both are reset here. */
.mj-stage {
  flex: 1 1 auto; min-height: 0;
  display: flex; align-items: stretch; overflow: hidden;
  padding: 8px 10px 10px;
}
.tc-wrap {
  --tc-bad: #C0533B;
  /* Ivory tile body, used by the shared tile art (see "tile furniture" below). */
  --tile-face: #fff; --tile-face-2: #FBF8F1; --tile-face-3: #F5F0E6;
  --tile-edge: #E2D9C6; --tile-edge-lo: #EDE6D6; --tile-ink: #16281F;
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; gap: 8px;
  font-family: var(--sans, system-ui, sans-serif);
  width: 100%; max-width: 1180px; margin: 0 auto;
}

/* ---------- tile furniture ----------
   Tile faces come from the shared SchoolTiles art, but the CSS that turns
   makeTile()'s markup into a tile lives in assets/site.css, which this game
   does not load: the chrome here is the game shell instead, and pulling in the
   whole site stylesheet to draw a tile would cost more than it gives. So the
   furniture is redeclared, scoped to this page.

   Left out, a tile is an unstyled <span>: the face image paints at its natural
   size, the corner digit drops into the text flow, and the PNG faces (bams,
   joker, flowers, dot-7) lose the ivory body they are printed on, because those
   files are artwork-only PNGs on a transparent background. */
.tc-wrap .tl {
  position: relative; display: block; width: 100%; height: 100%;
  border-radius: 8px; overflow: hidden;
  background: linear-gradient(174deg, var(--tile-face) 0%, var(--tile-face-2) 62%, var(--tile-face-3) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .9),
    inset 0 -1px 0 rgba(160, 145, 120, .22),
    0 1px 0 var(--tile-edge), 0 3px 0 var(--tile-edge-lo),
    0 5px 10px rgba(0, 0, 0, .3);
}
/* Both children are pinned to the tile box rather than stacked in flow: the
   SVG face and the PNG face sit on top of each other, so a raster tile never
   pushes its vector twin out of the tile while the image loads. */
.tc-wrap .tl > svg,
.tc-wrap .tl > .tl-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; border-radius: 8px;
}
.tc-wrap .tl > .tl-img { object-fit: contain; pointer-events: none; }
.tc-wrap .tl .mjs-ink { fill: var(--tile-ink); }
.tc-wrap .tl .cnr {
  position: absolute; top: 5%; left: 8%;
  font: 700 clamp(7px, 1.4vmin, 12px)/1 var(--sans, system-ui, sans-serif);
  font-style: normal; color: #A32C2C;
}
.tc-tp .tl { box-shadow: 0 1px 0 var(--tile-edge), 0 2px 5px rgba(0, 0, 0, .34); }

/* ---------- target card (compact) ---------- */
.tc-target {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--g-card), var(--g-panel));
  border: 1px solid var(--g-accent-edge);
  border-left: 4px solid var(--g-accent);
  border-radius: var(--g-radius);
  padding: 9px 12px;
  box-shadow: var(--g-shadow-md);
  flex: 0 0 auto;
}
.tc-t-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.tc-t-head { min-width: 0; }
.tc-t-lab { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--g-accent); font-weight: 700; }
.tc-t-lab #lvName { color: var(--g-muted); text-transform: none; letter-spacing: 0; }
.tc-t-name {
  font-family: Georgia, 'Times New Roman', serif; font-size: 24px; font-weight: 700;
  margin: 1px 0 2px; color: var(--g-heading); line-height: 1.02;
}
.tc-t-pts {
  flex: 0 0 auto; font-size: 12px; font-weight: 700;
  color: var(--g-accent); background: var(--g-accent-soft); border: 1px solid var(--g-accent-edge);
  border-radius: 999px; padding: 3px 9px;
}
.tc-t-desc { font-size: 12.5px; color: var(--g-muted); max-width: 60ch; line-height: 1.35; margin-top: 2px; }
.tc-row2 { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.tc-timer { flex: 1 1 auto; height: 8px; border-radius: 6px; background: var(--g-accent-soft); overflow: hidden; }
.tc-timer > i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--g-accent), var(--g-accent-lt));
  transform-origin: left; transition: transform .2s linear;
}
.tc-timer.low > i { background: linear-gradient(90deg, var(--tc-bad), #E08A3C); }
.tc-reveal {
  flex: 0 0 auto; font: 600 11px/1 var(--sans, system-ui, sans-serif);
  color: var(--g-accent); background: transparent; border: 1px solid var(--g-accent-edge);
  border-radius: 999px; padding: 4px 11px; cursor: pointer;
}
.tc-reveal:hover { border-color: var(--g-accent); }
.tc-reveal.on { background: var(--g-accent-soft); }

/* The example tiles and the five readouts share one row. The example gets
   the room it needs to actually be readable, the stats take what is left in
   an auto-fitting grid so they stay legible instead of shrinking forever,
   and on a narrow phone the stats wrap under the tiles rather than squeeze
   both. Either way the target card stays four lines tall, which is what
   gives the board its height back. */
.tc-row3 { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 8px; }
.tc-t-preview { flex: 0 0 auto; display: flex; align-items: center; gap: 5px; }
.tc-tp { width: 46px; height: 62px; flex: 0 0 auto; display: flex; filter: drop-shadow(0 2px 4px rgba(0,0,0,.32)); }
.tc-tp .tl { width: 100%; height: 100%; }

/* ---------- HUD chips ---------- */
/* Left to itself the card would stretch the five readouts across the whole
   header, which reads as five empty boxes. Capping the row keeps each chip at
   a label-with-a-number size and parks the cluster on the right, across from
   the example tiles. */
.tc-hud {
  flex: 1 1 190px; min-width: 0; margin-top: 0; max-width: 600px; margin-left: auto;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(46px, 1fr)); gap: 5px;
}
.tc-stat {
  min-width: 0;
  background: var(--g-glass); border: 1px solid var(--g-line); border-radius: 9px;
  padding: 4px 8px; display: flex; flex-direction: column; gap: 1px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.14), var(--g-shadow-sm);
}
.tc-stat-l {
  font-size: 8.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--g-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tc-stat b { font-size: 15px; line-height: 1.15; font-weight: 700; color: var(--g-fg); font-variant-numeric: tabular-nums; }
.tc-combo-flash { animation: tc-flash .5s ease; }
@keyframes tc-flash { 0% { transform: scale(1); } 35% { transform: scale(1.18); color: var(--g-accent); } 100% { transform: scale(1); } }
/* Sits in the timer row: the dots say the same thing as the Finds readout,
   so they belong next to the clock, not on a line of their own. */
.tc-pips { display: flex; flex: 0 0 auto; flex-wrap: nowrap; gap: 4px; }
.tc-pip { width: 8px; height: 8px; border-radius: 50%; background: var(--g-line); transition: background .2s ease, transform .2s ease; }
.tc-pip.on { background: var(--g-accent); transform: scale(1.15); box-shadow: 0 0 0 3px var(--g-accent-soft); }

/* ---------- board (fills remaining space; layoutBoard() in game.js sets
   exact aspect-correct track sizes, centered here so short racks sit mid-board).
   flex-basis is 0, not auto: the height has to come from the space left over,
   never from the tiles inside it, or the fit measures a box that its own
   content then changes. ---------- */
.tc-board {
  flex: 1 1 0; min-height: 0;
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  justify-content: center; align-content: center; gap: 8px;
}
.tc-cell {
  position: relative; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px; cursor: pointer; user-select: none;
  transition: transform .1s ease, box-shadow .14s ease;
}
.tc-cell > * { width: 100%; height: 100%; display: block; }
.tc-cell svg { width: 100%; height: 100%; display: block; }
.tc-cell:hover { transform: translateY(-2px); }
.tc-cell:active { transform: translateY(1px); }
.tc-cell.sel { box-shadow: 0 0 0 3px var(--g-accent), var(--g-shadow-md); transform: translateY(-3px); }
.tc-cell.bad { box-shadow: 0 0 0 3px var(--tc-bad); }
.tc-cell.gone { animation: tc-pop .35s ease forwards; pointer-events: none; }
.tc-cell.tc-flower { cursor: default; opacity: .46; filter: grayscale(.35); }
.tc-cell.tc-flower:hover { transform: none; }
.tc-cell.tc-flower.sel, .tc-cell.tc-flower.bad { box-shadow: none; }
@keyframes tc-pop { to { transform: scale(.2) rotate(8deg); opacity: 0; } }

/* ---------- footer ---------- */
.tc-footer { flex: 0 0 auto; display: flex; gap: 10px; align-items: center; }
.tc-hint { font-size: 12px; color: var(--g-muted); flex: 1; min-width: 0;
  line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- floating score + toast + shake ---------- */
.tc-float {
  position: absolute; left: 50%; top: 36%; transform: translateX(-50%);
  font: 800 24px/1 Georgia, serif; color: var(--g-accent);
  pointer-events: none; z-index: 75; animation: tc-float 1s ease forwards;
}
.tc-float-big { font-size: 30px; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.4); }
@keyframes tc-float { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -46px); } }
/* Streak glow. Five finds in a row is where the multiplier jumps to x3, so the
   rack gets a warm rim while the streak is alive. Painted with the shell accent
   rather than a fixed brass hex, so the theme switcher moves it too. */
.tc-surge .tc-board { position: relative; }
.tc-surge .tc-board::after {
  content: ""; position: absolute; inset: -4px; border-radius: 16px;
  border: 2px solid var(--g-accent); pointer-events: none;
  animation: tc-surge 1.6s ease-in-out infinite;
}
@keyframes tc-surge { 0%, 100% { opacity: .22; } 50% { opacity: .68; } }
.tc-shake { animation: tc-shake .32s ease; }
@keyframes tc-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}
.tc-toast {
  position: absolute; left: 50%; top: 16%; transform: translate(-50%, -12px);
  background: rgba(6,18,12,.9); color: #fff; border: 1px solid var(--g-accent-edge);
  border-radius: 999px; padding: 8px 18px; font: 600 14px/1 var(--sans, system-ui, sans-serif);
  letter-spacing: .02em; z-index: 80; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; white-space: nowrap;
}
.tc-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- overlays (start/end + help) ---------- */
.tc-overlay, .tc-help {
  inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
/* The help sheet is a genuine full-screen dialog, so it pins to the viewport
   instead of to the game box. */
.tc-help { position: fixed; background: rgba(6,18,12,.86); transition: opacity .18s ease; }
/* The start panel stays inside the game box. Pinned over the whole box at the
   shared z-index of 70 it also swallowed the sticky topbar (z-index 40), which
   left Menu, Restart and All games dead to the touch until the panel was
   dismissed. Absolute plus a lower z-index keeps the bar live underneath. */
.tc-overlay { position: absolute; background: rgba(6,18,12,.92); z-index: 35; }
.tc-help[hidden] { display: none; }
.tc-overlay.hide { display: none; }

/* ---------- level-up flourish (auto, no modal) ---------- */
.tc-levelup {
  position: absolute; inset: 0; z-index: 72;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  background: rgba(6,18,12,.5);
  opacity: 0; transition: opacity .25s ease;
}
.tc-levelup[hidden] { display: none; }
.tc-levelup.show { opacity: 1; }
.tc-lu-card {
  background: linear-gradient(160deg, var(--g-card), var(--g-panel));
  border: 1px solid var(--g-accent-edge); border-top: 3px solid var(--g-accent);
  border-radius: 18px; padding: 22px 30px; text-align: center;
  box-shadow: var(--g-shadow-lg);
  transform: scale(.88); transition: transform .32s cubic-bezier(.2,.8,.3,1);
}
.tc-levelup.show .tc-lu-card { transform: scale(1); }
.tc-lu-kicker { font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--g-accent); font-weight: 700; }
.tc-lu-stars { font-size: 30px; margin: 8px 0 2px; letter-spacing: 4px; }
.tc-lu-stars .on { color: var(--g-accent); }
.tc-lu-stars .off { color: var(--g-line); }
.tc-lu-bonus { font-size: 15px; font-weight: 700; color: var(--g-fg); }
.tc-lu-next { font-size: 12px; color: var(--g-muted); margin-top: 6px; }

.tc-panel {
  background: linear-gradient(160deg, var(--g-card), var(--g-panel));
  border: 1px solid var(--g-accent-edge); border-top: 3px solid var(--g-accent);
  border-radius: 18px; padding: 26px 24px; max-width: 440px; text-align: center;
  box-shadow: var(--g-shadow-lg);
}
.tc-panel-kicker { font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--g-accent); font-weight: 700; }
.tc-panel h2 { font-family: Georgia, serif; margin: 6px 0 10px; font-size: 27px; color: var(--g-heading); }
.tc-panel p { font-size: 14px; color: var(--g-muted); line-height: 1.55; margin: 0 0 18px; }
.tc-start { font-size: 15px; padding: 11px 26px; }
.tc-pips-big { margin: 14px 0 4px; }
.tc-star { font-size: 26px; color: var(--g-line); margin: 0 2px; }
.tc-star.on { color: var(--g-accent); }
.tc-ov-sub { font-size: 12.5px; color: var(--g-muted); margin-top: 8px; line-height: 1.45; }

.tc-help-card {
  background: linear-gradient(160deg, var(--g-card), var(--g-panel));
  border: 1px solid var(--g-accent-edge); border-top: 3px solid var(--g-accent);
  border-radius: 18px; padding: 24px 24px 22px; max-width: 560px; max-height: 86%; overflow: auto;
  box-shadow: var(--g-shadow-lg); position: relative;
}
.tc-help-card h2 { font-family: Georgia, serif; margin: 0 0 10px; font-size: 23px; color: var(--g-heading); }
.tc-help-card h3 { font-size: 12.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--g-accent); margin: 16px 0 6px; }
.tc-help-lead { font-size: 14px; color: var(--g-fg); line-height: 1.55; margin: 0 0 6px; }
.tc-help-card p { font-size: 13px; color: var(--g-muted); line-height: 1.55; margin: 6px 0; }
.tc-help-card em { color: var(--g-fg); font-style: normal; font-weight: 700; }
.tc-help-list { margin: 6px 0; padding-left: 1.2em; color: var(--g-muted); font-size: 13px; line-height: 1.7; }
.tc-help-list b { color: var(--g-fg); }
.tc-help-list a { color: var(--g-accent); }
.tc-help-fine { font-size: 11px; color: var(--g-muted); opacity: .8; margin-top: 14px; border-top: 1px solid var(--g-line); padding-top: 10px; }
.tc-help-x {
  position: absolute; top: 12px; right: 14px; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--g-line); background: var(--g-glass); color: var(--g-fg);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.tc-help-x:hover { border-color: var(--g-accent); color: var(--g-accent); }

/* ---------- small-screen tweaks (track sizes come from layoutBoard) ---------- */
@media (max-width: 430px) {
  .tc-board { gap: 6px; }
  .tc-t-name { font-size: 21px; }
  .tc-tp { width: 44px; height: 59px; }
  /* Sized so the row splits at 375px rather than at the 1px edge: a 390px
     phone keeps the chips beside the example, anything narrower drops them
     onto one tidy five-across line below. */
  .tc-hud { flex-basis: 140px; }
  .tc-stat { padding: 4px 5px; }
  .tc-stat-l { font-size: 7.5px; letter-spacing: 0; }
  .tc-stat b { font-size: 14px; }
  .tc-t-desc { font-size: 12px; }
  /* One line with an ellipsis hid half of the coaching text on a phone. Two
     lines is worth the height. */
  .tc-hint {
    white-space: normal; font-size: 11.5px; line-height: 1.35;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  }
}
