/* ════════════════════════════════════════════════════════════════════════
   Jeng Jang Mahjong
   ════════════════════════════════════════════════════════════════════════ */

:root {
  --cream: #fff1d2;
  --paper: #ffe6b7;
  --brown: #793616;
  --red: #9e140e;
  --gold: #ffd552;
  --orange: #f27f17;
  --ink: #203347;
  --shadow: rgba(28, 11, 4, 0.48);

  /* tile skin — see the .theme-* blocks; :root mirrors Jade as the default */
  --tile-edge: #b6d6c2;
  --tile-edge-dark: #86ab95;
  --tile-face-a: #f8fffb;
  --tile-face-b: #dbeee3;
  --tile-rim: rgba(28, 92, 66, 0.28);
  --tile-gloss: linear-gradient(160deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0) 55%);
  --tile-back-a: #22936a;
  --tile-back-b: #0c5b41;
  --tile-back-rim: #7fe6b6;
  --sym-blue: #1b4f8f;
  --sym-green: #0f6b46;
  --sym-red: #b32b28;
  --sym-ink: #26313f;
  --sym-hole: #fffdf3;

  font-family: ui-rounded, "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 10%, rgba(255, 208, 120, 0.28), transparent 28rem),
    linear-gradient(145deg, #1a4f49, #300b08 58%, #0f0a09);
  color: var(--cream);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
  border-radius: 6px;
}

.phone-shell {
  position: relative;
  width: min(100vw, 430px);
  height: 100svh;
  overflow: hidden;
  background: #100b09;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
}

.screen.is-active {
  display: flex;
  flex-direction: column;
}

/* ─── Lobby ─────────────────────────────────────────────────────────── */

.screen-lobby {
  background:
    linear-gradient(rgba(54, 21, 8, 0.1), rgba(54, 21, 8, 0.62)),
    repeating-linear-gradient(0deg, rgba(71, 34, 11, 0.5) 0 2px, transparent 2px 7px),
    linear-gradient(90deg, transparent 0 8%, rgba(124, 48, 18, 0.8) 8% 9.5%, transparent 9.5% 25%, rgba(124, 48, 18, 0.8) 25% 27%, transparent 27% 49%, rgba(124, 48, 18, 0.8) 49% 51%, transparent 51% 73%, rgba(124, 48, 18, 0.8) 73% 75%, transparent 75% 91%, rgba(124, 48, 18, 0.8) 91% 92.5%, transparent 92.5%),
    linear-gradient(#7a421f 0 8%, #eed2a2 8% 76%, #33140b 76%);
}

.screen-lobby::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 70% 22%, rgba(255, 255, 255, 0.2), transparent 22%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.1), transparent 45% 55%, rgba(0, 0, 0, 0.16));
  pointer-events: none;
}

.screen-lobby::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 18% 24%, rgba(44, 179, 98, 0.7) 0 1.6%, transparent 1.8%),
    radial-gradient(ellipse at 80% 17%, rgba(42, 155, 88, 0.62) 0 2%, transparent 2.2%),
    radial-gradient(ellipse at 63% 41%, rgba(58, 181, 104, 0.5) 0 1.4%, transparent 1.6%);
  animation: leafDrift 4.8s ease-in-out infinite alternate;
  pointer-events: none;
}

.shade {
  position: absolute;
  inset: 0 0 auto;
  height: 18%;
  background: repeating-linear-gradient(0deg, rgba(34, 15, 7, 0.7) 0 2px, rgba(174, 104, 52, 0.35) 2px 5px);
  box-shadow: 0 10px 30px rgba(32, 11, 3, 0.32);
}

.topbar,
.game-header {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(14px, env(safe-area-inset-top)) 14px 0;
}

.avatar-button {
  position: relative;
  width: 62px;
  height: 62px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, #28bfd6, #ffcf5c 54%, #188bae);
  box-shadow: 0 4px 0 #713616, 0 8px 14px var(--shadow);
}

.avatar-face {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #ffe9bd, #d99a56 62%, #8a4c1c);
  font-size: 27px;
  line-height: 1;
}

.avatar-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 28px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #294d87;
  border: 2px solid #ffe1a8;
  color: white;
  font-size: 13px;
  font-weight: 900;
}

