/* Theme-agnostic layout. All colors/typography/radii come from variables that
   theme-*.css files define on body[data-theme=…]. */

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  transition: background .4s, color .4s;
}

button {
  font-family: inherit;
  font-size: 0.95rem;
  padding: .55em 1.1em;
  border: var(--btn-border);
  border-radius: var(--radius-btn);
  background: var(--btn-bg);
  color: var(--btn-ink);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, background .2s;
}
button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-hover); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.mahj { background: var(--mahj-bg); color: var(--mahj-ink); border-color: var(--mahj-bg); font-weight: 700; }
button.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
input, select {
  font-family: inherit; font-size: 1rem;
  padding: .5em .8em;
  border: var(--input-border);
  border-radius: var(--radius-btn);
  background: var(--panel);
  color: var(--ink);
}

.hidden { display: none !important; }

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .5rem 1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 20;
}
#brand { font-family: var(--font-display); font-size: 1.25rem; font-weight: 700; color: var(--accent-deep); text-decoration: none; }
#phase-banner { flex: 1; text-align: center; font-family: var(--font-display); font-size: 1.05rem; color: var(--ink-soft); }
#topbar-right { display: flex; gap: .5rem; align-items: center; }

/* ---------- lobby ---------- */
#lobby { display: grid; place-items: center; min-height: calc(100vh - 60px); padding: 2rem; }
.lobby-card {
  background: var(--panel);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow);
  padding: 2.5rem 3rem;
  max-width: 430px; width: 100%;
  text-align: center;
}
.lobby-card h1 { font-family: var(--font-display); font-size: 2.2rem; color: var(--accent-deep); margin-bottom: .3rem; }
.tagline { color: var(--ink-soft); margin-bottom: 1.5rem; }
#lobby-join { display: flex; gap: .5rem; margin-bottom: 1.4rem; }
#lobby-join input { flex: 1; }
#save-list {
  display: grid; gap: .6rem;
  margin-bottom: 1.2rem;
  max-height: 280px; overflow-y: auto;
}
.save-card {
  border: 2px solid var(--accent);
  border-radius: var(--radius-tile);
  padding: .7rem .9rem;
  text-align: left;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  display: flex; gap: .8rem; align-items: center; justify-content: space-between;
}
.save-info { font-size: .9rem; line-height: 1.45; }
.save-actions { display: flex; gap: .5rem; flex: 0 0 auto; }

#lobby-seats { list-style: none; text-align: left; margin-bottom: 1.4rem; display: grid; gap: .5rem; }
#lobby-seats li {
  display: flex; justify-content: space-between;
  padding: .6rem .9rem;
  border-radius: var(--radius-btn);
  background: var(--bg);
  border: var(--input-border);
}
#lobby-seats li.you { outline: 2px solid var(--accent); }
#lobby-seats li.open .seat-who { color: var(--ink-faint); font-style: italic; }
.seat-num { font-weight: 600; color: var(--ink-soft); }
.lobby-actions { display: flex; gap: .6rem; justify-content: center; }
.hint, .bar-hint { color: var(--ink-faint); font-size: .88rem; }

/* ---------- table layout ---------- */
#table {
  display: grid;
  grid-template-areas: ". top ." "left center right" "me me me";
  grid-template-columns: minmax(130px, 1fr) minmax(0, 3.2fr) minmax(130px, 1fr);
  grid-template-rows: auto 1fr auto;
  gap: .6rem;
  padding: .8rem;
  min-height: calc(100vh - 56px);
}
#opp-top { grid-area: top; }
#opp-left { grid-area: left; }
#opp-right { grid-area: right; }
#center { grid-area: center; }
#me { grid-area: me; }

.opp { display: flex; flex-direction: column; align-items: center; gap: .4rem; }
.opp-hand { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; max-width: 100%; }
/* Side opponents: a tidy column of miniature tile backs (full tiles, never
   squished), plus the count chip and exposures. */
.opp.side .opp-hand:not(.face-up) {
  display: flex; flex-direction: column; flex-wrap: nowrap; gap: 2px;
}
.opp.side .opp-hand:not(.face-up) .tile.back {
  width: 27px; height: 30px; border-radius: 4px; margin: 0;
}
.opp.side { justify-content: flex-start; padding-top: 1.2rem; gap: .5rem; }
.opp.side .seat-label { flex-direction: column; gap: .3em; }
.opp.side .opp-hand.face-up { display: grid; grid-template-columns: repeat(2, auto); gap: 2px; }

