/* ================================================================
   CARROT MERGE — Page styles  v1.0.11
================================================================ */

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

:root {
  --cm-bg:        #1a0f09;
  --cm-surface:   rgba(255,230,180,0.07);
  --cm-border:    rgba(255,210,140,0.18);
  --cm-cream:     #F5EDD8;
  --cm-caramel:   #c97a35;
  --cm-muted:     rgba(245,237,216,0.50);
  --cm-topbar-h:  64px;
  --gap:          10px;
  --pad:          12px;
  --tr:           10px;
  --r:            16px;
}
@media (min-width:480px) { :root { --cm-topbar-h: 72px; } }
@media (min-width:600px) { :root { --cm-topbar-h: 76px; } }

.cm-body {
  background: var(--cm-bg);
  background-image: url('images/carrot-merge-wallpaper.svg');
  background-size: cover;
  background-position: center center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  font-family: 'DM Sans', system-ui, sans-serif;
  color: var(--cm-cream);
}
@supports (-webkit-touch-callout:none) {
  .cm-body { background-attachment: scroll; }
}
.cm-body #hdr { display: none; }
.cm-body #cp-footer-placeholder { display: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ================================================================
   AMBIENT BACKGROUND
================================================================ */
.pw-bg {
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none; overflow: hidden;
}
.pw-bg-glow {
  position: absolute; border-radius: 50%;
  filter: blur(40px); opacity: 0.18; will-change: transform;
}
.pw-bg-glow--a {
  width: 500px; height: 400px; top: -100px; left: -100px;
  background: radial-gradient(ellipse, #c97a35 0%, transparent 70%);
  animation: glowDrift 14s ease-in-out infinite alternate;
}
.pw-bg-glow--b {
  width: 400px; height: 300px; bottom: 80px; right: -80px;
  background: radial-gradient(ellipse, #8B5E3C 0%, transparent 70%);
  animation: glowDrift 18s ease-in-out infinite alternate-reverse;
}
.pw-bg-glow--c {
  width: 300px; height: 200px; top: 38%; left: 50%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, #7A5030 0%, transparent 70%);
  opacity: 0.10;
  animation: glowDriftC 23s ease-in-out infinite alternate;
}
@keyframes glowDrift {
  0%   { transform: translate(0,0) scale(1); }
  100% { transform: translate(40px,30px) scale(1.1); }
}
@keyframes glowDriftC {
  0%   { transform: translateX(-50%) translate(0,0) scale(1); }
  100% { transform: translateX(-50%) translate(40px,30px) scale(1.1); }
}
@media (prefers-reduced-motion:reduce) {
  .pw-bg-glow { animation: none !important; }
}

#cm-bg {
  position: fixed; inset: 0;
  pointer-events: none; overflow: hidden; z-index: 0;
}
.cm-floater {
  position: absolute; bottom: -60px; opacity: .08;
  animation: cmFloatUp var(--d,12s) var(--dl,0s) linear infinite;
}
@keyframes cmFloatUp {
  0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
  6%   { opacity: .08; }
  94%  { opacity: .08; }
  100% { transform: translateY(-115vh) rotate(var(--sp,300deg)); opacity: 0; }
}
@media (prefers-reduced-motion:reduce) { .cm-floater { animation: none; } }

/* Cream paw trail — random prints appear and fade on the background */
.cm-paw-trail {
  position: absolute; pointer-events: none; object-fit: contain;
  opacity: 0;
  transform: scale(0) rotate(var(--rot, 0deg));
  animation: pawTrail 3.2s ease-out forwards;
}
@keyframes pawTrail {
  0%   { opacity: 0;    transform: scale(0)   rotate(var(--rot, 0deg)); }
  15%  { opacity: 0.14; transform: scale(1)   rotate(var(--rot, 0deg)); }
  75%  { opacity: 0.09; transform: scale(1)   rotate(var(--rot, 0deg)); }
  100% { opacity: 0;    transform: scale(1.1) rotate(var(--rot, 0deg)); }
}

/* img-based floater (cream paw) */
.cm-floater-paw { object-fit: contain; }

/* ================================================================
   TOPBAR
================================================================ */
.pw-topbar {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 200;
  background: rgba(26,15,9,0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--cm-border);
  height: var(--cm-topbar-h);
}
.pw-topbar-inner {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px;
  max-width: 520px; margin: 0 auto;
  height: 100%;
}
.pw-topbar-title {
  display: flex; flex-direction: column; align-items: center;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(22px, 5.5vw, 38px);
  font-weight: 400; color: #f2e8d0;
  letter-spacing: 0;
  text-shadow: 0 2px 20px rgba(0,0,0,0.7);
  min-width: 0; overflow: hidden;
}
.pw-topbar-em {
  font-style: italic; color: #c97a35;
  font-family: 'Cormorant Garamond', Georgia, serif;
}
.pw-topbar-left  { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.pw-topbar-right { display: flex; gap: 4px; flex-shrink: 0; }
.pw-home-logo {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; opacity: 0.70;
  transition: opacity 0.2s; text-decoration: none; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.pw-home-logo:hover { opacity: 0.95; }
.pw-home-logo img  { display: block; width: 32px; height: 32px; }
.pw-icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--cm-surface);
  border: 1px solid var(--cm-border);
  color: var(--cm-cream); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.pw-icon-btn:hover, .pw-icon-btn:active {
  background: rgba(255,210,140,0.18); transform: scale(1.08);
}
.pw-icon-btn:focus-visible {
  outline: 2px solid #f4cf8a; outline-offset: 2px;
}

/* ================================================================
   MAIN CONTENT
================================================================ */
.cm-main {
  position: relative; z-index: 1;
  padding-top: calc(var(--cm-topbar-h) + 14px);
  padding-bottom: max(40px, env(safe-area-inset-bottom, 40px));
  display: flex; flex-direction: column;
  align-items: center; gap: 12px;
  max-width: 480px; margin: 0 auto;
  padding-left: 14px; padding-right: 14px;
}

/* ── Score bar — centred ── */
.cm-scorebar {
  width: 100%;
  display: flex;
  gap: 8px;
  justify-content: center;
}
.cm-sbox {
  background: var(--cm-surface);
  border: 1px solid var(--cm-border);
  border-radius: 14px;
  padding: 8px 16px;
  text-align: center;
  min-width: 90px;
  box-shadow: 0 2px 10px rgba(90,45,5,.14), inset 0 1px 0 rgba(255,255,255,.06);
}
.cm-slbl {
  font-size: .58rem; text-transform: uppercase;
  letter-spacing: 1.8px; color: var(--cm-muted); font-weight: 700;
}
.cm-sval {
  font-family: 'Bree Serif', Georgia, serif;
  font-size: 1.2rem; font-weight: 900;
  letter-spacing: -.5px; color: var(--cm-cream);
}
.cm-sval.pop { animation: cmValPop .28s ease; }
@keyframes cmValPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.35); color: var(--cm-caramel); }
  100% { transform: scale(1); }
}