.leaf-bank {
  min-width: 96px;
  height: 46px;
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 3px solid #d98943;
  border-radius: 10px;
  background: linear-gradient(#9d5527, #713015);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.2), 0 5px 0 #42170a;
  color: #ffdca0;
  font-size: 21px;
}

.leaf-plus {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-left: -2px;
  border-radius: 50%;
  background: #3fa14a;
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
}

.leaf-bank:active {
  transform: translateY(3px);
}

.shop-balance {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(122, 65, 42, 0.1);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.95;
}

.shop-balance b {
  font-size: 22px;
  text-transform: none;
  letter-spacing: 0;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.level-card {
  display: grid;
  justify-items: center;
  gap: 1px;
  padding: 10px 4px;
  border: 2px solid rgba(122, 65, 42, 0.2);
  border-radius: 12px;
  background: linear-gradient(#fff8e4, #ffeac4);
  color: #7a412a;
}

.level-card.is-current {
  border-color: var(--orange);
  background: linear-gradient(#fff2cf, #ffd98f);
}

.level-card:active {
  transform: translateY(2px);
}

.level-card b {
  font-size: 21px;
  font-variant-numeric: tabular-nums;
}

.level-card span {
  font-size: 11px;
  font-weight: 800;
  opacity: 0.8;
}

.level-card em {
  font-style: normal;
  font-size: 12px;
  color: #c98a1a;
  letter-spacing: 0.06em;
}

.level-card i {
  font-style: normal;
  font-size: 10px;
  font-weight: 700;
  opacity: 0.55;
}

.levels-icon {
  background:
    linear-gradient(0deg, transparent 30%, rgba(122, 60, 24, 0.55) 30% 36%, transparent 36%),
    linear-gradient(90deg, transparent 30%, rgba(122, 60, 24, 0.55) 30% 36%, transparent 36%),
    linear-gradient(0deg, transparent 62%, rgba(122, 60, 24, 0.55) 62% 68%, transparent 68%),
    linear-gradient(90deg, transparent 62%, rgba(122, 60, 24, 0.55) 62% 68%, transparent 68%),
    linear-gradient(145deg, #ffe9b8, #d9a05c);
}

.pack-grid {
  display: grid;
  gap: 10px;
}

.pack {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 2px solid rgba(122, 65, 42, 0.22);
  border-radius: 12px;
  background: linear-gradient(#fff8e4, #ffeac4);
  color: #7a412a;
  text-align: left;
}

.pack:active:not(:disabled) {
  transform: translateY(2px);
}

.pack:disabled {
  opacity: 0.55;
  cursor: default;
}

.pack-leaves {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.pack-leaves i {
  width: 20px;
  height: 11px;
  border-radius: 100% 0;
  background: linear-gradient(135deg, #5ed66f, #0b782a);
  transform: rotate(-28deg);
}

.pack-name {
  font-size: 15px;
  font-weight: 800;
}

.pack-name em {
  font-style: normal;
  font-size: 12px;
  color: #1a7f3c;
}

.pack-price {
  padding: 7px 14px;
  border-radius: 999px;
  background: linear-gradient(#51c843, #188236);
  color: white;
  font-size: 17px;
  font-weight: 900;
  box-shadow: 0 3px 0 #0b5426;
}

.pack:disabled .pack-price {
  background: linear-gradient(#c3b49b, #94836c);
  box-shadow: 0 3px 0 #6d5f4c;
}

.shop-status {
  margin: 12px 0 0;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  color: #1a7f3c;
  min-height: 18px;
}

.leaf-mark {
  width: 26px;
  height: 14px;
  border-radius: 100% 0;
  background: linear-gradient(135deg, #5ed66f, #0b782a);
  transform: rotate(-28deg);
}

.round-actions {
  display: flex;
  gap: 7px;
}

.round-actions button,
.round,
.close {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d68a3b, #8b441c 66%, #5a210f);
  color: #ffedc2;
  font-size: 22px;
  font-weight: 900;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18), 0 4px 0 #3b160b, 0 8px 14px var(--shadow);
}

.round-actions button:active,
.round:active,
.close:active {
  transform: translateY(3px);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18), 0 1px 0 #3b160b;
}

.brand-block {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  margin: clamp(28px, 7vh, 64px) auto 0;
  width: 92%;
  text-align: center;
  color: #fff6de;
  text-shadow: 0 5px 0 #5b230f, 3px 0 0 #5b230f, -3px 0 0 #5b230f, 0 10px 16px rgba(0, 0, 0, 0.32);
}

.brand-name {
  display: flex;
  justify-content: center;
  gap: 8px;
  font-size: min(15.5vw, 66px);
  font-weight: 950;
  line-height: 0.9;
  white-space: nowrap;
}

.brand-name span:first-child {
  font-style: italic;
}

.brand-subtitle {
  margin-top: 10px;
  font-size: min(10vw, 42px);
  font-weight: 950;
  text-transform: uppercase;
}

.lobby-doors {
  position: absolute;
  left: 50%;
  top: 36%;
  width: 74%;
  aspect-ratio: 1;
  transform: translateX(-50%);
  border: 10px solid #8d461d;
  border-radius: 50%;
  background:
    linear-gradient(90deg, transparent 0 49%, #57210d 49% 51%, transparent 51%),
    radial-gradient(circle, rgba(255, 194, 111, 0.24), rgba(87, 31, 12, 0.2) 45%, transparent 46%),
    repeating-linear-gradient(90deg, rgba(120, 46, 16, 0.72) 0 8px, transparent 8px 54px);
  box-shadow: inset 0 0 0 10px rgba(72, 27, 11, 0.36), 0 12px 20px rgba(45, 17, 8, 0.32);
  pointer-events: none;
}

.lobby-doors span {
  position: absolute;
  inset: 36%;
  border: 6px solid #6b2e14;
  border-radius: 50%;
}

.lobby-stats {
  position: relative;
  z-index: 4;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: min(88%, 340px);
  margin: 18px auto 0;
  padding: 10px 8px;
  border: 2px solid rgba(255, 214, 140, 0.28);
  border-radius: 14px;
  background: rgba(44, 18, 8, 0.52);
  backdrop-filter: blur(2px);
  text-align: center;
}

.lobby-stats div + div {
  border-left: 1px solid rgba(255, 214, 140, 0.2);
}

.lobby-stats dt {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #f0c98d;
  opacity: 0.8;
}

.lobby-stats dd {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 900;
  color: #fff2d4;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.side-calls {
  position: relative;
  z-index: 4;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0 12px;
}

.side-call {
  flex: 0 1 92px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  background: transparent;
  color: white;
  font-size: 19px;
  font-weight: 800;
  text-shadow: 0 2px 2px #54200d;
}

.call-label {
  position: relative;
  width: 100%;
  padding: 7px 6px;
  border-radius: 5px;
  background: linear-gradient(#a94920, #7d2e13);
  box-shadow: 0 4px 0 #4b190a;
}

.call-dot {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffdc4a;
  border: 2px solid #7d2e13;
  animation: dotPing 1.4s ease-in-out infinite;
}

.side-call:active {
  transform: translateY(3px);
}

.call-icon {
  width: 66px;
  height: 62px;
  border-radius: 16px;
  border: 4px solid #b66b34;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
}

.task-icon {
  background:
    linear-gradient(0deg, transparent 22%, rgba(122, 60, 24, 0.5) 22% 27%, transparent 27%),
    linear-gradient(0deg, transparent 42%, rgba(122, 60, 24, 0.5) 42% 47%, transparent 47%),
    linear-gradient(0deg, transparent 62%, rgba(122, 60, 24, 0.5) 62% 67%, transparent 67%),
    linear-gradient(145deg, #fff5d8, #e7bc76);
}

.daily-icon {
  background:
    radial-gradient(circle at 50% 42%, #fff 0 12%, transparent 13%),
    radial-gradient(circle at 50% 42%, #ffd34a 0 26%, transparent 27%),
    linear-gradient(135deg, #def9ff, #57bdf4 48%, #0b519a);
}

.lobby-cta {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 0 20px max(20px, env(safe-area-inset-bottom));
}

.best-line {
  margin: 0;
  color: #ffe0a0;
  font-size: 15px;
  font-weight: 800;
  text-shadow: 0 2px 2px rgba(0, 0, 0, 0.5);
}

.level-button {
  position: relative;
  width: min(100%, 330px);
  min-height: 84px;
  margin-top: 26px;
  border-radius: 20px;
  background: linear-gradient(#fb9c22, #d8470a);
  border: 5px solid #ffbd48;
  box-shadow: 0 7px 0 #7a210b, 0 13px 20px rgba(50, 14, 3, 0.36), inset 0 2px 12px rgba(255, 255, 255, 0.38);
  color: white;
  text-shadow: 0 3px 1px #82280c;
}

.level-button:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #7a210b, 0 6px 12px rgba(50, 14, 3, 0.36), inset 0 2px 12px rgba(255, 255, 255, 0.38);
}

.level-button small {
  position: absolute;
  left: 50%;
  top: -26px;
  transform: translateX(-50%);
  min-width: 132px;
  padding: 5px 22px 12px;
  border-radius: 12px 12px 0 0;
  background: linear-gradient(#e83b34, #b81f1d);
  font-size: 20px;
  font-weight: 900;
}

.level-button > span {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: min(9vw, 38px);
  font-weight: 900;
}

.level-button .level-pip {
  width: 30px;
  height: 38px;
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 50%, #ff9f25 0 18%, #b71618 19% 35%, transparent 36%),
    linear-gradient(135deg, #8ce9ff, #1478da);
  border: 3px solid #e4f7ff;
  box-shadow: 0 2px 0 #08529a;
}

.ghost-button {
  padding: 10px 20px;
  border-radius: 999px;
  border: 2px solid rgba(255, 224, 160, 0.5);
  background: rgba(60, 24, 10, 0.55);
  color: #ffe0a0;
  font-size: 16px;
  font-weight: 800;
}

.ghost-button:active {
  transform: translateY(2px);
}

/* ─── Game screen ───────────────────────────────────────────────────── */

.screen-game {
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 87, 70, 0.18), transparent 15rem),
    repeating-radial-gradient(circle at 18% 18%, rgba(255, 209, 102, 0.1) 0 2px, transparent 2px 42px),
    linear-gradient(#9c1512, #6a0908 72%, #350304);
}

.screen-game::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 8% 6%, rgba(255, 200, 190, 0.16) 0 6%, transparent 7%),
    radial-gradient(circle at 92% 12%, rgba(255, 200, 190, 0.12) 0 5%, transparent 6%),
    radial-gradient(circle at 88% 92%, rgba(255, 200, 190, 0.12) 0 6%, transparent 7%),
    radial-gradient(circle at 12% 88%, rgba(255, 200, 190, 0.1) 0 5%, transparent 6%);
  pointer-events: none;
}

.game-header {
  align-items: center;
}

.back {
  font-size: 38px;
  line-height: 0.7;
}

.score {
  text-align: center;
  color: #ffe9c0;
  text-shadow: 0 3px 0 #5a1608;
}

.score span {
  display: block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.74;
}

.score strong {
  display: block;
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}

.game-meta {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(38, 10, 7, 0.42);
  color: #ffd9a2;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.meta-chip i {
  font-style: normal;
  opacity: 0.75;
}

.tray-wrap {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  display: grid;
  justify-items: center;
  gap: 5px;
  margin-top: 8px;
}

.match-tray {
  width: min(68%, 262px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 6px;
  border: 4px solid #b77239;
  border-radius: 10px;
  background: linear-gradient(#3f160c, #1c0705);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
}

.match-tray span {
  aspect-ratio: 1.08;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: rgba(124, 54, 28, 0.42);
  box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.match-tray span.is-filled {
  background: linear-gradient(var(--tile-face-a), var(--tile-face-b));
  box-shadow: 0 0 10px rgba(255, 213, 82, 0.4);
}

.match-tray svg {
  width: 84%;
  height: 84%;
}

.combo-meter {
  position: relative;
  width: min(62%, 236px);
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(38, 10, 7, 0.5);
  overflow: hidden;
  text-align: center;
}

.combo-meter b {
  position: relative;
  z-index: 2;
  color: #fff0b8;
  font-size: 13px;
  font-weight: 900;
}

.combo-meter i {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--fill, 100%);
  background: linear-gradient(90deg, rgba(255, 168, 40, 0.65), rgba(255, 220, 90, 0.65));
  transition: width 250ms linear;
}

.set-status {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  width: max-content;
  max-width: 88%;
  margin: 6px auto 0;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(50, 13, 9, 0.46);
  color: #ffe0a0;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

/* flex-basis 0 keeps this box sized by the column, never by the board inside
   it — otherwise resizing the board resizes its own observer target. */
.board-wrap {
  position: relative;
  z-index: 2;
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 6px 14px;
}

.board {
  position: relative;
  touch-action: manipulation;
}

/* ─── Tiles ─────────────────────────────────────────────────────────── */

.tile {
  position: absolute;
  left: calc(var(--col) * var(--tw) + (var(--maxl) - var(--layer)) * var(--ox) + var(--shift-x, 0px));
  top: calc(var(--row) * var(--th) + (var(--maxl) - var(--layer)) * var(--oy) + var(--shift-y, 0px));
  z-index: calc(var(--layer) * 10000 + var(--row) * 100 + var(--col) + 1);
  width: var(--tw);
  height: var(--th);
  padding: 0;
  background: none;
  transition: transform 150ms cubic-bezier(0.2, 0.8, 0.25, 1), opacity 220ms ease;
}

.tile-body {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--tw) * 0.14);
  background: linear-gradient(150deg, var(--tile-face-a), var(--tile-face-b));
  box-shadow:
    calc(var(--depth) * 0.5) var(--depth) 0 var(--tile-edge),
    calc(var(--depth) * 0.5) var(--depth) 0 1px var(--tile-edge-dark),
    calc(var(--depth) * 0.6) calc(var(--depth) * 1.5) calc(var(--depth) * 1.4) rgba(24, 6, 4, 0.42);
}

.tile-face {
  position: absolute;
  inset: calc(var(--tw) * 0.05);
  display: grid;
  place-items: center;
  border-radius: calc(var(--tw) * 0.1);
  border: 1px solid var(--tile-rim);
  background: var(--tile-gloss);
  overflow: hidden;
}

.tile-face svg {
  width: 88%;
  height: 88%;
}

.tile-face .cjk {
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Songti SC", "Microsoft YaHei", serif;
  font-weight: 700;
}

/* Any tile you cannot play yet lies face down. */
.tile:not(.is-free):not(.is-removed) .tile-body {
  background:
    radial-gradient(circle at 50% 48%, rgba(255, 220, 200, 0.16), transparent 30%),
    linear-gradient(150deg, var(--tile-back-a), var(--tile-back-b));
  box-shadow:
    calc(var(--depth) * 0.5) var(--depth) 0 var(--tile-back-b),
    calc(var(--depth) * 0.5) var(--depth) 0 1px rgba(60, 12, 10, 0.55),
    calc(var(--depth) * 0.6) calc(var(--depth) * 1.5) calc(var(--depth) * 1.4) rgba(24, 6, 4, 0.42);
}

.tile:not(.is-free):not(.is-removed) .tile-face {
  border-color: var(--tile-back-rim);
  background: none;
}

.tile:not(.is-free):not(.is-removed) .tile-face svg {
  opacity: 0;
}

/* Coin motif on the tile back — decorative, not a "blocked" sign. */
.tile:not(.is-free):not(.is-removed) .tile-face::after {
  content: "";
  width: 44%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(255, 205, 175, 0.42);
  box-shadow:
    inset 0 0 0 3px rgba(255, 205, 175, 0.14),
    inset 0 0 0 5px rgba(255, 205, 175, 0.3);
  background: radial-gradient(circle, transparent 0 26%, rgba(255, 205, 175, 0.26) 27% 34%, transparent 35%);
}

/* visible but side-blocked */
.tile.is-locked {
  cursor: default;
}

/* Covered tiles sit deeper in the pile than merely side-blocked ones. */
.tile.is-covered .tile-body {
  filter: brightness(0.88);
}

.tile.is-free .tile-body {
  box-shadow:
    calc(var(--depth) * 0.5) var(--depth) 0 var(--tile-edge),
    calc(var(--depth) * 0.5) var(--depth) 0 1px var(--tile-edge-dark),
    calc(var(--depth) * 0.6) calc(var(--depth) * 1.5) calc(var(--depth) * 1.4) rgba(24, 6, 4, 0.42),
    0 0 0 1px rgba(255, 226, 140, 0.55);
}

.tile.is-selected {
  z-index: 900;
  transform: translateY(calc(var(--th) * -0.16)) scale(1.06);
}

.tile.is-selected .tile-body {
  box-shadow:
    calc(var(--depth) * 0.5) var(--depth) 0 #ffce6b,
    0 0 0 3px #ffb11d,
    0 calc(var(--depth) * 2) calc(var(--depth) * 2.4) rgba(24, 6, 4, 0.5),
    0 0 22px rgba(255, 205, 70, 0.75);
}

.tile.is-matching {
  z-index: 950;
  pointer-events: none;
  animation: squashMatch 380ms cubic-bezier(0.2, 0.85, 0.2, 1) forwards;
}

.tile.is-hint .tile-body {
  animation: hintPulse 800ms ease-in-out infinite;
}

.tile.is-denied {
  animation: deniedTap 320ms ease-out;
}

.tile.is-removed {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.6);
}

.tile:disabled {
  pointer-events: none;
}

/* Sits on the board, where the player's eyes already are, so the chain
   timer is felt rather than checked. */
.chain-badge {
  position: absolute;
  z-index: 8;
  right: 6px;
  top: 6px;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.chain-badge[hidden] {
  display: none;
}

.chain-badge b {
  position: relative;
  z-index: 2;
  color: #fff3c4;
  font-size: 22px;
  font-weight: 950;
  text-shadow: 0 2px 0 #7a2a06, 0 0 12px rgba(255, 190, 60, 0.9);
}

.chain-badge i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(#ffbe3c calc(var(--left, 1) * 360deg), rgba(0, 0, 0, 0.35) 0);
  mask: radial-gradient(circle, transparent 60%, #000 62%);
  -webkit-mask: radial-gradient(circle, transparent 60%, #000 62%);
}

.chain-badge.is-urgent b {
  color: #ffd0d0;
  animation: chainPulse 420ms ease-in-out infinite;
}

.chain-badge.is-urgent i {
  background: conic-gradient(#ff5a4a calc(var(--left, 1) * 360deg), rgba(0, 0, 0, 0.35) 0);
}

@keyframes chainPulse {
  50% { transform: scale(1.16); }
}

.score-pop {
  position: absolute;
  z-index: 999;
  left: 50%;
  top: 12%;
  display: none;
  color: #ffe15a;
  font-size: 32px;
  font-weight: 950;
  white-space: nowrap;
  text-shadow: 0 4px 0 #73150b, 0 8px 16px rgba(0, 0, 0, 0.38);
  pointer-events: none;
}

.score-pop.is-open {
  display: block;
  animation: scoreRise 760ms ease-out forwards;
}

/* ─── Power bar ─────────────────────────────────────────────────────── */

.powerbar {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  gap: min(12vw, 52px);
  padding: 8px 0 max(12px, env(safe-area-inset-bottom));
}

.powerbar button {
  position: relative;
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #8a4419, #5b2710 62%, #40190a);
  border: 3px solid #ffcf6b;
  color: #ffe2a1;
  box-shadow: 0 6px 0 #2d1006, 0 10px 16px rgba(0, 0, 0, 0.4);
}

.powerbar button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #2d1006, 0 5px 10px rgba(0, 0, 0, 0.4);
}

.powerbar svg {
  width: 32px;
  height: 32px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.powerbar .pip {
  position: absolute;
  top: -5px;
  right: -6px;
  min-width: 26px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #d94a24;
  border: 2px solid #ffdb9b;
  color: white;
  font-size: 14px;
  font-weight: 900;
}

.powerbar button.is-empty {
  filter: saturate(0.45) brightness(0.72);
}

.powerbar button.is-empty .pip {
  background: #6c3a2a;
}

/* ─── Modals ────────────────────────────────────────────────────────── */

.modal-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(21, 9, 5, 0.68);
  backdrop-filter: blur(2px);
}

.modal-layer[hidden] {
  display: none;
}

.modal {
  position: relative;
  width: min(100%, 380px);
  /* bound by the phone shell, not the viewport — they differ whenever the
     shell is not exactly 100svh, and the modal would then overflow it */
  max-height: 100%;
  overflow: auto;
  display: none;
  padding: 14px 20px 22px;
  border: 5px solid #9a4a21;
  border-radius: 16px;
  background: linear-gradient(#fff0cf, #ffe2ad);
  color: #7a412a;
  box-shadow: 0 12px 24px rgba(20, 6, 2, 0.5);
  overscroll-behavior: contain;
}

.modal.is-open {
  display: block;
  animation: modalIn 220ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

/* Close sits in flow so it stays put when the body scrolls, then the negative
   bottom margin pulls the title up alongside it into one header band. */
.modal {
  --hdr: 40px; /* close button and title share one header height */
}

.close {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  width: var(--hdr);
  height: var(--hdr);
  margin: 0 -2px calc(var(--hdr) * -1) auto;
  background: radial-gradient(circle at 35% 28%, #fff0b7, #f1ad63 62%, #8b3516);
  color: #8e3519;
  font-size: 26px;
  line-height: 0.7;
}

.modal h2 {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  min-height: var(--hdr);
  margin: 0 0 16px;
  padding: 0 50px;
  border-radius: 999px;
  background: linear-gradient(90deg, #d99d70, #f0c69a 18% 82%, #d99d70);
  border: 2px solid #b3663a;
  color: #512214;
  text-align: center;
  font-size: 23px;
}

.section-label {
  margin: 20px 0 8px;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  opacity: 0.55;
}

.modal-note {
  margin: 16px 0 0;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  opacity: 0.72;
}

.prose {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.45;
}

.prose.muted {
  opacity: 0.6;
  font-size: 14px;
}

.button-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}

.button-row .ghost-button {
  flex: 1;
  border-color: rgba(122, 65, 42, 0.35);
  background: rgba(122, 65, 42, 0.12);
  color: #7a412a;
}

.code-box {
  width: 100%;
  padding: 10px;
  border: 2px solid rgba(122, 65, 42, 0.3);
  border-radius: 10px;
  background: #f7e2bd;
  color: #6b3a22;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  resize: vertical;
}

.reward-track {
  display: flex;
  justify-content: space-around;
  align-items: center;
  min-height: 84px;
  margin-bottom: 12px;
  border-radius: 10px;
  background: linear-gradient(#52210f, #371107);
}

.box {
  width: 54px;
  height: 42px;
  border-radius: 10px 10px 14px 14px;
  transform: perspective(120px) rotateX(12deg);
  border: 3px solid rgba(255, 239, 188, 0.5);
  box-shadow: 0 8px 0 rgba(50, 14, 8, 0.34);
}

.box.is-claimed {
  filter: grayscale(0.8) brightness(0.7);
}

.box.teal { background: linear-gradient(#98dfd8, #51ae9d); }
.box.navy { background: linear-gradient(#395792, #192e62); }
.box.gold { background: linear-gradient(#ffdc79, #e77b28); }

.task-row {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 13px 0;
  border-bottom: 1px solid rgba(138, 72, 42, 0.2);
}

.task-row p {
  margin: 0;
  font-size: 17px;
  font-weight: 750;
}

.task-row strong {
  grid-column: 1 / 3;
  color: #c24624;
  font-size: 16px;
}

.task-row button {
  grid-column: 3 / 4;
  grid-row: 1 / 3;
  min-width: 88px;
  padding: 10px 16px;
  border-radius: 999px;
  background: linear-gradient(#51c843, #188236);
  color: white;
  font-size: 19px;
  font-weight: 850;
  box-shadow: 0 4px 0 #0b5426;
}

.task-row button:disabled {
  background: linear-gradient(#c3b49b, #94836c);
  box-shadow: 0 4px 0 #6d5f4c;
  cursor: default;
}

.tile-chip {
  width: 32px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: #fffaf0;
  border: 2px solid #b6d4c8;
  color: #286a83;
  font-weight: 900;
}

.profile-head {
  display: grid;
  grid-template-columns: 66px 1fr 50px;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.avatar-preview {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #28bfd6, #ffcf5c);
  font-size: 34px;
}

.profile-head input {
  width: 100%;
  min-width: 0;
  padding: 12px 10px;
  border: 0;
  border-radius: 9px;
  background: #efd3a7;
  color: #70412d;
  text-align: center;
  font-size: 21px;
  font-weight: 800;
}

.profile-head button,
.confirm {
  border-radius: 12px;
  background: linear-gradient(#37ba43, #168031);
  color: white;
  font-size: 21px;
  font-weight: 900;
  box-shadow: 0 5px 0 #0e5323;
}

.profile-head button {
  height: 50px;
}

.profile-head button:active,
.confirm:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #0e5323;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.avatar-grid button {
  aspect-ratio: 1;
  border-radius: 12px;
  background: linear-gradient(#fff4dc, #eabb82);
  font-size: 32px;
  box-shadow: inset 0 -5px rgba(105, 43, 18, 0.12);
}

.avatar-grid button.is-selected {
  outline: 4px solid var(--orange);
  outline-offset: -2px;
}

.wallet-card {
  margin-top: 16px;
  padding: 10px 14px 12px;
  border-radius: 12px;
  background: rgba(122, 65, 42, 0.1);
}

.wallet-card .section-label {
  margin: 0 0 6px;
}

.wallet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.wallet-amount {
  font-size: 26px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.wallet-row .ghost-button {
  flex: 0 0 auto;
  padding: 8px 18px;
  border-color: rgba(122, 65, 42, 0.35);
  background: rgba(122, 65, 42, 0.12);
  color: #7a412a;
  font-size: 15px;
}

.wallet-note {
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 700;
  opacity: 0.7;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0 0;
}

.stat-grid div {
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(122, 65, 42, 0.1);
}

.stat-grid dt {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.66;
}

.stat-grid dd {
  margin: 2px 0 0;
  font-size: 21px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.confirm {
  width: 100%;
  display: block;
  margin: 20px auto 0;
  padding: 12px 24px;
  border-radius: 999px;
  font-size: 24px;
}

.powerup-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.powerup-summary li {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 10px 6px;
  border-radius: 10px;
  background: rgba(122, 65, 42, 0.1);
  font-size: 12px;
  font-weight: 800;
  opacity: 0.9;
}

.powerup-summary i {
  font-style: normal;
  font-size: 20px;
  line-height: 1;
}

.powerup-summary b {
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}

.league-modal {
  background: linear-gradient(#0f634f 0 24%, #fff0cf 24%);
}

.league-statue {
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: radial-gradient(circle, #e8fdff, #49acec 56%, #085496);
  color: white;
  font-size: 54px;
  text-shadow: 0 3px 0 #1b679a;
  box-shadow: 0 0 28px rgba(147, 244, 255, 0.5);
}

.leaderboard {
  display: grid;
  gap: 7px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  min-height: 52px;
  padding: 8px 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, #ffe681, #fff3cc);
  color: #7a3d22;
  font-size: 19px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.leaderboard li.is-you {
  background: linear-gradient(90deg, #8ee0a4, #d9f7c8);
  outline: 3px solid #2f9b53;
}

.league-summary {
  margin: 0 0 12px;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  color: #7a412a;
}

.leaderboard span {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.leaderboard em {
  font-style: normal;
  font-size: 13px;
  color: #c98a1a;
  letter-spacing: 0.1em;
}

.leaderboard li.is-empty {
  justify-items: center;
  grid-template-columns: 1fr;
  opacity: 0.7;
  font-size: 16px;
}

.leaderboard b {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(198, 122, 37, 0.25);
  font-size: 15px;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.switch {
  min-height: 88px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 3px;
  border: 1px solid rgba(122, 65, 42, 0.15);
  border-radius: 11px;
  background: rgba(255, 245, 221, 0.46);
  color: #7a412a;
}

.switch span {
  font-size: 24px;
}

.switch em {
  font-style: normal;
  font-size: 11px;
  font-weight: 800;
  opacity: 0.75;
}

.switch i {
  min-width: 44px;
  padding: 3px 5px 3px 18px;
  border-radius: 999px;
  background: #864525;
  color: #ffeed0;
  font-style: normal;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  transition: background 160ms ease, padding 160ms ease;
}

.switch.is-on {
  background: rgba(86, 196, 86, 0.2);
}

.switch.is-on i {
  padding-left: 5px;
  padding-right: 18px;
  background: #209044;
}

.switch:active,
.avatar-grid button:active,
.theme-option:active,
.theme-tabs button:active,
.settings-list button:active {
  transform: translateY(2px);
}

.settings-list {
  padding: 0;
  margin: 0;
  list-style: none;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(122, 65, 42, 0.08);
}

.settings-list li + li {
  border-top: 1px solid rgba(122, 65, 42, 0.14);
}

.settings-list button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 12px 14px;
  background: transparent;
  color: #7a412a;
  font-size: 17px;
  font-weight: 750;
  text-align: left;
}

.settings-list button.danger {
  color: #b03018;
}

.settings-list .chev {
  flex: 0 0 auto;
  font-size: 20px;
  line-height: 1;
  opacity: 0.45;
}

.settings-list .row-note {
  margin-left: auto;
  font-size: 13px;
  font-weight: 800;
  opacity: 0.6;
}

.theme-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.theme-tabs button {
  flex: 1;
  padding: 12px 8px;
  border-radius: 10px 10px 0 0;
  background: #e6c692;
  color: #a15b39;
  font-size: 19px;
  font-weight: 900;
}

.theme-tabs .is-selected {
  background: #9d4b2b;
  color: white;
}

.theme-panel {
  display: none;
}

.theme-panel.is-active {
  display: block;
}

.theme-option {
  width: 100%;
  display: block;
  margin-bottom: 10px;
  padding: 9px;
  border-radius: 11px;
  background: #0d6758;
  color: #8af1c9;
  border: 3px solid transparent;
  text-align: left;
}

.theme-option[data-tile-theme="coral"] { background: #7a2c22; color: #ffc9ac; }
.theme-option[data-tile-theme="ink"] { background: #1d2740; color: #a9c4e8; }

.theme-option.is-selected {
  border-color: var(--orange);
}

.theme-option span {
  display: block;
  margin-bottom: 6px;
  font-size: 16px;
  font-weight: 800;
}

.theme-tiles {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

/* Swatches inherit the theme variables, so a preview can never drift
   from what the board actually renders. */
.theme-tiles i {
  aspect-ratio: 0.75;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid var(--tile-rim);
  background: linear-gradient(150deg, var(--tile-face-a), var(--tile-face-b));
  box-shadow: 0 4px 0 var(--tile-edge-dark);
  overflow: hidden;
}

.theme-tiles svg {
  width: 88%;
  height: 88%;
}

.theme-tiles .back {
  border-color: var(--tile-back-rim);
  background: linear-gradient(150deg, var(--tile-back-a), var(--tile-back-b));
}

.background-swatches {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.background-swatches button {
  min-height: 104px;
  border: 4px solid rgba(122, 65, 42, 0.18);
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18), 0 6px 0 rgba(87, 36, 16, 0.22);
}

.background-swatches button.is-selected {
  border-color: var(--orange);
}

.background-swatches [data-bg-theme="red"] { background: linear-gradient(#c92727, #660708); }
.background-swatches [data-bg-theme="green"] { background: linear-gradient(#1e9d69, #073d3c); }
.background-swatches [data-bg-theme="blue"] { background: linear-gradient(#2772b8, #18225b); }

/* ─── Overlays ──────────────────────────────────────────────────────── */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(18, 6, 3, 0.72);
  backdrop-filter: blur(3px);
}

.overlay[hidden] {
  display: none;
}

.result-card {
  width: min(100%, 340px);
  padding: 24px 22px 22px;
  border: 5px solid #ffcf5d;
  border-radius: 20px;
  background: linear-gradient(#fff2cf, #ffd483);
  color: #733315;
  text-align: center;
  box-shadow: 0 14px 30px rgba(21, 5, 2, 0.55);
  animation: modalIn 260ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

.result-card h2 {
  margin: 0 0 10px;
  color: #a51d18;
  font-size: 32px;
}

.stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 6px;
}

.stars i {
  font-size: 38px;
  font-style: normal;
  color: rgba(122, 65, 42, 0.22);
  transition: transform 200ms ease, color 200ms ease;
}

.stars i.is-lit {
  color: #ffb400;
  text-shadow: 0 3px 0 #b56900;
  transform: scale(1.12);
}

.how-to {
  margin: 0 0 18px;
  padding: 0 0 0 20px;
  text-align: left;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.45;
}

.how-to li + li {
  margin-top: 9px;
}

.result-note {
  margin: 14px 0 0;
  font-size: 14px;
  font-weight: 750;
  opacity: 0.8;
}

/* Unmissable marker so a simulated wallet is never mistaken for a real one. */
body.is-preview .phone-shell::after {
  content: "PREVIEW — simulated wallet, no real payments";
  position: absolute;
  z-index: 90;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 5px 8px;
  background: repeating-linear-gradient(45deg, #b3261e 0 10px, #8c1d18 10px 20px);
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-align: center;
  pointer-events: none;
}

.toast {
  position: absolute;
  z-index: 60;
  left: 50%;
  bottom: 12%;
  max-width: 82%;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(26, 10, 5, 0.92);
  border: 1px solid rgba(255, 214, 140, 0.35);
  color: #ffe6b7;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}

.toast.is-open {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ─── Themes ────────────────────────────────────────────────────────── */

/* Not scoped to .phone-shell, so the theme picker's swatches can carry the
   same variables and always preview exactly what the board will render. */
.theme-jade {
  --tile-edge: #b6d6c2;
  --tile-edge-dark: #86ab95;
  --tile-face-a: #f8fffb;
  --tile-face-b: #dbeee3;
  --tile-rim: rgba(28, 92, 66, 0.28);
  --tile-gloss: linear-gradient(160deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0) 55%);
  --tile-back-a: #22936a;
  --tile-back-b: #0c5b41;
  --tile-back-rim: #7fe6b6;
  --sym-blue: #1b4f8f;
  --sym-green: #0f6b46;
  --sym-red: #b32b28;
  --sym-ink: #26313f;
  --sym-hole: #fffdf3;
}

.theme-coral {
  --tile-edge: #f0b892;
  --tile-edge-dark: #c07f5c;
  --tile-face-a: #fff3e8;
  --tile-face-b: #ffd2b4;
  --tile-rim: rgba(158, 66, 28, 0.34);
  --tile-gloss: linear-gradient(160deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0) 55%);
  --tile-back-a: #e0562f;
  --tile-back-b: #8c1f22;
  --tile-back-rim: #ffc39c;
  --sym-blue: #0d5f63;
  --sym-green: #1d7a4f;
  --sym-red: #a81c1c;
  --sym-ink: #4a2a1c;
  --sym-hole: #fff6ee;
}

/* Dark skin — symbols invert to light so the faces stay readable. */
.theme-ink {
  --tile-edge: #46557a;
  --tile-edge-dark: #232c45;
  --tile-face-a: #3a4767;
  --tile-face-b: #232c47;
  --tile-rim: rgba(180, 202, 244, 0.3);
  --tile-gloss: linear-gradient(160deg, rgba(190, 214, 255, 0.22), rgba(255, 255, 255, 0) 55%);
  /* Deep wine, not navy — a face-down tile has no symbol to read, so it has
     to separate from the slate face on hue alone. */
  --tile-back-a: #973b55;
  --tile-back-b: #3c1224;
  --tile-back-rim: #e08aa4;
  --sym-blue: #86d3ff;
  --sym-green: #74e6b0;
  --sym-red: #ff9aa4;
  --sym-ink: #e8eefb;
  --sym-hole: #1e2740;
}

.phone-shell.bg-green .screen-game {
  background:
    radial-gradient(circle at 50% 38%, rgba(106, 255, 172, 0.14), transparent 15rem),
    repeating-radial-gradient(circle at 18% 18%, rgba(255, 222, 127, 0.1) 0 2px, transparent 2px 42px),
    linear-gradient(#12835e, #063f3f 72%, #052024);
}

.phone-shell.bg-blue .screen-game {
  background:
    radial-gradient(circle at 50% 38%, rgba(122, 213, 255, 0.18), transparent 15rem),
    repeating-radial-gradient(circle at 18% 18%, rgba(255, 239, 169, 0.11) 0 2px, transparent 2px 42px),
    linear-gradient(#285eaa, #1d235e 72%, #090f2d);
}

/* ─── Motion ────────────────────────────────────────────────────────── */

@keyframes hintPulse {
  50% {
    box-shadow:
      calc(var(--depth) * 0.5) var(--depth) 0 var(--tile-edge),
      0 0 0 3px #4be59a,
      0 0 22px rgba(80, 255, 170, 0.9);
  }
}

@keyframes scoreRise {
  0% { opacity: 0; transform: translate(-50%, 18px) scale(0.86); }
  18% { opacity: 1; transform: translate(-50%, 0) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -54px) scale(0.94); }
}

@keyframes leafDrift {
  0% { transform: translateY(-4px) rotate(-2deg); opacity: 0.58; }
  100% { transform: translateY(18px) rotate(3deg); opacity: 0.86; }
}

@keyframes deniedTap {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px) rotate(-2deg); }
  60% { transform: translateX(5px) rotate(2deg); }
}

@keyframes squashMatch {
  0% { transform: translateY(calc(var(--th) * -0.16)) scale(1.06); opacity: 1; }
  35% { transform: translateY(calc(var(--th) * -0.3)) scale(1.14, 0.84); }
  70% { transform: translateY(calc(var(--th) * -0.05)) scale(0.8, 1.14); opacity: 0.9; }
  100% { transform: translateY(calc(var(--th) * 0.15)) scale(0.1, 0.5); opacity: 0; }
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

@keyframes dotPing {
  50% { transform: scale(1.35); }
}

/* Effects switch and OS-level reduced motion both quiet the board down. */
.phone-shell.no-fx .screen-lobby::after,
.phone-shell.no-fx .call-dot {
  animation: none;
}

.phone-shell.no-fx .tile.is-hint .tile-body {
  animation: none;
  box-shadow: calc(var(--depth) * 0.5) var(--depth) 0 var(--tile-edge), 0 0 0 3px #4be59a;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .tile.is-hint .tile-body {
    box-shadow: calc(var(--depth) * 0.5) var(--depth) 0 var(--tile-edge), 0 0 0 3px #4be59a;
  }

  .score-pop.is-open {
    display: none;
  }
}

/* ─── Small screens ─────────────────────────────────────────────────── */

/* Short screens: claw vertical space back from the furniture so the board,
   which is 144 tiles no matter the device, keeps usable tap targets. */
@media (max-height: 700px) {
  .brand-block { margin-top: 16px; }
  .call-icon { width: 54px; height: 50px; }
  .level-button { min-height: 70px; margin-top: 22px; }

  .game-header { padding-top: max(8px, env(safe-area-inset-top)); }
  .round,
  .round-actions button,
  .close { width: 38px; height: 38px; font-size: 19px; }
  .back { font-size: 30px; }
  .score strong { font-size: 24px; }
  .score span { font-size: 10px; }

  .game-meta { margin-top: 3px; }
  .meta-chip { padding: 3px 9px; font-size: 11px; }
  .tray-wrap { margin-top: 5px; gap: 3px; }
  .match-tray { width: min(56%, 205px); padding: 4px; border-width: 3px; }
  .set-status { margin-top: 4px; padding: 3px 11px; font-size: 11px; }
  .board-wrap { padding: 3px 10px; }

  .powerbar { gap: min(11vw, 44px); padding: 6px 0 max(8px, env(safe-area-inset-bottom)); }
  .powerbar button { width: 52px; height: 52px; border-width: 2px; }
  .powerbar svg { width: 24px; height: 24px; }
  .powerbar .pip { min-width: 20px; padding: 1px 5px; font-size: 12px; }
}

@media (max-height: 620px) {
  .brand-block { margin-top: 8px; }
  .lobby-doors { display: none; }

  .game-meta { margin-top: 2px; }
  .meta-chip { padding: 2px 7px; font-size: 10px; }
  .tray-wrap { margin-top: 3px; }
  .match-tray { width: min(50%, 178px); }
  .set-status { margin-top: 3px; font-size: 10px; }
  .powerbar button { width: 46px; height: 46px; }
  .powerbar svg { width: 21px; height: 21px; }
}