.seat-label {
  font-family: var(--font-display); font-weight: 600; color: var(--ink-soft);
  display: flex; gap: .45em; align-items: center;
  padding: .2em .7em; border-radius: var(--radius-btn);
}
.seat-label.active-turn { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-hover); }
.wind-chip, .east-chip {
  font-size: .72em; padding: .15em .5em; border-radius: 999px;
  background: var(--chip-bg); color: var(--chip-ink); font-weight: 700;
}
.east-chip { background: var(--east-bg); color: var(--east-ink); }
.rack-count {
  display: inline-block;
  font-size: .72em; padding: .15em .55em; border-radius: 999px;
  background: var(--chip-bg); color: var(--chip-ink); font-weight: 700;
}
.rack-count::after { content: ' tiles'; font-weight: 400; }

#center {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .8rem;
  background: var(--felt);
  border-radius: var(--radius-panel);
  box-shadow: var(--felt-shadow);
  padding: 1rem;
  min-height: 260px;
  position: relative;
  overflow: hidden;
}
#center > :not(#felt-fx):not(#wall-ring) { position: relative; z-index: 1; }

/* ---------- the wall, drawn around the felt ---------- */
#wall-ring { position: absolute; inset: 7px; pointer-events: none; z-index: 0; }
.wall-side { position: absolute; display: flex; gap: 2px; justify-content: center; }
.wall-side.top { top: 0; left: 34px; right: 34px; }
.wall-side.bottom { bottom: 0; left: 34px; right: 34px; }
.wall-side.left { left: 0; top: 34px; bottom: 34px; flex-direction: column; }
.wall-side.right { right: 0; top: 34px; bottom: 34px; flex-direction: column; }
.wall-side span {
  flex: 1 1 0;
  max-width: 13px; min-width: 2px;
  height: 8px;
  border-radius: 2px;
  background: var(--tile-back);
  border: 1px solid rgba(0, 0, 0, .28);
  opacity: .85;
}
.wall-side.left span, .wall-side.right span {
  max-width: none; max-height: 13px; min-height: 2px;
  width: 8px; height: auto;
}
.wall-side span.gone { visibility: hidden; }

/* ---------- felt animations (optional, per theme) ---------- */
#felt-fx {
  position: absolute; inset: 0;
  overflow: hidden;
  pointer-events: none;
  border-radius: inherit;
  z-index: 0;
}
#felt-fx .fx { position: absolute; line-height: 1; will-change: transform; }
#felt-fx .fx-sway {
  bottom: -4px;
  transform-origin: 50% 100%;
  animation: fx-sway ease-in-out infinite alternate;
}
@keyframes fx-sway { from { transform: rotate(-9deg); } to { transform: rotate(10deg); } }
#felt-fx .fx-rise { top: 103%; animation: fx-rise linear forwards; }
@keyframes fx-rise { to { top: -10%; opacity: 0; } }
#felt-fx .fx-fall { top: -10%; animation: fx-fall linear forwards; }
@keyframes fx-fall { 60% { opacity: .85; } to { top: 104%; transform: rotate(300deg); opacity: .2; } }
#felt-fx .fx-cross { left: -8%; animation: fx-cross linear forwards; }
@keyframes fx-cross { to { left: 104%; } }
#felt-fx .fx-cross.fx-reverse {
  left: auto; right: -8%;
  transform: scaleX(-1);
  animation-name: fx-cross-rev;
}
@keyframes fx-cross-rev { to { right: 104%; } }
#felt-fx .fx-spin { animation: fx-cross linear forwards, fx-spin 1.2s linear infinite; }
#felt-fx .fx-spin.fx-reverse { animation: fx-cross-rev linear forwards, fx-spin 1.2s linear infinite; }
@keyframes fx-spin { to { rotate: 360deg; } }
#felt-fx .fx-drift { left: -22%; animation: fx-drift linear infinite; }
@keyframes fx-drift { to { left: 108%; } }
#felt-fx .fx-smoke {
  width: 190px; height: 190px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .06), transparent 68%);
  filter: blur(5px);
}
#fx-toggle.fx-off { opacity: .35; }
#wall-count { font-family: var(--font-display); color: var(--felt-ink); font-size: .95rem; }
#discard-pool {
  display: flex; flex-wrap: wrap; gap: 4px; justify-content: center;
  max-width: 560px; min-height: 60px;
}
#center-note { color: var(--felt-ink); font-family: var(--font-display); text-align: center; }
.thinking {
  font-weight: 700;
  padding: .4em 1em;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  animation: thinking-pulse 1.6s ease-in-out infinite;
}
@keyframes thinking-pulse { 50% { opacity: .55; } }
.win-line { font-size: 1.1rem; font-weight: 700; margin-bottom: .5rem; }
.win-tiles { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; }
.win-group { display: inline-flex; gap: 2px; padding: 2px 3px; border-radius: 6px; }
.win-group.was-exposed { background: var(--exposure-bg); }