/* ================================================================
   BOARD
================================================================ */
.cm-board-wrap { width: 100%; }

#board {
  width: 100%; aspect-ratio: 1/1;
  background: linear-gradient(148deg, #8B5E3C 0%, #6B3E20 100%);
  border-radius: 22px; position: relative;
  box-shadow:
    0 10px 42px rgba(80,40,5,.32),
    0 3px 10px rgba(0,0,0,.18),
    inset 0 1px 0 rgba(255,255,255,.10);
  user-select: none; touch-action: none;
  isolation: isolate;
  transition: background .3s;
}
#board::after {
  content: ''; position: absolute; inset: 0; border-radius: 22px;
  background: repeating-linear-gradient(
    89deg,
    transparent 0, transparent 13px,
    rgba(255,255,255,.015) 13px, rgba(255,255,255,.015) 14px
  );
  pointer-events: none; z-index: 0;
}

.gcells, #tl {
  position: absolute;
  top: var(--pad); right: var(--pad);
  bottom: var(--pad); left: var(--pad);
}
.gcells {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap); z-index: 1;
}
.gcell {
  background: rgba(0,0,0,.18);
  border-radius: var(--tr);
  box-shadow: inset 0 2px 5px rgba(0,0,0,.14);
}
#tl { z-index: 2; }

