/* Marmite SameGame — scoped styles (all rules under .samegame to avoid
   clashing with the site's global button/anchor/heading styles). */

.samegame {
  --sg-bg: #1a1206;
  --sg-panel: #2a1d0a;
  --sg-ink: #f4e9c8;
  --sg-gold: #f8d24a;
  --sg-line: #5a4413;
  max-width: 640px;
  margin: 0 0 18px;
}

/* HUD */
.samegame .sg-hud {
  display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: baseline;
  background: var(--sg-panel); border: 1px solid var(--sg-line);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 12px;
  color: var(--sg-ink);
}
.samegame .sg-stat { font-size: .95rem; }
.samegame .sg-stat b { color: var(--sg-gold); font-variant-numeric: tabular-nums; }
.samegame .sg-grow { flex: 1 1 auto; }
.samegame .sg-preview { min-width: 4.5em; text-align: right; font-variant-numeric: tabular-nums; }

.samegame .sg-btn {
  font: inherit; font-size: .85rem; line-height: 1; cursor: pointer;
  background: var(--sg-gold); color: #2a1d0a; border: 0;
  border-radius: 6px; padding: 8px 12px; font-weight: 700;
  min-height: 0; min-width: 0; height: auto;
}
.samegame .sg-btn.sg-alt { background: transparent; color: var(--sg-gold); border: 1px solid var(--sg-gold); }

/* Board */
.samegame .sg-stage { position: relative; }
.samegame .sg-board {
  display: grid; gap: 2px;
  background: #120c04; border: 1px solid var(--sg-line);
  border-radius: 8px; padding: 6px;
  width: 100%; touch-action: manipulation; user-select: none;
}
.samegame .sg-cell {
  position: relative; width: 100%; height: 100%;
  border: 0; padding: 0; margin: 0; cursor: pointer;
  background: transparent; border-radius: 4px;
  min-height: 0; min-width: 0;
  -webkit-appearance: none; appearance: none;
}
.samegame .sg-cell:disabled { cursor: default; }
/* Every occupied cell gets a faint tile "slot" background so narrow tiles
   (the tall soldier in particular) read as a filled square instead of an empty
   gap. Genuinely empty cells (top of columns after play) stay dark. */
.samegame .sg-cell:not(.sg-empty) { background: rgba(244, 233, 200, 0.07); }
.samegame .sg-cell .sg-pip {
  position: absolute; inset: 4%;
  background: var(--img) center / contain no-repeat;
}
.samegame .sg-cell.sg-empty .sg-pip { display: none; }
.samegame .sg-cell.sg-hot .sg-pip { filter: brightness(1.18); }
.samegame .sg-cell.sg-clearing .sg-pip { animation: sg-pop .18s ease forwards; }
@keyframes sg-pop { to { transform: scale(.1); opacity: 0; } }

/* Tile palette: each type points at its Marmite sprite via --img, inherited by
   both the board .sg-pip and the count-bar .sg-cpip.
   t1=jar, t2=toast, t3=love, t4=hate, t5=soldier. */
.samegame .sg-t1 { --img: url(/images/game/game-tile-jar.png?v=20260601g); }
.samegame .sg-t2 { --img: url(/images/game/game-tile-toast.png?v=20260601g); }
.samegame .sg-t3 { --img: url(/images/game/game-tile-love.png?v=20260601g); }
.samegame .sg-t4 { --img: url(/images/game/game-tile-hate.png?v=20260601g); }
.samegame .sg-t5 { --img: url(/images/game/game-tile-soldier.png?v=20260601g); }

/* Count bar: icon + remaining number per type */
.samegame .sg-counts {
  display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center;
  margin-top: 12px; padding: 8px 12px;
  background: var(--sg-panel); border: 1px solid var(--sg-line); border-radius: 8px;
  color: var(--sg-ink);
}
.samegame .sg-count { display: inline-flex; align-items: center; gap: 7px; font-variant-numeric: tabular-nums; }
.samegame .sg-count b { font-size: .95rem; min-width: 2ch; }
.samegame .sg-cpip {
  width: 24px; height: 24px; display: inline-block; flex: 0 0 auto;
  background: var(--img) center / contain no-repeat;
}