#me {
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  padding: .5rem .5rem .4rem;
  border-radius: var(--radius-panel);
  transition: box-shadow .3s, background .3s;
}
#me.your-turn {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: 0 0 0 3px var(--accent);
  animation: turn-glow 2s ease-in-out infinite;
}
#phase-banner.your-turn { color: var(--accent-deep); font-weight: 700; }
@keyframes turn-glow {
  50% { box-shadow: 0 0 18px 3px color-mix(in srgb, var(--accent) 65%, transparent); }
}
#rack { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; min-height: 96px; }
#action-bar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; justify-content: center; min-height: 42px; }

.exposures { display: flex; gap: .7rem; flex-wrap: wrap; justify-content: center; }
.exposure {
  display: flex; gap: 2px; padding: 3px 5px;
  background: var(--exposure-bg);
  border-radius: var(--radius-tile);
}

/* ---------- tiles ---------- */
.tile {
  width: 58px; height: 82px;
  border-radius: var(--radius-tile);
  background: var(--tile-bg);
  border: var(--tile-border);
  box-shadow: var(--tile-shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  user-select: none;
  position: relative;
  transition: transform .15s, box-shadow .15s, outline-color .1s;
}
.tile.anim-in { animation: tile-in var(--anim-tile-in) ease-out; }
.tile.small { width: 38px; height: 54px; border-radius: calc(var(--radius-tile) * .7); }
.tile.small .t-sub { display: none; }
.tile.small .t-top { font-size: .62rem; top: 2px; left: 4px; }
.tile.small .t-glyph { font-size: 1.05rem; }
.tile.back { background: var(--tile-back); border: var(--tile-back-border); animation: none; }
.t-top {
  position: absolute; top: 4px; left: 7px;
  font-family: var(--font-tile-num); font-weight: 700; font-size: .95rem;
  color: var(--tile-num);
}
.t-glyph { font-size: 1.7rem; line-height: 1.1; }
.t-glyph.svg-glyph svg { width: 1.5em; height: 1.55em; display: block; }
.t-glyph.text-glyph { white-space: nowrap; line-height: 1; }
.t-sub { font-size: .55rem; letter-spacing: .03em; color: var(--tile-sub); text-transform: uppercase; }

.tile[data-cat="joker"] { background: var(--tile-joker-bg); }
.tile[data-cat="flower"] { background: var(--tile-flower-bg); }

#rack .tile { touch-action: none; cursor: grab; }
.tile.dragging {
  pointer-events: none;
  opacity: .75;
  box-shadow: var(--shadow-hover);
  z-index: 5;
  transition: none; /* transform follows the pointer directly */
}
.tile.drop-before { box-shadow: -4px 0 0 0 var(--accent), var(--tile-shadow); }
.tile.drop-after { box-shadow: 4px 0 0 0 var(--accent), var(--tile-shadow); }
.tile.discardable:hover, .tile.selectable:hover { transform: translateY(-8px); cursor: pointer; box-shadow: var(--shadow-hover); }
.tile.selected { transform: translateY(-12px); outline: 3px solid var(--accent); }
.tile.swappable { cursor: pointer; outline: 2px dashed var(--accent); }
.tile.hot { outline: 3px solid var(--mahj-bg); animation: pulse 1s infinite; }
.tile.received { outline: 3px solid var(--mahj-bg); outline-offset: 2px; }
.tile.received::before {
  content: '✦ new';
  position: absolute;
  top: -15px; left: 50%;
  transform: translateX(-50%);
  font-size: .55rem; font-weight: 700; letter-spacing: .04em;
  color: var(--mahj-bg);
  white-space: nowrap;
}
.tile.received.anim-in { animation: received-pulse 1s ease-in-out 3; }
@keyframes received-pulse { 50% { transform: translateY(-7px); } }
.tile.drawn { outline: 3px solid var(--accent-deep); outline-offset: 2px; }
.tile.drawn::before {
  content: '↓ drawn';
  position: absolute;
  top: -15px; left: 50%;
  transform: translateX(-50%);
  font-size: .55rem; font-weight: 700; letter-spacing: .04em;
  color: var(--accent-deep);
  white-space: nowrap;
}
.tile.flying { animation: fly-out .3s ease-in forwards; }

@keyframes tile-in { from { transform: translateY(var(--anim-tile-in-dy)) scale(.9); opacity: 0; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--mahj-bg) 30%, transparent); } }
@keyframes fly-out { to { transform: translateY(-60px) scale(.7); opacity: 0; } }