/* ================================================================
   TILES
================================================================ */
.tile {
  position: absolute;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  border-radius: var(--tr); font-weight: 900;
  transition: transform .12s cubic-bezier(.25,.46,.45,.94);
  will-change: transform; z-index: 2;
  box-shadow:
    0 4px 10px rgba(0,0,0,.28),
    inset 0 1px 0 rgba(255,255,255,.28),
    inset 0 -1px 0 rgba(0,0,0,.08);
}
.te, .tn { pointer-events: none; line-height: 1; }
.tn { font-family: 'DM Sans', system-ui, sans-serif; font-weight: 700; }

.t2    { background: #F5EDD8; color: #4a2c0a; }
.t4    { background: #486CA0; color: #fff; }
.t8    { background: #509458; color: #fff; }
.t16   { background: #694894; color: #fff; }
.t32   { background: #B48A14; color: #fff; }
.t64   { background: #B06050; color: #fff; }
.t128  { background: #8B5E3C; color: #fff; }
.t256  { background: #C96820; color: #fff; }
.t512  { background: #4A2510; color: #F5EDD8; }
.t1024 { background: #7A1825; color: #F5EDD8; }
.t2048 {
  background: linear-gradient(135deg, #E8C44A, #c97a35);
  color: #fff;
  box-shadow:
    0 0 24px rgba(232,196,74,.45), 0 4px 10px rgba(0,0,0,.3),
    inset 0 1px 0 rgba(255,255,255,.5);
  animation: cmGoldPulse 1.6s ease-in-out infinite;
}
@keyframes cmGoldPulse {
  0%,100% { box-shadow: 0 0 18px rgba(232,196,74,.35), 0 4px 10px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.5); }
  50%     { box-shadow: 0 0 40px rgba(232,196,74,.70), 0 4px 10px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.5); }
}
@media (prefers-reduced-motion:reduce) { .t2048 { animation: none; } }

#board.board-won {
  box-shadow:
    0 0 0 3px rgba(232,196,74,0.55),
    0 10px 42px rgba(80,40,5,.32),
    0 3px 10px rgba(0,0,0,.18),
    inset 0 1px 0 rgba(255,255,255,.10);
  transition: box-shadow .4s ease;
}

@keyframes spawnAnim {
  0%   { transform: var(--pos) scale(0);    opacity: 0; }
  62%  { transform: var(--pos) scale(1.16); opacity: 1; }
  100% { transform: var(--pos) scale(1); }
}
.tile-new { animation: spawnAnim .22s cubic-bezier(.2,.8,.3,1.1) forwards; }

@keyframes popAnim {
  0%   { transform: var(--pos) scale(1); }
  35%  { transform: var(--pos) scale(1.2); }
  70%  { transform: var(--pos) scale(.96); }
  100% { transform: var(--pos) scale(1); }
}
.tile-pop { animation: popAnim .22s ease forwards; }

.prt {
  position: fixed; border-radius: 50%;
  pointer-events: none; z-index: 500; margin: 0;
  animation: prtBurst var(--d,.5s) ease-out forwards;
}
@keyframes prtBurst {
  0%   { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--px),var(--py)) scale(0); opacity: 0; }
}

.sfloat {
  position: fixed; font-size: .95rem; font-weight: 900;
  color: var(--cm-caramel);
  pointer-events: none; z-index: 300;
  text-shadow: 0 1px 3px rgba(0,0,0,.2);
  animation: sfAnim .9s ease-out forwards;
}
@keyframes sfAnim {
  0%   { transform: translateY(0) scale(1);    opacity: 1; }
  100% { transform: translateY(-56px) scale(.8); opacity: 0; }
}

/* ================================================================
   ACHIEVEMENTS
================================================================ */
.cm-sec-lbl {
  width: 100%; font-size: .7rem;
  text-transform: uppercase; letter-spacing: 2px;
  color: var(--cm-muted); font-weight: 700;
}
.cm-badges { width: 100%; display: flex; flex-wrap: wrap; gap: 7px; }
.cm-badge {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px;
  background: var(--cm-surface);
  border: 1px solid var(--cm-border);
  border-radius: 20px;
  font-size: .72rem; font-weight: 700;
  color: var(--cm-muted); opacity: .45;
  box-shadow: 0 2px 6px rgba(0,0,0,.14);
  transition: opacity .35s, transform .35s, box-shadow .35s, color .35s, background .35s;
  cursor: default;
}
.cm-badge.on {
  opacity: 1;
  color: var(--cm-cream);
  transform: scale(1.04);
  box-shadow: 0 4px 14px rgba(0,0,0,.22);
  background: rgba(201,122,53,0.18);
  border-color: rgba(201,122,53,0.35);
}
.cm-badge .bi { font-size: .9rem; }
.cm-badge img.bi { display:inline-block; width:16px; height:16px; object-fit:contain; opacity:.35; vertical-align:middle; transition:opacity .35s; }
.cm-badge.on img.bi { opacity:1; }

/* ================================================================
   TOAST — top position, consistent with Pawdle + Connect Paws
================================================================ */
#cm-toast {
  position: fixed;
  top: calc(var(--cm-topbar-h) + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  opacity: 0;
  background: linear-gradient(135deg, rgba(255,200,100,.95), rgba(200,130,50,.95));
  color: #2c1a0a;
  border-radius: 22px; padding: 11px 22px;
  font-size: .83rem; font-weight: 700;
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
  z-index: 700;
  transition: transform .28s cubic-bezier(.2,.8,.3,1.1), opacity .22s;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  max-width: calc(100vw - 40px);
  backdrop-filter: blur(6px);
}
#cm-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ================================================================
   MODALS
================================================================ */
.cm-overlay {
  display: none; position: fixed; inset: 0; z-index: 600;
  background: rgba(0,0,0,.60); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  align-items: center; justify-content: center; padding: 20px;
}
.cm-overlay.open { display: flex; }
.cm-modal {
  background: linear-gradient(160deg, #2e1a0c, #1e1008);
  border: 1.5px solid rgba(255,210,140,0.22);
  border-radius: 26px; padding: 28px 24px 22px;
  text-align: center; max-width: 320px; width: 100%;
  box-shadow: 0 24px 64px rgba(0,0,0,.45);
  animation: cmModalPop .3s cubic-bezier(.2,.8,.3,1.1);
}
@keyframes cmModalPop {
  0%   { transform: scale(.72); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}
.cm-mico { font-size: 3.2rem; margin-bottom: 10px; }
.cm-mico img { display: block; margin: 0 auto; object-fit: contain; }
.cm-mtit {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 2rem; font-weight: 400;
  color: var(--cm-cream); letter-spacing: -.5px; margin-bottom: 10px;
}

/* Character row in modals */
.cm-char-row {
  display: flex; align-items: flex-end; gap: 10px;
  justify-content: center; margin: 0 0 10px;
}
.cm-char-row:empty { display: none; margin: 0; }
.cm-char-img {
  width: 58px; height: 58px; object-fit: contain; flex-shrink: 0;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,0.45));
}
.cm-char-bubble {
  background: rgba(255,210,140,0.07);
  border: 1px solid var(--cm-border);
  border-radius: 14px 14px 14px 4px;
  padding: 8px 12px;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: .88rem; font-style: italic;
  color: var(--cm-cream); line-height: 1.4;
  text-align: left; max-width: 190px;
}
.cm-char-bubble strong {
  display: block;
  font-family: 'DM Sans', sans-serif;
  font-size: .6rem; font-style: normal;
  font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--cm-caramel);
  margin-bottom: 2px;
}

.cm-msub {
  font-size: .85rem; color: var(--cm-muted);
  line-height: 1.55; margin-bottom: 12px;
}
.cm-mscr {
  font-size: 1.25rem; font-weight: 900;
  color: var(--cm-caramel); margin-bottom: 16px;
}
.cm-mbtns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.cm-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 10px 16px; border: none; border-radius: 12px;
  font-size: .8rem; font-weight: 700;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer; white-space: nowrap;
  transition: transform .12s, box-shadow .12s;
  -webkit-tap-highlight-color: transparent;
}
.cm-btn-a {
  background: linear-gradient(135deg, #c97a35, #8B5E3C);
  color: #fff;
  box-shadow: 0 4px 14px rgba(201,122,53,.3);
}
.cm-btn-a:hover  { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(201,122,53,.42); }
.cm-btn-a:active { transform: translateY(0); }
.cm-btn-b {
  background: rgba(255,230,180,0.08);
  color: var(--cm-cream);
  border: 1px solid var(--cm-border);
}
.cm-btn-b:hover  { transform: translateY(-2px); background: rgba(255,230,180,0.14); }
.cm-btn-b:active { transform: translateY(0); }

/* Cross-promo links in modals */
.cm-xpromo {
  display: flex; gap: 10px; justify-content: center;
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid rgba(255,210,140,0.12);
}
.cm-xlink {
  font-size: .72rem; font-weight: 700; letter-spacing: .04em;
  color: var(--cm-caramel); text-decoration: none;
  padding: 5px 12px;
  border: 1px solid rgba(201,122,53,0.28);
  border-radius: 12px;
  transition: background .18s;
}
.cm-xlink:hover { background: rgba(201,122,53,0.12); }

/* ================================================================
   HOW TO PLAY PANEL
================================================================ */
.pw-overlay {
  position: fixed; inset: 0; z-index: 800;
  display: flex; align-items: center; justify-content: center;
  background: rgba(14,8,3,0.82);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  padding: 20px;
  animation: overlayIn .22s ease;
}
.pw-overlay[hidden] { display: none; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.pw-panel {
  background: linear-gradient(160deg, #2e1a0c, #1e1008);
  border: 1.5px solid rgba(255,210,140,0.22);
  border-radius: 24px; padding: 22px 18px 20px;
  width: 100%; max-width: 380px; position: relative;
  max-height: 90vh; max-height: 90dvh;
  overflow-y: auto; overscroll-behavior: contain;
  animation: panelUp .28s cubic-bezier(0.34,1.4,0.64,1);
}
@keyframes panelUp {
  from { transform: translateY(30px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.pw-panel-close {
  position: absolute; top: 10px; right: 10px;
  width: 44px; height: 44px; border-radius: 50%;
  background: transparent; border: none;
  color: var(--cm-muted); font-size: 14px;
  cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  transition: color 0.2s;
}
.pw-panel-close::before {
  content: ''; position: absolute;
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,210,140,0.1);
  border: 1px solid rgba(255,210,140,0.2);
  transition: background 0.2s;
}
.pw-panel-close:hover::before { background: rgba(255,210,140,0.2); }
.pw-panel-close:hover { color: var(--cm-cream); }
.pw-panel-close span { position: relative; z-index: 1; }
.pw-panel-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 22px; color: var(--cm-cream);
  margin-bottom: 6px; text-align: center;
}
.pw-panel-sub {
  font-size: 13px; color: var(--cm-muted);
  text-align: center; margin-bottom: 18px;
}
.cm-tile-guide {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; margin-bottom: 18px;
}
.cm-tile-pip {
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  font-size: .62rem; font-weight: 700;
  color: var(--cm-muted); letter-spacing: .03em;
}
.cm-tile-swatch {
  width: 40px; height: 40px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 3px 8px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.22);
}
.pw-how-rules {
  background: rgba(255,210,140,0.06);
  border: 1px solid rgba(255,210,140,0.12);
  border-radius: 14px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 7px;
}
.pw-how-rules p {
  font-family: 'DM Sans', sans-serif;
  font-size: 13px; color: var(--cm-muted); line-height: 1.5;
}
.pw-how-rules p strong { color: var(--cm-cream); }

/* ================================================================
   RESPONSIVE
================================================================ */
@media (max-width:400px) {
  .cm-main { padding-left: 10px; padding-right: 10px; gap: 9px; }
  :root    { --gap: 7px; --pad: 9px; }
  .cm-sval { font-size: 1.05rem; }
  .cm-sbox { min-width: 68px; padding: 7px 12px; }
}
@media (prefers-reduced-motion:reduce) {
  .pw-overlay { animation: none; }
  .pw-panel   { animation: none; }
  .cm-modal   { animation: none; }
  .cm-floater { animation: none; }
}
