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

:root {
  --wood: #8a5a2b;
  --wood-dark: #5a3515;
  --cream: #fff6e0;
  --grass: #8fcf5f;
  --grass-dark: #5a9a3a;
  --gold: #ffc93c;
}

body {
  font-family: 'Trebuchet MS', Verdana, sans-serif;
  background: #6fae4a repeating-linear-gradient(45deg, #6fae4a 0 20px, #68a545 20px 40px);
  color: var(--wood-dark);
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  /* GUI text is not selectable with the mouse (game UI, not a document) */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
input, textarea {
  user-select: text;
  -webkit-user-select: text;
}

button { font-family: inherit; cursor: pointer; border: none; }
.hidden { display: none !important; }

.icon { display: inline-block; width: 28px; height: 28px; }
.icon svg { width: 100%; height: 100%; display: block; }

#app {
  position: relative;
  width: 100%;
  max-width: 640px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #f3e3bd;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  background: var(--wood);
  border-bottom: 5px solid var(--wood-dark);
  color: var(--cream);
}
.top-bar h1 { font-size: 26px; letter-spacing: 1px; text-shadow: 2px 2px 0 var(--wood-dark); }
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { color: var(--gold); width: 32px; height: 32px; }
.gold-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--wood-dark); border-radius: 16px; padding: 4px 14px 4px 6px;
  font-size: 20px; font-weight: bold;
}
.gold-pill .icon { width: 26px; height: 26px; }
.pills { display: flex; align-items: center; gap: 8px; }
.sound-btn { font-size: 20px; padding: 4px 12px; color: var(--cream); transition: transform 0.1s; }
.sound-btn:hover { transform: scale(1.08); }
.sound-btn.off { opacity: 0.55; filter: grayscale(0.7); }

/* Narrow phones: compact top bar so trophy/gold/sound/account all fit. */
@media (max-width: 480px) {
  .top-bar { padding: 8px; gap: 6px; }
  .top-bar h1 { font-size: 18px; }
  .logo { gap: 6px; }
  .logo-icon { width: 24px; height: 24px; }
  .pills { gap: 6px; }
  .gold-pill { font-size: 15px; padding: 3px 10px 3px 5px; gap: 4px; }
  .gold-pill .icon { width: 20px; height: 20px; }
  #btn-account .icon { width: 20px; height: 20px; }
  .sound-btn { padding: 3px 8px; }
}

/* ---------- Pages ---------- */
#content { flex: 1; overflow-y: auto; padding: 16px; }
.tab-page { display: none; }
.tab-page.active { display: block; }

.page-title { text-align: center; margin-bottom: 14px; font-size: 24px; }

.empty-page { text-align: center; padding-top: 80px; }
.empty-page h2 { font-size: 28px; margin: 10px 0 6px; }
.big-icon { width: 110px; height: 110px; }

.big-btn {
  display: block;
  margin: 18px auto 0;
  padding: 14px 50px;
  font-size: 26px;
  font-weight: bold;
  color: var(--cream);
  background: linear-gradient(#ffb03a, #e8791f);
  border: 4px solid var(--wood-dark);
  border-radius: 18px;
  box-shadow: 0 6px 0 var(--wood-dark);
  text-shadow: 2px 2px 0 var(--wood-dark);
  transition: transform 0.1s;
}
.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--wood-dark); }

/* Lobby arena card */
.arena-card {
  text-align: center;
  background: var(--cream);
  border: 4px solid var(--wood-dark);
  border-radius: 20px;
  padding: 12px;
  box-shadow: 0 6px 0 var(--wood-dark);
}

/* Battle lobby fits the screen like a mobile game: no scrolling, the arena
   preview shrinks/grows into the leftover space */
#content { min-height: 0; }
#page-battle.active { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
#page-battle .arena-card {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
  padding: 8px;
}
#page-battle .arena-preview-wrap { flex: 1 1 auto; min-height: 0; width: auto; align-self: stretch; display: flex; justify-content: center; }
#page-battle #arena-preview { height: 100%; width: auto; max-width: 100%; }
#page-battle .arena-card h2 { font-size: 22px; margin-top: 2px; }
#page-battle .arena-hint { font-size: 11px; }
#page-battle .arena-nav { margin-bottom: 4px; }
#page-battle .arena-progress { margin: 2px auto 0; }
#page-battle #btn-fight { margin-top: 8px; padding: 10px 40px; font-size: 22px; flex-shrink: 0; }
#page-battle .chest-title { margin: 8px 0 6px; font-size: 18px; flex-shrink: 0; }
#page-battle #chest-slots { flex-shrink: 0; }
#game-version {
  text-align: center; font-size: 11px; opacity: 0.55;
  margin-top: 6px; flex-shrink: 0;
}
#page-battle .chest-slot { min-height: 84px; }
#page-battle .chest-icon { width: 38px; height: 38px; }