/* Tiles committed to a pass: dimmed, labeled, drifting toward their new home. */
.tile.outgoing { opacity: .7; outline: 2px dashed var(--ink-faint); }
.tile.outgoing::before {
  position: absolute; top: -15px; left: 50%; transform: translateX(-50%);
  font-size: .55rem; font-weight: 700; letter-spacing: .04em;
  color: var(--ink-faint); white-space: nowrap;
}
#rack[data-passdir="right"] .tile.outgoing::before { content: 'passing →'; }
#rack[data-passdir="left"] .tile.outgoing::before { content: '← passing'; }
#rack[data-passdir="across"] .tile.outgoing::before { content: '↑ passing'; }
#rack[data-passdir="right"] .tile.outgoing { animation: drift-right 1.5s ease-in-out infinite; }
#rack[data-passdir="left"] .tile.outgoing { animation: drift-left 1.5s ease-in-out infinite; }
#rack[data-passdir="across"] .tile.outgoing { animation: drift-across 1.5s ease-in-out infinite; }
@keyframes drift-right { 50% { transform: translate(9px, -4px); } }
@keyframes drift-left { 50% { transform: translate(-9px, -4px); } }
@keyframes drift-across { 50% { transform: translateY(-9px); } }

/* ---------- card & help panels ---------- */
#card-panel, #help-panel {
  position: fixed; top: 56px; right: 0; bottom: 0;
  width: min(360px, 90vw);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 1rem 1.2rem;
  overflow-y: auto;
  z-index: 30;
}
#card-resize {
  position: absolute; left: 0; top: 0; bottom: 0; width: 8px;
  cursor: ew-resize; touch-action: none;
}
#card-resize:hover { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.panel-head-btns { display: flex; gap: .1rem; }
#card-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 60; }
#card-panel.modal {
  top: 50%; left: 50%; right: auto; bottom: auto;
  transform: translate(-50%, -50%);
  width: min(880px, 94vw) !important;
  height: min(84vh, 900px);
  border-radius: var(--radius-panel);
  z-index: 61;
}
#card-panel.modal #card-resize { display: none; }
#card-panel.modal #card-list { columns: 2 320px; column-gap: 1.6rem; }
#card-panel.modal .card-row, #card-panel.modal #card-list h3,
#card-panel.modal .card-legend { break-inside: avoid; }
#help-body { color: var(--ink); line-height: 1.55; font-size: .95rem; }
.help-event {
  margin-bottom: .8rem; padding: .55rem .8rem;
  border-radius: var(--radius-btn);
  background: var(--chip-bg); color: var(--chip-ink);
  font-size: .9rem;
}
#tutorial-chip {
  font-size: .72rem; font-weight: 700; padding: .2em .7em;
  border-radius: 999px; background: var(--east-bg); color: var(--east-ink);
  letter-spacing: .05em; text-transform: uppercase;
}
#profile-card {
  margin-top: 1rem;
  padding: .8rem 1rem;
  border-radius: var(--radius-tile);
  background: var(--bg);
  border: var(--input-border);
  text-align: left;
  font-size: .92rem;
  line-height: 1.6;
}
#tutorial-row, #pause-row, #card-row {
  display: flex; gap: .5rem; align-items: center; justify-content: center;
  margin-bottom: .8rem; color: var(--ink-soft); font-size: .92rem;
  cursor: pointer;
}
#pause-row select, #help-options select { font-size: .85rem; padding: .25em .5em; }
select.ai-level { font-size: .78rem; padding: .2em .35em; }
.ai-opts { display: flex; gap: .3rem; margin-left: .5rem; flex: 0 0 auto; }
#lobby-seats li { align-items: center; }
.opp-hand.face-up { gap: 2px; }
.opp.side .opp-hand.face-up {
  display: grid; grid-template-columns: repeat(2, auto); gap: 2px;
}
.opp.side .opp-hand.face-up .tile { height: 54px; margin-top: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.panel-head h2 { font-family: var(--font-display); color: var(--accent-deep); }
#card-panel h3 {
  font-family: var(--font-display); font-size: .85rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-faint); margin: 1rem 0 .3rem;
}
/* Suit-relationship colors for card hands (per-theme values). */
.cs-a { color: var(--cs-a); font-weight: 700; }
.cs-b { color: var(--cs-b); font-weight: 700; }
.cs-c { color: var(--cs-c); font-weight: 700; }
.cs-f { color: var(--cs-f); font-weight: 700; }
.cs-n { color: var(--ink); font-weight: 700; }
.card-legend p { font-size: .84rem; color: var(--ink-soft); line-height: 1.5; margin-bottom: .5rem; }
.card-legend .cs-a, .card-legend .cs-b, .card-legend .cs-c { font-weight: 700; }

