/* ============================================================
   Romantic Dice · style.css
   Dark, elegant, rose-gold / violet neon.
   ============================================================ */

:root {
  --night:   #0a0a0f;
  --mid:     #101018;
  --char:    #1a1a24;
  --ash:     #262633;
  --rose:    #e8b4c0;
  --rosehi:  #f5c9d4;
  --violet:  #9b7bd9;
  --neon:    #b388ff;
  --muted:   #8a8a99;
  --shadow:  0 10px 40px -10px rgba(0,0,0,0.7);
}

* { -webkit-tap-highlight-color: transparent; }

html, body { overflow-x: hidden; }

body {
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(155,123,217,0.18), transparent 60%),
    radial-gradient(1000px 500px at 90% 10%, rgba(232,180,192,0.12), transparent 55%),
    var(--night);
  background-attachment: fixed;
}

/* ---------- Age gate ---------- */
#age-gate.is-hidden { opacity: 0; pointer-events: none; }
.age-card { animation: rise .5s ease both; }

/* ---------- Panels / Buttons ---------- */
.panel {
  background: linear-gradient(180deg, rgba(38,38,51,0.55), rgba(26,26,36,0.55));
  border: 1px solid rgba(232,180,192,0.10);
  backdrop-filter: blur(8px);
}

.gate-btn, .ctrl-btn, .roll-btn, .task-btn {
  position: relative;
  border-radius: 9999px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: transform .15s ease, box-shadow .25s ease, background .25s ease, color .25s ease, border-color .25s ease;
  user-select: none;
}
.gate-btn  { padding: 0.75rem 1rem; font-size: 0.95rem; }
.ctrl-btn  { padding: 0.55rem 0.9rem; font-size: 0.8rem; }
.roll-btn  { padding: 0.7rem 1.3rem; font-size: 0.95rem; font-weight: 600; }
.task-btn  { padding: 0.6rem 1.3rem; font-size: 0.85rem; }

.gate-btn.primary, .task-btn.primary, .ctrl-btn:not(.ghost) {
  background: linear-gradient(135deg, var(--rose), var(--violet));
  color: #1a0d1f;
  box-shadow: 0 8px 24px -8px rgba(232,180,192,0.5);
}
.gate-btn.primary:hover, .task-btn.primary:hover, .ctrl-btn:not(.ghost):hover, .roll-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px -10px rgba(179,136,255,0.55);
}
.gate-btn.ghost, .task-btn.ghost, .ctrl-btn.ghost, .roll-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(232,180,192,0.25);
  color: var(--rose);
}
.gate-btn.ghost:hover, .task-btn.ghost:hover, .ctrl-btn.ghost:hover {
  border-color: var(--rose);
  background: rgba(232,180,192,0.08);
}
.roll-btn {
  background: linear-gradient(135deg, rgba(232,180,192,0.15), rgba(155,123,217,0.15));
  border: 1px solid rgba(232,180,192,0.4);
  color: var(--rosehi);
}
.roll-btn:active { transform: scale(0.97); }
.roll-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ripple */
.ripple { overflow: hidden; }
.ripple::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: radial-gradient(circle at var(--rx, 50%) var(--ry, 50%), rgba(255,255,255,0.35), transparent 40%);
  opacity: 0; transition: opacity .5s ease;
}
.ripple.is-rippling::after { opacity: 1; transition: none; }

/* ---------- Spice slider ---------- */
.spice-range {
  -webkit-appearance: none; appearance: none;
  height: 6px; border-radius: 9999px;
  background: linear-gradient(90deg, var(--rose), var(--violet), #ff4d6d);
  outline: none;
}
.spice-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--rosehi);
  box-shadow: 0 0 0 4px rgba(232,180,192,0.2), 0 4px 10px rgba(0,0,0,0.5);
  cursor: pointer; border: 2px solid #1a0d1f;
}
.spice-range::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--rosehi); border: 2px solid #1a0d1f;
  box-shadow: 0 0 0 4px rgba(232,180,192,0.2); cursor: pointer;
}