/* Slim top row inside the arena card: trophy-road progress + quest button */
.top-minirow { display: flex; gap: 8px; margin-bottom: 6px; }
.mini-road {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 4px 10px;
  background: linear-gradient(#6cc04a, #3f9a2a);
  border: 3px solid var(--wood-dark); border-radius: 12px;
  box-shadow: 0 3px 0 var(--wood-dark);
  color: var(--cream); font-size: 14px; font-weight: bold;
  text-shadow: 1px 1px 0 var(--wood-dark);
}
.mini-road .icon { width: 24px; height: 24px; flex-shrink: 0; }
.mini-road .road-badge { font-size: 11px; padding: 2px 8px; }
.road-minicol { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
#road-label { font-size: 13px; line-height: 1; }
.road-minibar {
  display: block; height: 8px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid rgba(255, 246, 224, 0.7); border-radius: 5px;
  overflow: hidden;
}
#road-fill {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(#ffe07a, #e8a51f);
  border-radius: 4px;
  transition: width 0.4s ease-out;
}
.mini-quest {
  position: relative;
  width: 44px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(#8fd0ea, #3b82c4);
  border: 3px solid var(--wood-dark); border-radius: 12px;
  box-shadow: 0 3px 0 var(--wood-dark);
  color: var(--cream);
}
.mini-quest .icon { width: 26px; height: 26px; }
.mini-quest .road-badge {
  position: absolute; top: -10px; right: -10px;
  font-size: 11px; padding: 2px 8px;
}
.arena-label {
  display: inline-block;
  background: var(--grass-dark);
  color: var(--cream);
  padding: 4px 14px;
  border-radius: 12px;
  font-weight: bold;
  margin-bottom: 8px;
}
#arena-preview {
  display: block;
  margin: 0 auto;
  height: 42vh;
  border: 4px solid var(--wood-dark);
  border-radius: 12px;
}
.arena-card h2 { font-size: 30px; margin-top: 6px; }

/* Deck builder: 3-column card grid */
.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 10px; margin-bottom: 22px; }
.card-tile {
  position: relative;
  min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 6px;
  background: var(--cream);
  border: 4px solid;
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--wood-dark);
  color: var(--wood-dark);
  transition: transform 0.1s;
}
.card-tile:hover { transform: translateY(-2px); }
.card-tile canvas { width: 100%; max-width: 64px; height: auto; }
.tile-name { font-weight: bold; font-size: 15px; max-width: 100%; overflow-wrap: anywhere; }
.tile-level { font-size: 12px; }
.tile-bar {
  position: relative; width: 100%; height: 16px; margin-top: 4px;
  background: #d9c59a; border-radius: 8px; overflow: hidden;
}
.tile-bar div { height: 100%; background: #7cc4f0; }
.tile-bar.ready div { background: #5cc24a; }
.tile-bar span { position: absolute; inset: 0; font-size: 11px; font-weight: bold; line-height: 16px; text-align: center; }
.card-grid.swapping .card-tile { outline: 3px dashed var(--gold); outline-offset: 2px; }

/* The deck: a wooden board with 8 sunken slots */
#deck-grid {
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
  background: #b98a52;
  border: 4px solid var(--wood-dark);
  border-radius: 16px;
  box-shadow: inset 0 4px 0 rgba(0, 0, 0, 0.2);
}
.deck-slot {
  display: flex;
  min-width: 0;
  min-height: 150px;
  padding: 6px;
  background: rgba(60, 35, 12, 0.35);
  border-radius: 12px;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.4);
}
.deck-slot .card-tile { flex: 1; min-width: 0; }
.deck-slot-empty { margin: auto; color: var(--cream); font-weight: bold; opacity: 0.7; }
.deck-slot-tabs { display: flex; justify-content: center; gap: 8px; margin: 0 auto 12px; }
.deck-slot-tab {
  width: 42px; height: 42px; display: grid; place-items: center;
  border: 3px solid var(--wood-dark); border-radius: 12px;
  color: #f4ead5; background: linear-gradient(#97999b, #686a6c);
  box-shadow: 0 3px 0 #392a21; font-size: 18px; font-weight: bold;
}
.deck-slot-tab.active {
  background: linear-gradient(#8bd456, #398d32); border-color: #214d24;
  box-shadow: 0 3px 0 #214d24, inset 0 1px #d9ffd0;
}
.deck-slot-tab:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.swap-banner {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin-bottom: 12px; padding: 8px 12px;
  background: var(--gold); border: 3px solid var(--wood-dark); border-radius: 12px; font-weight: bold;
}
.swap-banner button { padding: 4px 12px; font-weight: bold; border-radius: 8px; background: var(--cream); border: 2px solid var(--wood-dark); }

/* Card details popup */
.modal {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(30, 20, 5, 0.55);
}
.modal-box {
  position: relative;
  width: 100%; max-width: 440px; max-height: 100%; overflow-y: auto;
  padding: 16px;
  background: var(--cream);
  border: 5px solid var(--wood-dark);
  border-radius: 20px;
  box-shadow: 0 8px 0 var(--wood-dark);
  text-align: center;
}
.modal-close { position: absolute; top: 4px; right: 12px; background: none; font-size: 30px; font-weight: bold; color: var(--wood-dark); }
.modal-head { display: flex; align-items: center; justify-content: center; gap: 10px; }
.modal-head h3 { font-size: 26px; }
.exclusive-chip {
  background: linear-gradient(#7a3fb0, #4a1f7a);
  border: 2px solid #ffd66b; border-radius: 10px;
  color: #ffd66b; font-size: 12px; font-weight: bold; padding: 3px 10px;
  white-space: nowrap;
}
.rarity-chip { color: #fff; padding: 2px 10px; border-radius: 10px; font-size: 13px; font-weight: bold; }
.modal-sub { display: flex; align-items: center; justify-content: center; gap: 4px; margin: 4px 0 10px; font-weight: bold; }
.modal-sub .icon { width: 20px; height: 20px; }
.preview { display: block; width: 100%; aspect-ratio: 260 / 110; border: 3px solid var(--wood-dark); border-radius: 12px; }
.desc { margin: 10px 0; font-size: 15px; }
.stats { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; text-align: left; }
.stats li {
  display: flex; justify-content: space-between; gap: 6px;
  background: #f0dca8; border-radius: 8px; padding: 4px 8px; font-size: 13px;
}
.upgrade-need { margin-top: 10px; font-size: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 12px; align-items: center; }
.action-btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  padding: 10px;
  font-size: 17px; font-weight: bold;
  color: var(--cream);
  background: linear-gradient(#6cc04a, #3f9a2a);
  border: 3px solid var(--wood-dark);
  border-radius: 12px;
  box-shadow: 0 4px 0 var(--wood-dark);
  text-shadow: 1px 1px 0 var(--wood-dark);
}
.action-btn.use { background: linear-gradient(#ffb03a, #e8791f); }
.action-btn.danger { background: linear-gradient(#e0654f, #b03a2a); }
.action-btn:disabled { filter: grayscale(1); opacity: 0.6; cursor: default; }
.action-btn .icon { width: 22px; height: 22px; }
.in-deck { flex: 1; font-weight: bold; }

/* Lobby chests */
.chest-title { text-align: center; margin: 22px 0 10px; font-size: 22px; }
.chest-slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chest-slot {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 108px; padding: 6px 4px;
  background: #e6d3a6;
  border: 3px solid var(--wood-dark);
  border-radius: 12px;
  color: var(--wood-dark);
  cursor: default;
}
.chest-slot.empty { background: rgba(90, 53, 21, 0.12); border-style: dashed; }
.chest-slot.ready { background: #fff1b8; border-color: #e8791f; cursor: pointer; box-shadow: 0 0 12px #ffc93c; }
.chest-icon { width: 48px; height: 48px; }
.chest-name { font-size: 11px; font-weight: bold; }
.chest-time { font-size: 13px; font-weight: bold; }

/* Chest rewards popup */
.chest-modal-title { font-size: 26px; }
.chest-big { width: 110px; height: 110px; margin: 6px auto; display: block; }
.reward-gold { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 26px; font-weight: bold; }
.reward-gold .icon { width: 32px; height: 32px; }
.reward-cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 12px; }
.reward-card {
  display: flex; flex-direction: column; align-items: center;
  width: 90px; padding: 6px;
  background: #fff8e6; border: 3px solid; border-radius: 12px;
}
.reward-card canvas { width: 56px; height: 56px; }
.reward-card span { font-size: 13px; font-weight: bold; }
.reward-card b { font-size: 18px; color: #3f9a2a; }

/* ---------- Tab bar ---------- */
.tab-bar {
  display: flex;
  background: var(--wood);
  border-top: 5px solid var(--wood-dark);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 0 9px;
  background: transparent;
  color: var(--cream);
  font-weight: bold;
  font-size: 12px;
  border-right: 2px solid var(--wood-dark);
  opacity: 0.8;
}
.tab:last-child { border-right: none; }
.tab .icon { width: 34px; height: 34px; }
.tab.active { background: #b27a3f; box-shadow: inset 0 4px 0 var(--gold); opacity: 1; }

/* ---------- Global press feedback ----------
   Every button visibly presses while held (mouse, touch, right-click-hold).
   Releasing OFF the button cancels natively (no click fires), so a held
   press is always safe to abort. */
button { touch-action: manipulation; }
button:active { transform: scale(0.94); }
button:active.big-btn { transform: translateY(4px) scale(0.98); box-shadow: 0 2px 0 var(--wood-dark); }
button:disabled:active { transform: none; }
.tab:active { transform: scale(0.95); box-shadow: inset 0 4px 0 var(--gold); }
.hand-card:active { transform: translateY(-4px) scale(0.96); }
.hand-card.selected:active { transform: translateY(-10px) scale(0.96); }

/* ---------- Friends tab ---------- */
.friends-sec { display: flex; flex-direction: column; gap: 10px; }
.friend-me {
  display: flex; gap: 10px; align-items: center;
  background: var(--cream);
  border: 4px solid var(--wood-dark); border-radius: 16px;
  padding: 10px; box-shadow: 0 4px 0 var(--wood-dark);
}
.friend-me-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.friend-avatar {
  width: 44px; height: 44px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: bold; color: var(--cream);
  background: linear-gradient(#6cc04a, #3f9a2a);
  border: 3px solid var(--wood-dark); border-radius: 50%;
  text-shadow: 1px 1px 0 var(--wood-dark);
}
.friend-avatar.big { width: 58px; height: 58px; font-size: 28px; }
.friend-avatar.duel { background: linear-gradient(#ffb03a, #e8791f); }
.friend-add {
  background: rgba(90, 53, 21, 0.08);
  border: 3px dashed var(--wood-dark); border-radius: 16px;
  padding: 10px;
}
.friend-add > b { display: block; margin-bottom: 6px; }
.friend-group { display: flex; flex-direction: column; gap: 8px; }
.friend-group > b { font-size: 16px; }
.friend-card {
  display: flex; align-items: center; gap: 8px;
  background: var(--cream);
  border: 3px solid var(--wood-dark); border-radius: 14px;
  padding: 8px; box-shadow: 0 3px 0 var(--wood-dark);
}
.friend-card.fresh { border-color: #e8791f; box-shadow: 0 0 12px #ffc93c, 0 3px 0 var(--wood-dark); }
.friend-card .friend-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-sub { font-size: 11px; opacity: 0.7; flex-shrink: 0; }
.friend-card .action-btn { flex: 0 0 auto; font-size: 13px; padding: 7px 10px; }

/* ---------- Customize (Díszek) ---------- */
.pin-face { vertical-align: middle; flex-shrink: 0; }
.pin-preview {
  --pin-accent: #f0c76a;
  position: sticky; top: 0; z-index: 4;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 6px; margin-bottom: 14px;
  color: #fff1d3; border: 2px solid #bc8a4d; border-radius: 18px;
  background: radial-gradient(ellipse at 12% 40%, #88633c, transparent 65%), linear-gradient(135deg, #573b26, #302117);
  box-shadow: 0 4px 0 #352314, 0 8px 18px #35231426;
}
.pin-preview > canvas { width: 108px; height: 108px; }
.pin-preview-info { display: flex; flex: 1; flex-direction: column; gap: 5px; min-width: 0; }
.pin-preview-label { color: #edc989; font-size: 10px; font-weight: bold; letter-spacing: 0.1em; }
.pin-preview-name { font-size: 18px; line-height: 1.15; overflow-wrap: anywhere; }
.pin-preview-say { color: var(--pin-accent); font-size: 15px; font-weight: bold; }
.pin-preview-status { font-size: 11px; line-height: 1.35; color: #e1cfb6; }
.pin-replay {
  flex: none; align-self: flex-end; width: 32px; height: 32px;
  display: grid; place-items: center; padding: 6px;
  color: #ffe5ad; background: #ffffff12; border: 1px solid #e5c38166; border-radius: 50%;
  transition: background 0.15s, transform 0.15s;
}
.pin-replay svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pin-replay:hover { background: #ffffff26; transform: rotate(-20deg); }
.pin-replay:focus-visible, .emote-slot:focus-visible, .emote-tile:focus-visible, .emote-pick:focus-visible { outline: 3px solid #e99732; outline-offset: 3px; }
@media (max-width: 400px) {
  .pin-preview { gap: 5px; padding: 8px 8px 8px 2px; }
  .pin-preview > canvas { width: 86px; height: 86px; }
  .pin-preview-name { font-size: 15px; }
  .pin-preview-say { font-size: 13px; }
  .pin-preview-label { font-size: 8px; }
  .pin-replay { width: 28px; height: 28px; }
}
.custom-hint { text-align: center; font-size: 14px; margin: 6px 0 10px; opacity: 0.85; }
.emote-deck {
  display: flex; gap: 6px; justify-content: center;
  background: var(--wood); border: 4px solid var(--wood-dark); border-radius: 16px;
  padding: 8px; margin-bottom: 6px;
}
.emote-slot {
  display: flex; flex: 1; min-width: 0; flex-direction: column; align-items: center; gap: 2px;
  background: var(--cream); border: 3px solid var(--wood-dark); border-radius: 12px;
  padding: 6px 2px 4px; font-size: 12px; font-weight: bold; color: var(--wood-dark); overflow-wrap: anywhere;
  box-shadow: 0 3px 0 var(--wood-dark); transition: transform 0.1s;
}
.emote-slot canvas { width: 52px; max-width: 100%; height: auto; aspect-ratio: 1; }
.emote-slot.selected { transform: translateY(-6px); background: #fff1b8; border-color: #e8791f; }
.emote-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.emote-tile {
  position: relative;
  scroll-margin-top: 150px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--cream); border: 3px solid var(--wood-dark); border-radius: 12px;
  padding: 8px 4px 6px;
}
.emote-tile canvas { width: 60px; height: 60px; }
.emote-tile .emote-say { font-size: 12px; font-style: italic; opacity: 0.85; }
.emote-tile.locked { filter: grayscale(0.85) brightness(0.92); }
.emote-tile.locked .tile-lock { position: absolute; top: 4px; right: 4px; }
.emote-tile.locked .tile-lock .icon { width: 22px; height: 22px; }
.emote-tile.indeck { border-color: #3f9a2a; box-shadow: 0 0 0 2px #3f9a2a inset; }
.emote-indeck {
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  background: #3f9a2a; color: #fff; font-size: 10px; font-weight: bold;
  padding: 1px 8px; border-radius: 8px; white-space: nowrap;
  max-width: calc(100% - 2px); overflow: hidden; text-overflow: ellipsis;
}
.reward-pin { border-color: var(--gold) !important; box-shadow: 0 0 12px rgba(255, 201, 60, 0.7); }

/* ---------- Battle emote bubbles + picker ---------- */
.canvas-wrap { position: relative; }
#btn-emote {
  position: absolute; right: 10px; bottom: 10px; z-index: 16;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--cream); border: 3px solid var(--wood-dark);
  box-shadow: 0 4px 0 var(--wood-dark);
}
#btn-emote .icon { width: 30px; height: 30px; color: var(--wood-dark); }
#btn-emote:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood-dark); }
#emote-picker {
  position: absolute; right: 70px; bottom: 10px; z-index: 16;
  display: flex; gap: 8px;
  background: rgba(40, 25, 10, 0.85); border-radius: 16px; padding: 8px;
}
.emote-pick { background: transparent; padding: 0; transition: transform 0.1s; }
.emote-pick canvas { width: 48px; height: 48px; display: block; }
.emote-pick:hover { transform: scale(1.12); }
.emote-bubble {
  --pin-accent: #d79c48;
  position: absolute; z-index: 15;
  display: flex; align-items: center; gap: 6px;
  background: linear-gradient(#fffbef, #f8e7c7); border: 3px solid var(--pin-accent); border-radius: 22px;
  padding: 3px 14px 3px 2px; font-weight: bold; font-size: 16px; color: var(--wood-dark);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25), 0 0 14px #00000018;
  animation: bubblepop 0.42s cubic-bezier(0.2, 0.8, 0.25, 1.2), bubbleleave 0.2s 3s forwards;
  max-width: 82%; pointer-events: none;
}
.emote-bubble::after {
  content: ''; position: absolute; width: 12px; height: 12px; transform: rotate(45deg);
  background: #f8e7c7; border-right: 3px solid var(--pin-accent); border-bottom: 3px solid var(--pin-accent);
}
.emote-bubble.player::after { bottom: -8px; right: 22px; }
.emote-bubble.enemy::after { top: -8px; left: 22px; background: #fffbef; transform: rotate(225deg); }
.emote-bubble canvas { width: 64px; height: 64px; }
.emote-bubble.enemy { top: max(9%, 62px); left: 12px; }
.emote-bubble.player { bottom: max(9%, 74px); right: 12px; }
.emote-text { min-width: 0; font-size: 16px; overflow-wrap: anywhere; animation: pinsay 0.25s 0.12s backwards; }
.emote-from {
  position: absolute; top: -11px; left: 14px;
  font-size: 10px; font-weight: bold; color: #fff6e0;
  background: #c23b2b; border: 2px solid #5a1d12; border-radius: 8px;
  padding: 0 7px; white-space: nowrap; max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis;
}
@keyframes bubblepop {
  0% { transform: translateY(8px) scale(0.4); opacity: 0; }
  65% { transform: translateY(-2px) scale(1.06); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes bubbleleave { to { transform: translateY(-6px) scale(0.95); opacity: 0; } }
@keyframes pinsay { from { transform: translateX(-5px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .emote-bubble, .emote-text { animation: none; }
  .emote-slot, .emote-pick, .pin-replay { transition: none; }
}

/* ---------- Tap-to-open chests ---------- */
.chest-slot.ready { animation: chestglow 1.6s ease-in-out infinite; }
@keyframes chestglow {
  50% { box-shadow: 0 0 20px #ffc93c; transform: scale(1.04); }
}
.tap-chest {
  background: transparent; padding: 0; display: block; margin: 0 auto;
  transition: transform 0.1s;
}
.tap-chest .chest-big { width: 130px; height: 130px; }
.tap-chest.shake { animation: chestshake 0.3s; }
@keyframes chestshake {
  20% { transform: rotate(-8deg) scale(1.05); }
  45% { transform: rotate(7deg) scale(1.08); }
  70% { transform: rotate(-4deg) scale(1.05); }
  100% { transform: rotate(0) scale(1); }
}
.tap-chest.upgraded { animation: upgradeGlow 1.1s ease-in-out; }
@keyframes upgradeGlow {
  0% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.25); filter: brightness(1.8) drop-shadow(0 0 22px #ffc93c); }
  100% { transform: scale(1.1); filter: brightness(1.2) drop-shadow(0 0 12px #ffc93c); }
}
.tap-chest.burst { animation: chestburst 0.6s ease-in; }
@keyframes chestburst {
  30% { transform: scale(1.2); filter: brightness(2); }
  100% { transform: scale(1.6); filter: brightness(3); opacity: 0; }
}
.tap-dots { display: flex; gap: 8px; justify-content: center; margin: 10px 0 4px; }
.tap-dots i {
  width: 14px; height: 14px; border-radius: 50%;
  background: rgba(90, 53, 21, 0.2); border: 2px solid var(--wood-dark);
}
.tap-dots i.on { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.tap-cancel {
  display: block; margin: 12px auto 0; padding: 8px 26px;
  font-size: 15px; font-weight: bold; color: var(--wood-dark);
  background: transparent; border: 2px solid var(--wood-dark); border-radius: 12px;
}
.reward-cards > div { animation: rewardpop 0.4s backwards; }
@keyframes rewardpop {
  0% { transform: scale(0.3) translateY(20px); opacity: 0; }
  70% { transform: scale(1.1) translateY(-3px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
/* New unlocks shine in their rarity color (green/blue/purple/gold) */
.reward-card.new-one { position: relative; }
.reward-card.new-rare { box-shadow: 0 0 14px #5cc24a; }
.reward-card.new-superrare { box-shadow: 0 0 14px #3fa7f5; }
.reward-card.new-epic {
  box-shadow: 0 0 20px #a55ee0;
  animation: rewardpop 0.4s backwards, epicpulse 1.2s ease-in-out 2;
}
.reward-card.new-legendary {
  box-shadow: 0 0 28px #ffc93c;
  border-width: 4px;
  animation: rewardpop 0.45s backwards, legpulse 1s ease-in-out 3;
}
@keyframes epicpulse { 50% { transform: scale(1.08); filter: brightness(1.4); } }
@keyframes legpulse { 50% { transform: scale(1.15); filter: brightness(1.9); } }
/* Full-screen gold flash for legendary unlocks */
.legend-flash {
  position: fixed; inset: 0; z-index: 99; pointer-events: none;
  background: radial-gradient(circle, rgba(255,220,100,0.9), rgba(255,180,40,0.3) 60%, transparent 75%);
  animation: legflash 1.4s ease-out;
}
@keyframes legflash { 0% { opacity: 0; } 20% { opacity: 1; } 100% { opacity: 0; } }
/* Locked card modal: everything grey, but the preview loop keeps playing */
#card-modal .modal-box.locked { filter: grayscale(1); }
#card-modal .modal-box.levelup { animation: levelup 0.7s; }
@keyframes levelup {
  0% { filter: brightness(1); transform: scale(1); }
  35% { filter: brightness(1.7) drop-shadow(0 0 18px #ffc93c); transform: scale(1.04); }
  100% { filter: brightness(1); transform: scale(1); }
}

/* ---------- Trophy road ---------- */
.road-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; margin-top: 12px; padding: 10px 14px;
  background: linear-gradient(#6cc04a, #3f9a2a);
  border: 4px solid var(--wood-dark); border-radius: 16px;
  box-shadow: 0 4px 0 var(--wood-dark);
  color: var(--cream); text-align: left;
}
.road-btn .icon { width: 40px; height: 40px; flex-shrink: 0; }
.road-text { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.road-text b { font-size: 18px; text-shadow: 1px 1px 0 var(--wood-dark); }
.road-text span { font-size: 13px; opacity: 0.95; }
.road-badge {
  background: #e05a47; border: 2px solid #fff6e0; border-radius: 12px;
  font-size: 13px; font-weight: bold; padding: 4px 10px; white-space: nowrap;
  animation: roadpulse 1.1s ease-in-out infinite;
}
@keyframes roadpulse { 50% { transform: scale(1.1); } }

/* ---------- Pre-Halloween event ---------- */
#battle-btn-row {
  position: relative;
  display: flex; justify-content: center;
  margin-top: 8px; flex-shrink: 0;
}
.battle-btn-col { display: flex; flex-direction: column; }
#page-battle #battle-btn-row #btn-fight { margin-top: 0; }
#battle-btn-row .event-btn {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
}
@media (max-width: 400px) {
  #battle-btn-row .event-btn { padding: 6px 8px; font-size: 13px; }
  #battle-btn-row .event-btn canvas { width: 44px; height: 44px; }
  #page-battle #battle-btn-row #btn-fight { padding: 10px 30px; }
}
.event-btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 8px 12px;
  background: linear-gradient(#7a3fb0, #4a1f7a);
  border: 4px solid #2a1245; border-radius: 18px;
  box-shadow: 0 4px 0 #2a1245;
  color: #ffd66b; font-weight: bold; font-size: 15px;
  text-shadow: 1px 1px 0 #2a1245;
}
.event-btn canvas { width: 52px; height: 52px; }
.event-btn #event-badge {
  position: absolute; top: -12px; right: -14px; font-size: 11px; padding: 2px 8px;
}
.hween-tokens {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 6px; font-size: 13px; font-weight: bold; color: #5a2c10;
  cursor: pointer;
}
.hween-tokens .icon { width: 30px; height: 30px; }
.hween-tok.empty { filter: grayscale(1); opacity: 0.35; }
.hween-grace { color: #7a3fb0; }
.hween-box {
  max-height: 88vh; overflow: hidden; display: flex; flex-direction: column;
  background: linear-gradient(#2a1245, #4a1f7a);
  border-color: #160826; color: #fff6e0;
}
.hween-box .modal-close { color: #ffd66b; }
.hween-scene { width: 100%; border-radius: 12px; border: 3px solid #160826; }
.hween-title {
  text-align: center; font-size: 28px; margin: 6px 0 0; color: #ff9a3c;
  text-shadow: 0 0 12px rgba(232, 121, 31, 0.8), 2px 2px 0 #160826;
}
.hween-box .custom-hint { color: #e8d5ff; }
.hween-box .custom-hint b { color: #ffd66b; }
#hween-list {
  overflow-x: auto; overflow-y: hidden;
  display: flex; gap: 10px;
  margin-top: 8px; padding: 14px 6px 10px;
  touch-action: pan-x pan-y;
  cursor: grab; user-select: none;
}
.hween-node {
  position: relative; flex: 0 0 132px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px;
  background: rgba(255, 246, 224, 0.08);
  border: 2px solid rgba(255, 214, 107, 0.35); border-radius: 14px;
  padding: 10px 6px; font-size: 14px; text-align: center;
}
.hween-node.reward { border-color: rgba(232, 121, 31, 0.7); }
.hween-node.claimed { opacity: 0.55; }
.hween-node.next { border-style: dashed; }
.hween-circle {
  min-width: 30px; text-align: center; color: #ffd66b; font-weight: bold;
  background: rgba(0, 0, 0, 0.35); border-radius: 10px; padding: 2px 10px;
}
.hween-node .icon.hween-big { width: 56px; height: 56px; flex: none; }
.hween-node .icon.dim { filter: grayscale(1); opacity: 0.4; }
.hween-tname { font-size: 13px; color: #fff6e0; }
.hween-cards { display: flex; gap: 2px; justify-content: center; }
.hween-facepin { width: 52px; height: 52px; flex: none; }
.hween-check { color: #5cc24a; font-weight: bold; font-size: 18px; }
.hween-need { font-size: 12px; opacity: 0.7; white-space: nowrap; }
.hween-claim {
  padding: 4px 12px; font-weight: bold; border-radius: 10px;
  background: #ff9a3c; border: 2px solid #160826; color: #2a1245; white-space: nowrap;
}
/* Maxed (discounted) cards: NOT the plain legendary gold — layered radiant
   frame with a MAX ribbon and a slow divine pulse. */
.card-tile.maxed {
  border-color: #ffc93c;
  box-shadow: 0 4px 0 var(--wood-dark),
    0 0 0 2px #fff3c0,
    0 0 18px 4px rgba(255, 201, 60, 0.85);
  animation: maxglow 1.6s ease-in-out infinite;
}
@keyframes maxglow {
  50% {
    box-shadow: 0 4px 0 var(--wood-dark),
      0 0 0 2px #fff3c0,
      0 0 26px 8px rgba(255, 201, 60, 1);
  }
}
.card-tile.maxed .cost-badge { background: var(--gold); }
.max-ribbon {
  position: absolute; top: -11px; right: -6px; z-index: 2;
  background: linear-gradient(#ffe07a, #e8a51f);
  border: 2px solid #7a5a10; border-radius: 8px;
  color: #5a3a10; font-size: 10px; font-weight: bold; padding: 1px 7px;
}
/* Card-modal preview of a maxed animal: golden frame around the animation. */
canvas.preview.maxed {
  border: 4px solid #ffc93c;
  outline: 2px solid #fff3c0;
  border-radius: 12px;
  box-shadow: 0 0 18px 4px rgba(255, 201, 60, 0.85);
}
/* Discount purchase: the preview flashes into its golden form. */
canvas.preview.maxburst { animation: maxburst 0.95s ease-out; }
@keyframes maxburst {
  0% { filter: brightness(1); transform: scale(1); }
  30% { filter: brightness(2.2) drop-shadow(0 0 22px #ffc93c); transform: scale(1.12); }
  100% { filter: brightness(1.15); transform: scale(1); }
}
.maxed-note { color: #a8801f; }
.hand-card.maxed { border-color: #ffc93c !important; box-shadow: 0 0 10px rgba(255, 201, 60, 0.9); }
/* Discounted but not maxed: quiet gold edge, no glow, no ribbon. */
.card-tile.dimmed { border-color: #e8c85a; }
.hand-card.dimmed { border-color: #e8c85a !important; }
canvas.preview.dimmed {
  border: 3px solid #e8c85a;
  border-radius: 12px;
}
.road-box { max-height: 84vh; overflow-y: auto; }
.road-track {
  display: flex; gap: 10px; overflow-x: auto; padding: 18px 6px 10px;
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
  cursor: grab;
  user-select: none;
}
.road-track.dragging { cursor: grabbing; }
.road-node {
  position: relative; flex: 0 0 108px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: #fff8e6; border: 3px solid var(--wood-dark); border-radius: 14px;
  padding: 10px 6px;
}
.road-node:nth-child(even) { margin-top: 26px; }
.road-circle {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--cream); border: 3px solid var(--wood-dark);
  display: flex; align-items: center; justify-content: center;
}
.road-circle .icon { width: 34px; height: 34px; }
.road-pin { width: 52px; height: 52px; }
.road-cards { display: flex; gap: 4px; justify-content: center; }
.road-cards .road-pin { width: 44px; height: 44px; }
.road-t { font-size: 15px; }
.road-rew { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: bold; flex-direction: column; }
.road-rew .icon { width: 26px; height: 26px; }
.road-node.claimed { opacity: 0.75; }
.road-node.claimed .road-circle { background: #bfe3a8; }
.road-check { color: #2f6a1d; }
.road-node.claimable { border-color: #e8791f; box-shadow: 0 0 14px #ffc93c; animation: roadpulse 1.2s ease-in-out infinite; }
.road-claim {
  margin-top: 4px; padding: 6px 10px;
  font-size: 13px; font-weight: bold; color: var(--cream);
  background: linear-gradient(#ffb03a, #e8791f);
  border: 2px solid var(--wood-dark); border-radius: 10px;
  box-shadow: 0 3px 0 var(--wood-dark);
}
.road-node.locked { filter: grayscale(0.7); }
.road-lock { width: 22px; height: 22px; opacity: 0.7; }
.emote-indeck.road { background: #c98512; }

/* ---------- Cloud-first boot veil + net status ---------- */
#boot-veil {
  position: absolute; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(30, 20, 5, 0.55);
  color: var(--cream); font-size: 22px; font-weight: bold;
  text-shadow: 2px 2px 0 var(--wood-dark);
}
#boot-veil span { animation: veilpulse 1s ease-in-out infinite; }
@keyframes veilpulse { 50% { opacity: 0.55; } }
#net-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #5cc24a; border: 2px solid var(--wood-dark);
  align-self: center; flex-shrink: 0;
}
#net-dot.off { background: #8a8a8a; }

/* ---------- Challenge tiers + animated cup pins ---------- */
.challenge-tier {
  display: inline-block; padding: 2px 10px; border-radius: 10px;
  color: #fff; font-size: 12px; font-weight: bold; margin-left: 6px;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.4);
}

/* ---------- Online net HUD (role, snapshot age, warnings) ---------- */
#net-debug {
  position: absolute; top: 8px; left: 10px; z-index: 16;
  font-size: 11px; font-weight: bold; color: #fff6e0;
  background: rgba(40, 25, 10, 0.65); border-radius: 8px; padding: 2px 8px;
  pointer-events: none;
}
#net-warn {
  position: absolute; top: 34px; left: 50%; transform: translateX(-50%); z-index: 16;
  font-size: 13px; font-weight: bold; color: #fff6e0; white-space: nowrap;
  background: rgba(194, 59, 43, 0.92); border: 2px solid #5a1d12; border-radius: 10px;
  padding: 3px 12px; pointer-events: none;
  animation: otpulse 1.2s ease-in-out infinite;
}

/* ---------- Online friendly battles + friends ---------- */
#page-battle .mini-online {
  display: block;
  margin: 6px auto 0;
  padding: 6px 22px;
  font-size: 15px; font-weight: bold; color: var(--cream);
  background: linear-gradient(#6cc04a, #3f9a2a);
  border: 3px solid var(--wood-dark); border-radius: 12px;
  box-shadow: 0 3px 0 var(--wood-dark);
  flex-shrink: 0;
}
#account-modal .modal-box { max-height: 86vh; overflow-y: auto; }
#btn-account.alert { animation: roadpulse 1.1s ease-in-out infinite; border-color: #e05a47; }
.friends-sec h3 { font-size: 20px; margin-bottom: 6px; }
.friend-row {
  display: flex; align-items: center; gap: 8px;
  margin: 6px 0;
}
.friend-row input {
  flex: 1; min-width: 0;
  padding: 8px 10px; font-size: 15px; font-family: inherit;
  border: 3px solid var(--wood-dark); border-radius: 10px;
  background: #fffdf4; color: var(--wood-dark);
}
.friend-row .action-btn { flex: 0 0 auto; font-size: 14px; padding: 8px 12px; }
.friend-name { flex: 1; font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-x {
  width: 32px; height: 32px; flex-shrink: 0;
  font-size: 20px; font-weight: bold; line-height: 1;
  color: var(--cream); background: #c0392b;
  border: 2px solid var(--wood-dark); border-radius: 50%;
}
.online-dot { width: 12px; height: 12px; border-radius: 50%; background: #8a8a8a; border: 2px solid var(--wood-dark); flex-shrink: 0; }
.online-dot.on { background: #5cc24a; box-shadow: 0 0 6px #5cc24a; }
.room-code {
  font-size: 30px; font-weight: bold; letter-spacing: 6px;
  background: #4a2c12; color: var(--gold);
  padding: 6px 12px 6px 18px; border-radius: 12px;
}
.room-code.small { font-size: 16px; letter-spacing: 2px; padding: 4px 10px; }

/* ---------- Account ---------- */
#btn-account .icon { width: 26px; height: 26px; }
#btn-account.off { opacity: 0.55; }
.account-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.account-form input {
  padding: 10px 12px; font-size: 16px; font-family: inherit;
  border: 3px solid var(--wood-dark); border-radius: 12px;
  background: #fffdf4; color: var(--wood-dark);
}
.account-err { color: #c0392b; font-weight: bold; }
.privacy-link { color: #3b82f6; font-weight: bold; }

/* Online/offline account chooser: comparison table */
.compare-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 14px;
  background: #fffdf4;
  border: 3px solid var(--wood-dark);
  border-radius: 12px;
  overflow: hidden;
}
.compare-table th, .compare-table td {
  border: 1px solid #c9b183;
  padding: 7px 8px;
  text-align: center;
}
.compare-table th { background: #f0dfb8; }
.compare-table td:first-child, .compare-table th:first-child { text-align: left; font-weight: bold; }
.compare-table .yes { color: #2f6a1d; font-weight: bold; }
.compare-table .no { color: #c0392b; font-weight: bold; }
.account-transfer { margin-top: 10px; border-top: 2px dashed var(--wood-dark); padding-top: 8px; }
.account-transfer textarea {
  width: 100%; min-height: 52px; max-height: 90px;
  font-size: 10px; font-family: monospace;
  border: 3px solid var(--wood-dark); border-radius: 10px;
  background: #fffdf4; color: var(--wood-dark);
  padding: 6px; resize: vertical;
}

/* Gift-code congrats popup: the loot list */
.codes-title { font-size: 18px; margin: 14px 0 2px; }
.code-loot { list-style: none; margin: 12px 0; display: flex; flex-direction: column; gap: 6px; }
.code-loot li {
  background: #fff8e6; border: 2px solid var(--wood-dark); border-radius: 10px;
  padding: 6px 10px; font-weight: bold;
  display: flex; align-items: center; gap: 8px; text-align: left;
}
.code-loot li .icon { width: 32px; height: 32px; flex: none; }
.code-loot canvas.loot-card { width: 36px; height: 36px; flex: none; }

/* Shop chest preview popup */
.shop-chest-info { cursor: pointer; }
.chest-info-row {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: #fff8e6; border: 2px solid var(--wood-dark); border-radius: 10px;
  padding: 6px 10px; margin: 6px 0; font-size: 14px; font-weight: bold;
}
.chest-info-row .icon { width: 30px; height: 30px; flex: none; }

/* Developer (admin-only) code manager rows */
.admin-code-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: #fff8e6; border: 2px solid var(--wood-dark); border-radius: 10px;
  padding: 6px 8px; margin-bottom: 6px; font-size: 13px;
}
.admin-code-row .action-btn { padding: 2px 8px; font-size: 12px; }

/* ---------- Daily quests ---------- */
.tower-grid { grid-template-columns: repeat(2, 1fr); }
.tower-tile canvas { width: 64px; height: 64px; }
.tower-up { margin-top: 6px; font-size: 15px; }
#quest-list { display: flex; flex-direction: column; gap: 10px; }
.quest-row {
  background: #fff8e6; border: 3px solid var(--wood-dark); border-radius: 14px;
  padding: 10px 12px;
}
.quest-row.claimable { border-color: #e8791f; box-shadow: 0 0 14px #ffc93c; }
.quest-row.claimed { opacity: 0.7; }
.quest-info { display: flex; justify-content: space-between; font-size: 15px; }
.quest-info span { font-weight: bold; }
.quest-bar {
  height: 12px; margin: 8px 0;
  background: #4a2c12; border: 2px solid var(--wood-dark); border-radius: 8px; overflow: hidden;
}
.quest-bar div { height: 100%; background: linear-gradient(#ffe07a, #e8a51f); transition: width 0.3s; }
.quest-foot { display: flex; align-items: center; justify-content: space-between; }
.quest-rew { display: flex; align-items: center; gap: 4px; font-size: 16px; font-weight: bold; }
.quest-rew .icon { width: 26px; height: 26px; }
.quest-done { font-size: 14px; font-weight: bold; color: #3f9a2a; }

/* ---------- Battle screen ---------- */
#battle-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--grass-dark);
  z-index: 10;
}
.canvas-wrap { flex: 1; min-height: 0; overflow: hidden; }
#battle-canvas { display: block; cursor: pointer; } /* size is set in fitCanvas() */

.hand {
  background: var(--wood);
  border-top: 5px solid var(--wood-dark);
  padding: 8px 12px 12px;
}

.feed-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.feed-icon { width: 30px; height: 30px; }
.feed-track {
  flex: 1; height: 16px;
  background: #4a2c12; border: 2px solid var(--wood-dark); border-radius: 10px; overflow: hidden;
}
#feed-fill { height: 100%; width: 50%; background: linear-gradient(#ffe07a, #e8a51f); }
#feed-count { color: var(--cream); font-size: 22px; font-weight: bold; min-width: 24px; text-align: center; }

#hand-cards { display: flex; gap: 8px; justify-content: center; align-items: flex-end; }
.next-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  margin-right: 6px;
  color: var(--cream); font-size: 11px; font-weight: bold;
}
.next-card canvas {
  width: 44px; height: 44px;
  background: var(--cream); border: 3px solid var(--wood-dark); border-radius: 10px;
  opacity: 0.85;
}
.hand-card {
  position: relative;
  width: 80px; height: 98px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--cream);
  border: 3px solid var(--wood-dark);
  border-radius: 12px;
  box-shadow: 0 4px 0 var(--wood-dark);
  transition: transform 0.1s;
}
.hand-card canvas { width: 60px; height: 60px; }
.hand-card .hand-name { font-size: 12px; font-weight: bold; color: var(--wood-dark); }
.hand-card.selected { transform: translateY(-10px); background: #fff1b8; border-color: #e8791f; }
.hand-card.too-expensive { filter: grayscale(0.8) brightness(0.8); }
.hand-card.locked { background: #c9b99a; cursor: default; }
.hand-card.locked .icon { width: 40px; height: 40px; }
.cost-badge {
  position: absolute; top: -8px; left: -8px;
  width: 26px; height: 26px; line-height: 20px;
  background: var(--gold); border: 3px solid #7a5a10; border-radius: 50%;
  font-weight: bold; color: #5a3a10; font-size: 14px;
}

/* Result popup */
#result {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(30, 20, 5, 0.55);
}
.result-box {
  background: var(--cream);
  border: 5px solid var(--wood-dark);
  border-radius: 22px;
  padding: 24px 40px;
  text-align: center;
  box-shadow: 0 8px 0 var(--wood-dark);
}
.result-box h2 { font-size: 36px; }
.result-box p { font-size: 18px; margin-top: 6px; }
#result-chest { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 10px auto 0; font-weight: bold; max-width: 260px; }
#result-chest .icon { width: 44px; height: 44px; }

/* Countdown + overtime polish */
#countdown {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(30, 20, 5, 0.45);
  z-index: 20; pointer-events: none;
}
#countdown span {
  font-size: 110px; font-weight: bold; color: var(--cream);
  text-shadow: 4px 4px 0 var(--wood-dark), 0 0 30px rgba(255, 201, 60, 0.8);
  animation: countpop 0.9s ease-out;
}
@keyframes countpop {
  0% { transform: scale(1.8); opacity: 0; }
  25% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.95); opacity: 1; }
}
#overtime-banner {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  background: rgba(194, 59, 43, 0.95); color: #fff6e0;
  font-weight: bold; font-size: 15px; padding: 8px 18px; border-radius: 14px;
  border: 3px solid #5a1d12; box-shadow: 0 4px 0 rgba(0,0,0,0.3);
  z-index: 15; white-space: nowrap;
  animation: otpulse 1.2s ease-in-out infinite;
}
@keyframes otpulse { 50% { transform: translateX(-50%) scale(1.05); } }

/* ---------- Trophies, arenas, locked cards ---------- */
.pills { display: flex; gap: 8px; }
.big-btn:disabled { filter: grayscale(1); opacity: 0.6; cursor: default; transform: none; }

.arena-nav { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 8px; }
.arena-nav .arena-label { margin-bottom: 0; }
.arena-arrow {
  width: 36px; height: 36px;
  font-size: 26px; font-weight: bold; line-height: 30px;
  color: var(--cream); background: var(--wood);
  border: 3px solid var(--wood-dark); border-radius: 50%;
}
.arena-arrow:disabled { opacity: 0.3; cursor: default; }

.arena-preview-wrap { position: relative; width: fit-content; margin: 0 auto; }
.arena-lock {
  position: absolute; inset: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: rgba(30, 20, 5, 0.6); border-radius: 10px;
  color: var(--cream); font-size: 20px; font-weight: bold;
}
.arena-lock .icon { width: 64px; height: 64px; }

.arena-progress { margin: 6px auto 0; max-width: 320px; font-size: 14px; font-weight: bold; }
.arena-bar { position: relative; height: 18px; margin-top: 4px; background: #d9c59a; border: 2px solid var(--wood-dark); border-radius: 9px; overflow: hidden; }
.arena-bar div { height: 100%; background: linear-gradient(#ffe07a, #e8a51f); }
.arena-bar b { position: absolute; inset: 0; font-size: 12px; line-height: 14px; }

.arena-cards-title { margin-top: 10px; font-size: 13px; font-weight: bold; }
.arena-cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 6px; }
.arena-card-item {
  display: flex; flex-direction: column; align-items: center;
  width: 64px; padding: 3px;
  background: #fff8e6; border: 3px solid; border-radius: 10px;
  font-size: 10px; font-weight: bold;
}
.arena-card-item canvas { width: 44px; height: 44px; }
.arena-card-item.locked canvas, .card-tile.locked canvas { filter: grayscale(1) brightness(0.6); }
.arena-card-item.locked { opacity: 0.75; }

.card-tile.locked { background: #e2d4b2; }
.tile-lock { display: flex; align-items: center; gap: 3px; font-size: 12px; font-weight: bold; }
.tile-lock .icon { width: 16px; height: 16px; }
.upgrade-need .icon { width: 16px; height: 16px; vertical-align: middle; }

.chest-arena { font-size: 10px; font-weight: bold; background: var(--wood); color: var(--cream); padding: 0 6px; border-radius: 6px; }
.reward-card { position: relative; }
.new-badge {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  white-space: nowrap; padding: 1px 6px;
  background: #e05a47; color: #fff; border-radius: 8px; font-size: 10px; font-weight: bold;
}
#result-chest { flex-wrap: wrap; }
.new-arena { width: 100%; color: #3f9a2a; font-size: 18px; }

/* Arena list popup */
.arena-preview-wrap { cursor: pointer; }
.arena-hint { font-size: 12px; opacity: 0.75; }
.arena-list { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; max-height: 65vh; overflow-y: auto; padding-right: 4px; }
.arena-entry {
  padding: 10px;
  background: #fff8e6;
  border: 3px solid var(--wood-dark);
  border-radius: 14px;
  text-align: left;
}
.arena-entry.current { border-color: #e8791f; box-shadow: 0 0 10px var(--gold); }
.arena-entry.locked { background: #e2d4b2; }
.arena-entry.locked .arena-thumb { filter: grayscale(0.8) brightness(0.7); }
.arena-entry-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 16px; }
.arena-entry-trophies { display: flex; align-items: center; gap: 3px; font-weight: bold; }
.arena-entry-trophies .icon { width: 20px; height: 20px; }
.arena-entry-body { display: flex; gap: 10px; align-items: flex-start; }
.arena-thumb { width: 96px; border: 3px solid var(--wood-dark); border-radius: 8px; flex-shrink: 0; }
.arena-entry .arena-cards { justify-content: flex-start; }
.arena-entry .arena-cards-title { margin-top: 0; }

/* ---------- Wooden scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--wood) rgba(90, 53, 21, 0.15); }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: rgba(90, 53, 21, 0.15); border-radius: 6px; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(90deg, #b27a3f, var(--wood));
  border: 2px solid var(--wood-dark);
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover { background: linear-gradient(90deg, #c68a4c, #9a6a3a); }
.arena-no-cards { font-size: 13px; font-style: italic; opacity: 0.75; }

/* Pause button (bot matches only): orange, top-left corner of the arena */
#btn-pause {
  position: absolute; top: 8px; left: 10px; z-index: 16;
  width: 38px; height: 38px; border-radius: 12px;
  background: linear-gradient(#ffb03a, #e8791f);
  border: 3px solid var(--wood-dark); color: #fff;
  font-size: 15px; font-weight: bold; cursor: pointer;
  box-shadow: 0 3px 0 var(--wood-dark);
}
#btn-pause:active { transform: translateY(3px); box-shadow: none; }
#pause-overlay {
  position: absolute; inset: 0; z-index: 15;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: rgba(30, 20, 5, 0.55); color: var(--cream);
  font-size: 34px; font-weight: bold; cursor: pointer;
}
#pause-overlay small { font-size: 14px; font-weight: normal; opacity: 0.85; }

/* Connection banner (online accounts): signal lost, auto-heals on return */
#conn-banner {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 30;
  max-width: 94%; padding: 7px 14px;
  background: rgba(160, 30, 20, 0.92); color: #fff6e0;
  border: 3px solid #5a0f0a; border-radius: 12px;
  font-size: 14px; font-weight: bold; text-align: center;
  box-shadow: 0 3px 0 rgba(0,0,0,0.35);
}

/* Spectator banner: who plays + invite/leave buttons, below the top edge */
#spectate-banner {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 16;
  display: flex; align-items: center; gap: 8px;
  max-width: 94%; padding: 5px 10px;
  background: rgba(40, 25, 10, 0.8); color: #fff6e0;
  border: 2px solid var(--wood-dark); border-radius: 12px;
  font-size: 13px; white-space: nowrap;
}
#spectate-banner .action-btn, #spectate-banner .tap-cancel {
  padding: 3px 10px; font-size: 12px;
}

/* Chest opening always sits above the other modals (quest/road rewards) */
#chest-modal { z-index: 60; }

/* ---------- Friendly room: deck editor + host settings ---------- */
.friend-subtitle { margin: 12px 0 6px; font-size: 15px; }
.fslots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.fslot {
  padding: 6px 2px; font-size: 12px; border-radius: 10px; cursor: pointer;
  background: #fff8e6; border: 2px solid var(--wood-dark); color: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.fslot b { font-size: 12px; color: #8a5a2b; }
.fslot.sel { border-color: #e8791f; box-shadow: 0 0 8px var(--gold); background: #fff3d0; }
.fslot.banned { border-color: #c0392b; background: #f3d8d0; }
/* Portrait canvases carry device pixels in their attributes: pin the CSS
   size or high-DPR phones blow the modal grids apart (mobile overflow). */
.fslot canvas { width: 44px; height: 44px; }
.fcard canvas { width: 56px; height: 56px; }
.road-pin { max-width: 56px; height: auto; }

/* Narrow phones: tighten the friendly deck grids so nothing overflows. */
@media (max-width: 400px) {
  .fslots { gap: 4px; }
  .fslot { font-size: 10px; padding: 4px 1px; }
  .fcards { gap: 4px; }
}
/* Narrow phones: the 8-slot deck board stays 4 x 2 but shrinks so all
   four columns fit without overflowing. */
@media (max-width: 480px) {
  #deck-grid { grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 6px; }
  .deck-slot { min-height: 0; padding: 2px; border-radius: 8px; }
  #deck-grid .card-tile { padding: 4px 2px; border-width: 3px; border-radius: 10px; }
  #deck-grid .card-tile canvas { max-width: 44px; }
  #deck-grid .tile-name { font-size: 10px; }
  #deck-grid .tile-level { font-size: 9px; }
  #deck-grid .tile-bar { height: 12px; margin-top: 2px; }
  #deck-grid .tile-bar span { font-size: 9px; line-height: 12px; }
  #deck-grid .cost-badge {
    width: 20px; height: 20px; line-height: 15px; font-size: 11px;
    top: -6px; left: -6px; border-width: 2px;
  }
  .card-grid { gap: 10px 8px; }
}
.fcards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-height: 30vh; overflow-y: auto; padding-right: 2px; }
.fcard {
  padding: 5px 3px; font-size: 12px; border-radius: 10px; cursor: pointer;
  background: #fff8e6; border: 2px solid var(--wood-dark); color: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.fcard small { font-size: 10px; opacity: 0.75; }
.fcard.in { background: #e4f3d8; }
.fpeer-card {
  display: inline-block; margin: 2px; padding: 3px 8px; font-size: 12px;
  background: #fff8e6; border: 2px solid var(--wood-dark); border-radius: 10px;
}
#rule-level { width: 64px; }
.room-code { letter-spacing: 2px; }

/* ---------- Leaderboard ---------- */
.board-tabs { display: flex; gap: 6px; margin: 8px 0; }
.board-table { width: 100%; border-collapse: collapse; }
.board-table td { padding: 6px 8px; border-bottom: 2px solid rgba(90, 53, 21, 0.15); font-size: 14px; }
.board-pos { width: 44px; font-weight: bold; }
.board-pos.gold { color: #a8801f; }
.board-pos.silver { color: #6a6a72; }
.board-pos.bronze { color: #8a5a2b; }
.board-val { text-align: right; font-weight: bold; white-space: nowrap; }
.board-me td { background: #fff3d0; }

/* ---------- Daily streak ---------- */
.daily-dots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }

/* Narrow phones: compact account + chooser modals so the login fits without scrolling. */
@media (max-width: 480px) {
  .modal { padding: 8px; }
  #account-modal .modal-box, #acctype-modal .modal-box { padding: 10px 12px; border-width: 4px; }
  #account-modal .chest-modal-title, #acctype-modal .chest-modal-title { font-size: 20px; margin: 2px 0 4px; }
  #account-modal .custom-hint, #acctype-modal .custom-hint { font-size: 12px; margin: 4px 0 6px; }
  #account-modal .account-form { gap: 5px; margin-top: 4px; }
  #account-modal .account-form input { padding: 7px 10px; font-size: 14px; }
  #account-modal .action-btn { padding: 7px; font-size: 15px; }
  #account-modal .modal-actions { margin-top: 8px; }
  .compare-table { font-size: 12px; margin: 6px 0; }
  .compare-table th, .compare-table td { padding: 4px 5px; }
}
.daily-dot {
  padding: 6px 2px; font-size: 11px; border-radius: 10px; text-align: center;
  background: #fff8e6; border: 2px solid var(--wood-dark);
  display: flex; flex-direction: column; gap: 2px;
}
.daily-dot.done { background: #e4f3d8; }
.daily-dot.now { border-color: #e8791f; box-shadow: 0 0 8px var(--gold); background: #fff3d0; }

/* Compact phone game board: viewport fills the screen, lobby controls fit
   above the fixed tabs, and the entire five-slot card hand stays onscreen. */
@media (max-width: 480px) {
  #app { height: 100vh; height: 100dvh; min-height: 0; }
  body { overflow: hidden; }
  .top-bar { flex: 0 0 auto; }
  #content { flex: 1 1 auto; min-height: 0; padding: 8px; }
  #page-battle.active { height: 100%; min-height: 0; }
  #page-battle .arena-card { padding: 5px; }
  #page-battle .arena-card h2 { font-size: 18px; line-height: 1.1; }
  #page-battle .arena-hint { font-size: 10px; line-height: 1.1; }
  #page-battle #btn-fight { margin-top: 5px; padding: 7px 26px; font-size: 19px; }
  #page-battle .mini-online { margin-top: 4px; padding: 5px 16px; font-size: 13px; }
  #page-battle .chest-title { margin: 5px 0 4px; font-size: 15px; }
  #page-battle .chest-slots { gap: 4px; }
  #page-battle .chest-slot { min-width: 0; min-height: 65px; padding: 4px 2px; gap: 0; border-width: 2px; }
  #page-battle .chest-arena, #page-battle .chest-name { font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  #page-battle .chest-time { font-size: 10px; }
  #page-battle .chest-icon { width: 27px; height: 27px; }
  #page-battle #game-version { margin-top: 2px; font-size: 9px; }
  .tab-bar { flex: 0 0 auto; }
  #battle-screen { min-height: 0; overflow: hidden; }
  .canvas-wrap { flex: 1 1 auto; min-height: 0; }
  .hand { flex: 0 0 auto; padding: 5px 5px max(7px, env(safe-area-inset-bottom)); }
  .feed-bar { gap: 5px; margin-bottom: 5px; }
  .feed-icon { width: 24px; height: 24px; }
  #feed-count { font-size: 18px; min-width: 20px; }
  #hand-cards { gap: 4px; width: 100%; min-width: 0; }
  .next-card { flex: 0 0 38px; width: 38px; min-width: 0; margin-right: 0; font-size: 9px; }
  .next-card canvas { width: 34px; height: 34px; border-width: 2px; }
  .hand-card { flex: 1 1 0; width: auto; min-width: 0; max-width: 82px; height: 82px; border-width: 2px; }
  .hand-card canvas { width: min(13vw, 44px); height: min(13vw, 44px); }
  .hand-card .hand-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
  .hand-card .cost-badge { width: 21px; height: 21px; line-height: 16px; font-size: 11px; border-width: 2px; top: -6px; left: -6px; }
}