.card-row, .closest-row {
  display: flex; justify-content: space-between; gap: .8rem;
  padding: .35rem .4rem; border-radius: 6px; font-size: .92rem;
}
.card-row:nth-child(odd) { background: var(--bg); }
.card-row.impossible { opacity: .32; }
.tag-chip {
  border: 1.5px dashed var(--ink-faint);
  background: transparent;
  color: var(--ink-faint);
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 700;
  padding: .05em .55em;
  margin-left: auto;
  cursor: pointer;
  line-height: 1.4;
  white-space: nowrap;
}
.tag-chip:hover { border-color: var(--accent); color: var(--accent-deep); transform: none; box-shadow: none; }
.tag-chip.tagged { border-style: solid; color: #fff; }
.tag-chip.tag-c0 { background: var(--cs-a); border-color: var(--cs-a); }
.tag-chip.tag-c1 { background: var(--cs-b); border-color: var(--cs-b); }
.tag-chip.tag-c2 { background: var(--cs-c); border-color: var(--cs-c); }
.card-row .c-pts { margin-left: .5rem; }
.dim-row {
  display: flex; gap: .45rem; align-items: center;
  font-size: .84rem; color: var(--ink-soft);
  margin-top: .4rem; cursor: pointer;
}
.closest-row { background: var(--bg); margin-bottom: .3rem; border-left: 3px solid var(--accent); }
.c-pts, .c-missing { color: var(--ink-soft); white-space: nowrap; }

/* ---------- tile gallery ---------- */
#gallery { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.gallery-section { margin-bottom: 2rem; }
.gallery-section h2 { font-family: var(--font-display); color: var(--accent-deep); margin-bottom: .2rem; }
.gallery-note { color: var(--ink-soft); font-size: .9rem; margin-bottom: .8rem; max-width: 640px; }
.gallery-row { display: flex; flex-wrap: wrap; gap: .8rem; }
.gallery-cell {
  display: flex; flex-direction: column; align-items: center; gap: .35rem;
  font-size: .78rem; color: var(--ink-soft);
}
.topbar-link { color: var(--ink-soft); text-decoration: none; font-size: .92rem; align-self: center; }
.topbar-link:hover { color: var(--accent-deep); }

/* ---------- toasts / overlay ---------- */
/* Transient game-event alerts: centered under the top bar, hands-off. */
#alerts {
  position: fixed; top: 62px; left: 50%; transform: translateX(-50%);
  display: grid; gap: .35rem; justify-items: center;
  z-index: 45; pointer-events: none;
  max-width: min(92vw, 480px);
}
.event-alert {
  background: var(--panel); color: var(--ink);
  padding: .45rem 1.1rem;
  border-radius: 999px;
  box-shadow: var(--shadow-hover);
  border-left: 4px solid var(--accent);
  font-size: .92rem;
  animation: alert-in .25s ease-out;
  transition: opacity .8s;
  text-align: center;
}
.event-alert.big {
  font-size: 1.15rem; font-weight: 700;
  border-left-color: var(--mahj-bg);
  color: var(--accent-deep);
}
.event-alert.fading { opacity: 0; }
@keyframes alert-in { from { transform: translateY(-10px); opacity: 0; } }

.log-head {
  font-family: var(--font-display); font-size: .85rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-faint); margin: 1.2rem 0 .3rem;
}
#move-log {
  max-height: 40vh; overflow-y: auto;
  font-size: .85rem; color: var(--ink-soft);
  display: grid; gap: .2rem;
}
#move-log .log-row { padding: .2rem .4rem; border-radius: 5px; }
#move-log .log-row:nth-child(odd) { background: var(--bg); }

#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: grid; gap: .4rem; z-index: 50; }
.toast {
  background: var(--panel); color: var(--ink);
  padding: .6rem 1.1rem; border-radius: var(--radius-btn);
  box-shadow: var(--shadow-hover);
  animation: toast-in .25s ease-out;
}
.toast.error { border-left: 4px solid var(--mahj-bg); }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