/* Magic potion: lives at the right of the count row, dragged onto a tile */
.samegame .sg-potion-wrap { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.samegame .sg-potion {
  background: transparent; border: 0; padding: 2px; line-height: 0; border-radius: 6px;
  cursor: grab; touch-action: none; -webkit-appearance: none; appearance: none;
}
.samegame .sg-potion:active { cursor: grabbing; }
.samegame .sg-potion.sg-spent { opacity: .35; cursor: not-allowed; }
.samegame .sg-potion img { width: 32px; height: 32px; display: block; }
.samegame .sg-potion-charges { color: var(--sg-gold); font-variant-numeric: tabular-nums; font-size: .9rem; font-weight: 700; }
/* Ghost is appended to <body> (outside .samegame), so these rules are unscoped. */
.sg-potion-ghost {
  position: fixed; z-index: 60; pointer-events: none;
  transform: translate(-50%, -50%); line-height: 0;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.5));
}
.sg-potion-ghost img { width: 38px; height: 38px; display: block; }
.samegame .sg-cell.sg-droptarget {
  box-shadow: inset 0 0 0 3px var(--sg-gold), 0 0 10px 2px rgba(248,210,74,.55);
  border-radius: 4px;
}

/* Potion transform: slot-machine through tiles before settling */
.samegame .sg-cell.sg-morphing .sg-pip { animation: sg-morph .3s linear infinite; }
@keyframes sg-morph {
  0%   { transform: scale(.8) rotate(-10deg); }
  50%  { transform: scale(1.12) rotate(10deg); }
  100% { transform: scale(.8) rotate(-10deg); }
}

/* Idle jiggle */
.samegame .sg-cell.sg-jiggle .sg-pip { animation: sg-jiggle .75s ease; transform-origin: 50% 70%; }
@keyframes sg-jiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-8deg) translateY(-2px); }
  45% { transform: rotate(7deg); }
  70% { transform: rotate(-4deg); }
  88% { transform: rotate(2deg); }
}

/* Game-over / win overlay, anchored to the board (not position:fixed, which
   the site CSS overrides) so it is always visible right where the player is. */
.samegame .sg-overlay {
  position: absolute; inset: 0; z-index: 3;
  display: none; align-items: center; justify-content: center;
  background: rgba(18, 12, 4, .86); border-radius: 8px;
}
.samegame .sg-overlay.sg-show { display: flex; }
.samegame .sg-overlay-card { text-align: center; color: var(--sg-ink); padding: 20px 26px; max-width: 90%; }
.samegame .sg-overlay-card #sg-status-msg {
  margin: 0 0 14px; font-size: 1.15rem; font-weight: 700; color: var(--sg-gold); line-height: 1.35;
}
.samegame .sg-hs-entry { margin: 0 0 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.samegame .sg-hs-entry label { font-size: .9rem; }
.samegame .sg-hs-entry input {
  font: inherit; padding: 7px 10px; border-radius: 6px; border: 1px solid var(--sg-line);
  background: #fffdf5; color: #2a1d0a; max-width: 12em; text-align: center;
}

/* High score table */
.samegame .sg-scores { margin-top: 18px; }
.samegame .sg-scores h2 { font-size: 1.05rem; margin: 0 0 8px; }
.samegame .sg-scores table { width: 100%; max-width: 420px; border-collapse: collapse; font-size: .9rem; }
.samegame .sg-scores th, .samegame .sg-scores td {
  text-align: left; padding: 6px 10px; border-bottom: 1px solid #e6ddc2;
}
.samegame .sg-scores th { color: #7a5a16; font-weight: 700; }
.samegame .sg-scores td:nth-child(3), .samegame .sg-scores th:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; }
.samegame .sg-scores .sg-hs-empty { color: #8a7a52; font-style: italic; }

.samegame .sg-note { font-size: .82rem; opacity: .8; margin-top: 12px; line-height: 1.5; }

/* Fullscreen: give the board the whole screen, centred, with the count bar
   under it. Hide the explanatory note and the score table to keep it clean. */
.samegame:fullscreen, .samegame:-webkit-full-screen {
  max-width: none; width: 100vw; height: 100vh; margin: 0; padding: 16px;
  background: var(--sg-bg); box-sizing: border-box;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
}
.samegame:fullscreen .sg-hud, .samegame:-webkit-full-screen .sg-hud { width: min(96vw, 900px); margin: 0; }
.samegame:fullscreen .sg-stage, .samegame:-webkit-full-screen .sg-stage { display: flex; justify-content: center; }
.samegame:fullscreen .sg-board, .samegame:-webkit-full-screen .sg-board { width: auto; }
.samegame:fullscreen .sg-note, .samegame:-webkit-full-screen .sg-note,
.samegame:fullscreen .sg-scores, .samegame:-webkit-full-screen .sg-scores { display: none; }