/* ---------- Player cards ---------- */
.player-card {
  border: 1px solid rgba(232,180,192,0.12);
  background: linear-gradient(180deg, rgba(38,38,51,0.45), rgba(16,16,24,0.45));
}
.player-card[data-player="A"] { box-shadow: inset 0 0 0 1px rgba(232,180,192,0.08); }
.player-card[data-player="B"] { box-shadow: inset 0 0 0 1px rgba(155,123,217,0.10); }

.turn-indicator { animation: pulse 1.6s ease-in-out infinite; }

/* ============================================================
   BOARD
   6 columns x 6 rows serpentine -> 36 tiles (index 0..35)
   ============================================================ */
.board-frame {
  background: linear-gradient(180deg, rgba(26,26,36,0.7), rgba(10,10,15,0.7));
  border: 1px solid rgba(232,180,192,0.12);
  box-shadow: var(--shadow);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: 6px;
  aspect-ratio: 1 / 1;
}

.tile {
  position: relative;
  border-radius: 12px;
  background: transparent;
  border: none;
  min-height: 54px;
  min-width: 0;
  padding: 0;
  text-align: center;
  perspective: 800px;
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease, background .25s ease;
  cursor: default;
}

.tile-flipper {
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  border-radius: 12px;
}
.tile.flipped .tile-flipper { transform: rotateY(180deg); }