#overlay { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.petal { position: absolute; top: -30px; animation: petal-fall 5s linear forwards; }
@keyframes petal-fall {
  to { transform: translateY(105vh) rotate(340deg); opacity: .7; }
}

@media (max-width: 900px) and (min-width: 701px) {
  #table { grid-template-columns: minmax(90px, 1fr) minmax(0, 2.6fr) minmax(90px, 1fr); }
  .tile { width: 46px; height: 66px; }
  .t-glyph { font-size: 1.3rem; }
}

/* ---------- phone layout ----------
   Opponents collapse to a compact 3-up strip (name + tile count + exposures),
   the discard pool takes the middle, and your rack + actions stick to the
   bottom. Tile backs are not drawn at all — the rack-count chip stands in. */
@media (max-width: 700px) {
  #topbar { padding: .35rem .6rem; gap: .5rem; }
  #brand { font-size: 1rem; }
  #phase-banner { font-size: .82rem; }
  #topbar-right { gap: .3rem; }
  #topbar-right select { font-size: .8rem; padding: .3em .4em; }

  #table {
    grid-template-areas: "left top right" "center center center" "me me me";
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: .45rem;
    padding: .45rem;
    min-height: 0;
  }

  .opp {
    background: var(--panel);
    border-radius: var(--radius-tile);
    box-shadow: var(--shadow);
    padding: .35rem .3rem;
    gap: .25rem;
    justify-content: flex-start;
  }
  .opp .seat-label { font-size: .72rem; padding: .1em .3em; flex-wrap: wrap; justify-content: center; gap: .25em; }
  .opp .rack-count {
    display: inline-block;
    font-size: .72em; padding: .15em .55em; border-radius: 999px;
    background: var(--chip-bg); color: var(--chip-ink); font-weight: 700;
  }
  .opp .opp-hand:not(.face-up) { display: none; }
  .opp.side .opp-hand.face-up { display: flex; flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .opp .opp-hand.face-up .tile { width: 22px; height: 32px; margin: 0; border-radius: 3px; }
  .opp .opp-hand.face-up .t-glyph { font-size: .7rem; }
  .opp .opp-hand.face-up .t-top { font-size: .45rem; top: 1px; left: 2px; }
  .opp .exposures { gap: .25rem; }
  .opp .exposure .tile { width: 22px; height: 32px; }
  .opp .exposure .t-glyph { font-size: .7rem; }
  .opp .exposure .t-top { font-size: .45rem; top: 1px; left: 2px; }

  #center { min-height: 140px; padding: .6rem .4rem; gap: .45rem; }
  #wall-ring { display: none; } /* too tight on phones */
  #wall-count { font-size: .8rem; }
  #discard-pool { max-width: 100%; gap: 3px; }
  #discard-pool .tile { width: 30px; height: 42px; }
  #discard-pool .t-glyph { font-size: .85rem; }
  #discard-pool .t-top { font-size: .5rem; top: 1px; left: 3px; }
  #center-note { font-size: .85rem; }
  .win-tiles .tile { width: 30px; height: 42px; }

  #me {
    position: sticky; bottom: 0;
    background: var(--bg);
    padding: .4rem 0 .5rem;
    gap: .4rem;
    box-shadow: 0 -6px 12px -8px rgba(0, 0, 0, .35);
  }
  #rack { gap: 3px; min-height: 66px; }
  #rack .tile { width: 44px; height: 62px; }
  #rack .t-glyph { font-size: 1.15rem; }
  #rack .t-sub { display: none; }
  #rack .t-top { font-size: .7rem; top: 2px; left: 4px; }
  #my-exposures .tile { width: 30px; height: 42px; }
  #action-bar { gap: .4rem; min-height: 36px; }
  #action-bar button { font-size: .82rem; padding: .45em .8em; }
  .bar-hint { font-size: .75rem; flex-basis: 100%; text-align: center; }
  #my-name { font-size: .8rem; }

  #card-panel, #help-panel { top: 48px; width: 100vw !important; }
  #card-resize, #card-expand { display: none; }
  #card-panel.modal { top: 48px; left: 0; transform: none; height: auto; bottom: 0; border-radius: 0; }
  #card-panel.modal #card-list { columns: 1; }
  .lobby-card { padding: 1.6rem 1.2rem; }
  #lobby { padding: 1rem; }
}
#lobby-join button { white-space: nowrap; }