.tile-face {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 4px;
  border-radius: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

.tile-front {
  background: rgba(38,38,51,0.55);
  border: 1px solid rgba(255,255,255,0.04);
}
.tile-back {
  transform: rotateY(180deg);
  background: linear-gradient(135deg, rgba(232,180,192,0.22), rgba(155,123,217,0.22));
  border: 1px solid rgba(232,180,192,0.45);
  color: var(--rosehi);
  padding: 6px;
}
.tile-back .tile-back-text {
  font-size: 9px;
  line-height: 1.15;
  color: var(--rosehi);
  text-align: center;
  letter-spacing: 0.01em;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile .tile-no {
  position: absolute; top: 4px; left: 6px;
  font-size: 9px; color: var(--muted); letter-spacing: 0.05em;
  z-index: 2;
}
.tile .tile-type {
  font-size: 10px; font-weight: 600; color: var(--rose);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.tile .tile-emoji { font-size: 18px; line-height: 1; margin-top: 2px; }

.tile[data-type="start"]    .tile-front { background: linear-gradient(135deg, rgba(232,180,192,0.35), rgba(155,123,217,0.25)); border-color: rgba(232,180,192,0.6); }
.tile[data-type="end"]      .tile-front { background: linear-gradient(135deg, rgba(179,136,255,0.35), rgba(232,180,192,0.25)); border-color: rgba(179,136,255,0.6); }
.tile[data-type="forward"]  .tile-front { background: linear-gradient(135deg, rgba(123,210,180,0.25), rgba(38,38,51,0.55)); }
.tile[data-type="back"]     .tile-front { background: linear-gradient(135deg, rgba(220,90,120,0.25), rgba(38,38,51,0.55)); }
.tile[data-type="special"]  .tile-front { background: linear-gradient(135deg, rgba(255,77,109,0.25), rgba(38,38,51,0.55)); border-color: rgba(255,77,109,0.5); }
.tile[data-type="skip"]     .tile-front { background: linear-gradient(135deg, rgba(255,210,128,0.20), rgba(38,38,51,0.55)); }

.tile.is-active .tile-flipper {
  box-shadow: 0 0 0 2px var(--rose), 0 0 18px rgba(232,180,192,0.5);
  transform: scale(1.04);
  z-index: 2;
}
.tile.is-active.flipped .tile-flipper {
  transform: scale(1.04) rotateY(180deg);
}

.pieces { position: absolute; bottom: 4px; left: 0; right: 0; display: flex; gap: 3px; justify-content: center; z-index: 3; pointer-events: none; }
.piece {
  width: 13px; height: 13px; border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.4), 0 0 8px currentColor;
  transition: all .35s cubic-bezier(.2,.9,.3,1);
}
.piece[data-p="A"] { background: var(--rosehi); color: var(--rosehi); }
.piece[data-p="B"] { background: var(--neon);   color: var(--neon); }

/* ---------- Dice (3D-ish via transform) ---------- */
.dice {
  position: relative;
  width: 72px; height: 72px;
  display: grid; place-items: center;
  transition: transform .8s cubic-bezier(.2,.8,.3,1);
}
.dice-face {
  position: absolute;
  width: 72px; height: 72px;
  border-radius: 14px;
  background: linear-gradient(145deg, #fff8f3, #e7c9d3);
  display: grid; place-items: center;
  gap: 6px; padding: 8px;
  box-shadow: inset 0 -4px 8px rgba(0,0,0,0.15), 0 8px 20px rgba(0,0,0,0.45);
  grid-template-areas: "a . c" "e f b" "d . g";
}
.dice-face .pip { width: 10px; height: 10px; border-radius: 50%; background: #2a1014; box-shadow: inset 0 1px 2px rgba(0,0,0,0.6); }
.dice-face[data-face="1"] { grid-template-areas: ". . ." ". f ." ". . ."; }
.dice-face[data-face="2"] { grid-template-areas: "a . ." ". . ." ". . c"; }
.dice-face[data-face="3"] { grid-template-areas: "a . ." ". f ." ". . c"; }
.dice-face[data-face="4"] { grid-template-areas: "a . c" ". . ." "d . g"; }
.dice-face[data-face="5"] { grid-template-areas: "a . c" ". f ." "d . g"; }
.dice-face[data-face="6"] { grid-template-areas: "a . c" "e . b" "d . g"; }
.dice-face[data-face="6"] .pip:nth-child(1){ grid-area: a; }
.dice-face[data-face="6"] .pip:nth-child(2){ grid-area: e; }
.dice-face[data-face="6"] .pip:nth-child(3){ grid-area: b; }
.dice-face[data-face="6"] .pip:nth-child(4){ grid-area: d; }
.dice-face[data-face="6"] .pip:nth-child(5){ grid-area: g; }
.dice-face[data-face="6"] .pip:nth-child(6){ grid-area: c; }

.dice-face[data-face="1"] .pip:nth-child(1){ grid-area: f; }

.dice-face[data-face="2"] .pip:nth-child(1){ grid-area: a; }
.dice-face[data-face="2"] .pip:nth-child(2){ grid-area: c; }

.dice-face[data-face="3"] .pip:nth-child(1){ grid-area: a; }
.dice-face[data-face="3"] .pip:nth-child(2){ grid-area: f; }
.dice-face[data-face="3"] .pip:nth-child(3){ grid-area: c; }

.dice-face[data-face="4"] .pip:nth-child(1){ grid-area: a; }
.dice-face[data-face="4"] .pip:nth-child(2){ grid-area: c; }
.dice-face[data-face="4"] .pip:nth-child(3){ grid-area: d; }
.dice-face[data-face="4"] .pip:nth-child(4){ grid-area: g; }

.dice-face[data-face="5"] .pip:nth-child(1){ grid-area: a; }
.dice-face[data-face="5"] .pip:nth-child(2){ grid-area: c; }
.dice-face[data-face="5"] .pip:nth-child(3){ grid-area: f; }
.dice-face[data-face="5"] .pip:nth-child(4){ grid-area: d; }
.dice-face[data-face="5"] .pip:nth-child(5){ grid-area: g; }

/* Only the active face is shown; others hidden but kept for animation */
.dice-face { opacity: 0; transform: scale(0.6) rotate(-30deg); transition: opacity .2s ease, transform .2s ease; }
.dice-face.is-on { opacity: 1; transform: scale(1) rotate(0); }

.dice.is-rolling { animation: dice-spin .8s cubic-bezier(.2,.8,.3,1); }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; padding: 1.25rem; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,10,15,0.75); backdrop-filter: blur(8px); animation: fade .25s ease; }

.task-card, .custom-card, .disclaimer-card, .age-card, .donate-card {
  position: relative; z-index: 1;
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, #1a1a24, #101018);
  border: 1px solid rgba(232,180,192,0.18);
  border-radius: 22px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.custom-card, .disclaimer-card { max-width: 540px; }

.task-card { animation: cardIn .35s cubic-bezier(.2,.9,.3,1) both; }
.task-tag {
  display: inline-block; padding: 3px 10px; border-radius: 9999px;
  background: rgba(232,180,192,0.12); color: var(--rose);
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
}

.custom-input {
  background: rgba(10,10,15,0.6);
  border: 1px solid rgba(232,180,192,0.18);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  color: var(--rosehi); font-size: 0.85rem; outline: none;
}
.custom-input:focus { border-color: var(--rose); box-shadow: 0 0 0 2px rgba(232,180,192,0.18); }

#custom-tile {
  flex: 0 0 auto;
  width: 7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (min-width: 640px) { #custom-tile { width: 10rem; } }
#custom-tile option { background: #1a1a24; color: var(--rosehi); }

.custom-list { list-style: none; padding: 0; margin: 0; max-height: 280px; overflow-y: auto; }
.custom-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.5rem 0.6rem; border-radius: 10px;
  background: rgba(38,38,51,0.4); border: 1px solid rgba(255,255,255,0.04);
  margin-bottom: 6px; font-size: 0.8rem; color: var(--rose);
}
.custom-list li .pill-tile {
  display: inline-block; min-width: 28px; text-align: center;
  padding: 1px 6px; border-radius: 8px; margin-right: 8px;
  background: rgba(155,123,217,0.2); color: var(--neon); font-size: 10px;
}
.custom-list li .del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }
.custom-list li .del:hover { color: #ff6b8b; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 95; padding: 0.6rem 1rem; border-radius: 9999px;
  background: rgba(26,26,36,0.95); border: 1px solid rgba(232,180,192,0.25);
  color: var(--rosehi); font-size: 0.8rem; box-shadow: var(--shadow);
  animation: toastIn .3s ease both;
}
.toast.hidden { display: none; }

/* ---------- Ad slot ---------- */
.ad-slot { min-height: 80px; }

/* ---------- Mode tabs ---------- */
.mode-tab {
  padding: 0.5rem 0.9rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  transition: all .2s ease;
  cursor: pointer;
  white-space: nowrap;
}
.mode-tab:hover { color: var(--rose); border-color: rgba(232,180,192,0.2); }
.mode-tab.is-active {
  color: var(--rosehi);
  background: linear-gradient(135deg, rgba(232,180,192,0.18), rgba(155,123,217,0.18));
  border-color: rgba(232,180,192,0.4);
}

.vip-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 9999px;
  background: linear-gradient(135deg, #f5c9d4, #b388ff);
  color: #1a0d1f; font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
  box-shadow: 0 4px 12px -4px rgba(179,136,255,0.5);
}

.donate-pill {
  padding: 0.45rem 0.9rem; border-radius: 9999px;
  background: linear-gradient(135deg, rgba(255,196,90,0.2), rgba(232,180,192,0.2));
  border: 1px solid rgba(255,196,90,0.4);
  color: #ffd28a; font-size: 0.75rem; cursor: pointer;
  transition: all .2s ease;
}
.donate-pill:hover { background: linear-gradient(135deg, rgba(255,196,90,0.35), rgba(232,180,192,0.35)); }

/* ---------- Action dice ---------- */
.action-dice-row {
  display: flex; flex-wrap: wrap; gap: 12px;
  justify-content: center; padding: 8px 0;
}
.action-die {
  width: 76px; height: 76px;
  border-radius: 16px;
  background: linear-gradient(145deg, #fff8f3, #e7c9d3);
  display: grid; place-items: center;
  padding: 6px;
  text-align: center;
  color: #2a1014;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.15;
  box-shadow: inset 0 -4px 8px rgba(0,0,0,0.15), 0 8px 18px rgba(0,0,0,0.4);
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
  backface-visibility: hidden;
  word-break: break-word;
}
.action-die.is-rolling { animation: dice-spin 0.8s cubic-bezier(0.2, 0.8, 0.3, 1); }

.action-result {
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(232,180,192,0.18), rgba(155,123,217,0.18));
  border: 1px solid rgba(232,180,192,0.3);
  color: var(--rosehi);
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.action-result .ar-label { font-size: 10px; color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 4px; font-weight: 400; }
.action-result .ar-combo { font-family: "Playfair Display", serif; font-size: 1.1rem; }

/* ---------- Edit dice modal ---------- */
.edit-dice-list { max-height: 50vh; overflow-y: auto; }
.edit-dice-block {
  margin-bottom: 12px;
  padding: 0.75rem;
  background: rgba(38,38,51,0.5);
  border-radius: 10px;
  border: 1px solid rgba(232,180,192,0.1);
}
.edit-dice-block .ed-title {
  font-size: 11px; color: var(--rose); text-transform: uppercase;
  letter-spacing: 0.1em; margin-bottom: 6px; font-weight: 600;
}
.edit-dice-faces { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.edit-dice-faces input {
  background: rgba(10,10,15,0.7);
  border: 1px solid rgba(232,180,192,0.18);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--rosehi); font-size: 12px; outline: none;
  min-width: 0;
}
.edit-dice-faces input:focus { border-color: var(--rose); }

/* ---------- Donate modal ---------- */
.donate-card { max-width: 460px; }
.donate-link {
  display: flex; align-items: center; justify-content: center;
  padding: 0.7rem 0.4rem; border-radius: 12px;
  background: rgba(38,38,51,0.6);
  border: 1px solid rgba(232,180,192,0.2);
  color: var(--rosehi);
  font-size: 0.78rem;
  text-decoration: none;
  text-align: center;
  transition: all .2s ease;
}
.donate-link:hover { background: linear-gradient(135deg, rgba(232,180,192,0.18), rgba(155,123,217,0.18)); border-color: var(--rose); }

/* ---------- Chat panel ---------- */
.chat-box {
  height: 260px;
  overflow-y: auto;
  border-radius: 14px;
  background: rgba(10,10,15,0.6);
  border: 1px solid rgba(232,180,192,0.10);
  padding: 0.5rem;
}
.chat-box::-webkit-scrollbar { width: 6px; }
.chat-box::-webkit-scrollbar-thumb { background: rgba(232,180,192,0.25); border-radius: 3px; }
.chat-list { list-style: none; padding: 0; margin: 0; }
.chat-list li {
  display: flex; flex-direction: column;
  margin-bottom: 8px;
}
.chat-list li .meta {
  font-size: 9px; color: var(--muted); letter-spacing: 0.06em; margin-bottom: 2px;
}
.chat-list li .bubble {
  display: inline-block;
  padding: 7px 11px; border-radius: 12px;
  background: rgba(38,38,51,0.7);
  border: 1px solid rgba(232,180,192,0.10);
  font-size: 0.82rem; color: var(--rose); max-width: 80%;
  word-break: break-word; white-space: pre-wrap;
}
.chat-list li.me   { align-items: flex-end; }
.chat-list li.me   .bubble { background: linear-gradient(135deg, rgba(232,180,192,0.18), rgba(155,123,217,0.18)); border-color: rgba(232,180,192,0.4); color: var(--rosehi); }
.chat-list li.them { align-items: flex-start; }
.chat-list li.them .bubble { background: rgba(38,38,51,0.7); color: var(--rose); }
.chat-list li.sys  { align-items: center; }
.chat-list li.sys  .bubble { font-size: 10px; color: var(--muted); background: none; border: none; padding: 2px; }
.chat-list li .bubble img { max-width: 220px; max-height: 220px; border-radius: 8px; display: block; cursor: zoom-in; }
.chat-list li .time { font-size: 9px; color: var(--muted); margin-top: 2px; align-self: flex-end; }
.chat-list li.them .time { align-self: flex-start; }
.chat-loading { color: var(--muted); font-size: 11px; text-align: center; padding: 1rem; }

/* ---------- Language switcher ---------- */
.lang-pick {
  background: rgba(232,180,192,0.08);
  border: 1px solid rgba(232,180,192,0.15);
  border-radius: 8px;
  padding: 3px 6px;
  font-size: 14px;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease;
}
.lang-pick:hover { background: rgba(232,180,192,0.18); border-color: rgba(232,180,192,0.4); }
.lang-pick.is-active { background: linear-gradient(135deg, rgba(232,180,192,0.25), rgba(155,123,217,0.25)); border-color: var(--rose); }

/* ---------- Animations ---------- */
@keyframes rise   { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fade   { from { opacity: 0; } to { opacity: 1; } }
@keyframes cardIn { from { opacity: 0; transform: translateY(20px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes pulse  { 0%,100% { opacity: .55; } 50% { opacity: 1; } }
@keyframes toastIn{ from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes dice-spin {
  0%   { transform: rotate(0) scale(1); }
  25%  { transform: rotate(120deg) scale(1.08); }
  50%  { transform: rotate(240deg) scale(1.12); }
  75%  { transform: rotate(360deg) scale(1.04); }
  100% { transform: rotate(420deg) scale(1); }
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .dice, .dice-face { width: 60px; height: 60px; }
  .board-grid { gap: 4px; }
  .tile { min-height: 44px; }
  .tile-face, .tile-flipper { border-radius: 9px; }
  .tile .tile-emoji { font-size: 14px; }
  .tile .tile-type { font-size: 8px; }
  .tile-back .tile-back-text { font-size: 7px; -webkit-line-clamp: 3; }
  .gate-btn { font-size: 0.85rem; padding: 0.7rem 0.9rem; }
}

/* ============================================================
   MOBILE-FIRST (≤ 640px)
   Touch targets ≥ 48px · active scale · board fits one screen
   Chat becomes a bottom sheet · soft keyboard adaptation
   ============================================================ */
@media (max-width: 640px) {
  :root { --shadow: 0 4px 16px -4px rgba(0,0,0,0.7); }

  body { -webkit-text-size-adjust: 100%; }

  #mode-tabs > div { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #mode-tabs > div::-webkit-scrollbar { display: none; }
  .mode-tab { padding: 0.45rem 0.7rem; font-size: 0.75rem; }
  .vip-badge { display: none !important; }
  .donate-pill { padding: 0.4rem 0.7rem; font-size: 0.7rem; }

  .action-die { width: 64px; height: 64px; font-size: 10px; padding: 4px; }
  .action-dice-row { gap: 8px; }
  .action-result .ar-combo { font-size: 0.95rem; }

  .edit-dice-faces { grid-template-columns: repeat(2, 1fr); }

  .gate-btn, .ctrl-btn, .roll-btn, .task-btn {
    min-height: 48px;
    padding-top:    0.7rem;
    padding-bottom: 0.7rem;
  }
  .gate-btn { font-size: 0.95rem; }
  .ctrl-btn { font-size: 0.85rem; }
  .roll-btn { font-size: 1rem; padding-left: 1.5rem; padding-right: 1.5rem; }
  .task-btn { font-size: 0.95rem; }
  .lang-pick {
    min-width: 44px; min-height: 44px;
    padding: 6px 8px; font-size: 18px;
  }
  .lang-option { min-height: 44px; padding-top: 0.6rem; padding-bottom: 0.6rem; }
  #btn-sound { min-width: 48px; }

  .gate-btn:active, .ctrl-btn:active, .roll-btn:active,
  .task-btn:active, .lang-pick:active, .lang-option:active {
    transform: scale(0.95);
    transition: transform .08s ease;
  }

  header .mx-auto { padding-top: 0.55rem; padding-bottom: 0.55rem; }
  #online-pill, #room-pill, #lang-switcher button { padding-left: 0.6rem; padding-right: 0.6rem; }
  #lang-name { display: none; }

  section.mx-auto.max-w-5xl.px-4.sm\:px-6.pt-6 { padding-top: 0.85rem; }
  .panel { padding: 0.85rem; }

  .board-frame { padding: 0.5rem; border-radius: 18px; }
  .board-grid { gap: 4px; aspect-ratio: 1 / 1; }
  .tile {
    min-height: 0;
    padding: 0;
  }
  .tile-face, .tile-flipper { border-radius: 8px; }
  .tile .tile-no    { font-size: 7px; top: 2px; left: 3px; }
  .tile .tile-type  { font-size: 7px; letter-spacing: 0.04em; }
  .tile .tile-emoji { font-size: 13px; }
  .tile-back .tile-back-text { font-size: 7px; -webkit-line-clamp: 3; line-height: 1.1; }
  .piece { width: 10px; height: 10px; }

  .player-card { padding: 0.6rem; border-radius: 14px; }
  .player-card .font-display { font-size: 1rem; }
  .player-card .text-xs.uppercase { font-size: 9px; }

  .grid.sm\:grid-cols-\[1fr_auto_1fr\] {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }
  .flex.flex-col.items-center.gap-3 { order: -1; }

  .dice { width: 64px; height: 64px; }
  .dice-face { width: 64px; height: 64px; border-radius: 12px; padding: 6px; }
  .dice-face .pip { width: 8px; height: 8px; }

  #chat-section {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 70;
    padding: 0;
    margin: 0;
    background: transparent;
    pointer-events: none;
  }
  #chat-section .panel {
    pointer-events: auto;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    background: linear-gradient(180deg, #1a1a24ee, #101018f7);
    backdrop-filter: blur(14px);
    padding: 0.6rem 0.85rem calc(0.6rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -6px 24px -8px rgba(0,0,0,0.7);
    transform: translateY(calc(100% - 56px));
    transition: transform .3s cubic-bezier(.2,.9,.3,1);
    max-height: 85vh;
    max-height: 85dvh;
    display: flex;
    flex-direction: column;
  }
  #chat-section .panel::before {
    content: ""; display: block; width: 44px; height: 4px;
    background: rgba(232,180,192,0.4); border-radius: 9999px;
    margin: 0 auto 8px auto;
    flex: 0 0 auto;
  }
  #chat-section.is-open .panel { transform: translateY(0); }
  #chat-section .panel > div:first-of-type,
  #chat-section .panel > h3 { flex: 0 0 auto; }

  .chat-box {
    flex: 1 1 auto;
    min-height: 0;
    height: 0;
    overflow: hidden;
    transition: height .25s ease, padding .25s ease;
    padding: 0 0.25rem;
    margin-bottom: 0;
  }
  #chat-section.is-open .chat-box {
    height: auto;
    min-height: 200px;
    max-height: none;
    overflow-y: auto;
    padding: 0.25rem;
    margin-bottom: 0.5rem;
  }

  #chat-section .panel > div:last-of-type,
  #chat-section .panel > p {
    flex: 0 0 auto;
  }
  #chat-section .panel > p { display: none; }
  #chat-section.is-open .panel > p { display: block; }
  .chat-input-row { gap: 0.4rem; flex-shrink: 0; }
  #chat-input { font-size: 16px; }

  #chat-section.is-open.is-keyboard .panel {
    max-height: 60vh;
    max-height: 60dvh;
  }
  #chat-section.is-open.is-keyboard .chat-box {
    min-height: 80px;
    max-height: none;
  }
  #chat-section.is-keyboard .panel {
    transform: translateY(0);
  }

  .modal { padding: 0.75rem; }
  .task-card, .custom-card, .disclaimer-card {
    max-height: 88vh; overflow-y: auto;
    border-radius: 18px;
    padding: 1.25rem;
  }
  .task-card { max-width: 100%; }
  .custom-card, .disclaimer-card { max-width: 100%; }

  footer .mx-auto { padding-top: 1rem; padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); }
}

@media (min-width: 481px) and (max-width: 768px) {
  .board-grid { gap: 6px; }
  .tile .tile-emoji { font-size: 16px; }
  .tile .tile-type { font-size: 9px; }
}

@media (max-width: 900px) and (orientation: landscape) {
  #chat-section { position: static; pointer-events: auto; }
  #chat-section .panel {
    transform: none;
    border-radius: 18px;
    max-height: 50vh;
  }
  #chat-section .chat-box { height: 200px; }
  #chat-section.is-open .panel { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.05ms !important; }
}
