/* Elderly-friendly mahjong — landscape tablet, high contrast, large touch targets */

/* Author .btn { display } would otherwise override UA [hidden] */
[hidden] {
  display: none !important;
}


:root {
  --felt: #0d5c3d;
  --felt-dark: #084029;
  --felt-light: #127a52;
  --cream: #f5ecd7;
  --cream-edge: #d4c4a0;
  --tile-face-top: #fffef8;
  --tile-back-a: #1a4a8a;
  --tile-back-b: #0d2a55;
  --tile-back-border: #0a1e3d;
  --tile-back-line: #3a7ad0;
  --ink: #1a1a1a;
  --red: #c41e3a;
  --green-tile: #1a7a3a;
  --blue-tile: #1a4a8a;
  --gold: #e8c547;
  --btn: #2a8f5a;
  --danger: #b83232;
  --panel: rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --touch: 56px;
  font-size: 18px;
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  background: var(--felt-dark);
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

#app { height: 100%; width: 100%; }

.screen {
  display: none;
  height: 100%;
  width: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; flex-direction: column; }

/* ----- Lobby / Waiting ----- */
.app-header {
  text-align: center;
  padding: 1.2rem 1rem 0.5rem;
}
.app-header h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--gold);
  text-shadow: 0 2px 0 #0006;
}
.app-header.compact h1 { font-size: 1.8rem; }
.subtitle { font-size: 1.1rem; opacity: 0.85; margin-top: 0.3rem; }

.card {
  margin: 0.8rem auto 1.5rem;
  padding: 1.4rem 1.6rem;
  max-width: 560px;
  width: calc(100% - 2rem);
  background: var(--panel);
  border: 2px solid #ffffff22;
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
}

.field-label {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  color: #ffe9a8;
}

.big-input {
  width: 100%;
  height: 64px;
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  border-radius: 12px;
  border: 3px solid #fff8;
  background: #fff;
  color: var(--ink);
  margin-bottom: 1rem;
  outline: none;
}
.big-input:focus { border-color: var(--gold); }
.code-input {
  letter-spacing: 0.4em;
  font-size: 2rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 0.75rem 1.5rem;
  font-size: 1.35rem;
  font-weight: 800;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  width: 100%;
  margin-bottom: 0.75rem;
  letter-spacing: 0.08em;
  box-shadow: 0 4px 0 #0005;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #0005; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-xl { min-height: 68px; font-size: 1.55rem; }
.btn-primary { background: linear-gradient(#3ecf7a, #1f9a52); color: #fff; }
.btn-secondary { background: linear-gradient(#4a9fe8, #2468b8); color: #fff; }
.btn-ghost { background: transparent; border: 2px solid #fff6; color: #fff; box-shadow: none; width: auto; min-width: 140px; margin: 0.5rem auto; display: flex; }
.btn-draw {
  width: auto;
  min-width: 120px;
  background: var(--gold);
  color: #222;
  margin: 0;
  min-height: 48px;
  font-size: 1.2rem;
}

.divider {
  text-align: center;
  margin: 1rem 0;
  opacity: 0.7;
  font-size: 1rem;
}
.divider span {
  background: transparent;
  padding: 0 0.5rem;
}

.error-msg {
  color: #ffb4b4;
  background: #8008;
  padding: 0.6rem;
  border-radius: 8px;
  text-align: center;
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}
.hint {
  font-size: 0.95rem;
  opacity: 0.75;
  text-align: center;
  line-height: 1.45;
  margin-top: 0.4rem;
}

.room-label { text-align: center; font-size: 1.2rem; opacity: 0.8; }
.room-code-huge {
  text-align: center;
  font-size: 4.2rem;
  font-weight: 900;
  letter-spacing: 0.35em;
  color: var(--gold);
  line-height: 1.1;
  padding-left: 0.35em;
  text-shadow: 0 3px 0 #0005;
}

.seat-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  margin: 0.55rem 0 0.7rem;
  width: 100%;
}
.seat-slot {
  background: #0005;
  border: 2px solid #fff3;
  border-radius: 10px;
  padding: 0.4rem 0.3rem;
  text-align: center;
  min-height: 0;
  min-width: 0;
}
.seat-slot.filled { border-color: #5adf8a; background: #0a503088; }
.seat-slot .wind { font-size: 1.05rem; color: var(--gold); font-weight: 800; line-height: 1.15; }
.seat-slot .name {
  font-size: 0.95rem;
  font-weight: 700;
  margin-top: 0.1rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.seat-slot .empty { opacity: 0.5; font-size: 0.95rem; }
.seat-slot.you { box-shadow: 0 0 0 3px var(--gold); }

.status-line {
  text-align: center;
  font-size: 1.15rem;
  margin-bottom: 0.8rem;
}

/* ----- Table ----- */
.table-screen {
  position: relative;
  background: radial-gradient(ellipse at center, var(--felt-light) 0%, var(--felt) 45%, var(--felt-dark) 100%);
}

.table-topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.45rem 0.6rem;
  background: #0006;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  z-index: 5;
}
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: #0007;
  border: 1px solid #fff3;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
}

/* Connection LED (replaces 已連線 text pill) */
.conn-dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #6b7280;
  box-shadow: 0 0 0 2px #0006, 0 0 6px #0008;
}
.conn-dot.is-on {
  background: #22c55e;
  box-shadow: 0 0 0 2px #14532d88, 0 0 10px #22c55ecc;
}
.conn-dot.is-off {
  background: #ef4444;
  box-shadow: 0 0 0 2px #7f1d1d88, 0 0 10px #ef4444aa;
}

.pill-turn {
  background: #c41e3acc;
  border-color: #ff8;
  font-size: 1.15rem;
  min-height: 42px;
  padding: 0.3rem 1rem;
}

.table-felt {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0.3rem 0.4rem 0.4rem;
  gap: 0.25rem;
}

.opp-top {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
}
.opp-name {
  font-size: 0.95rem;
  font-weight: 700;
  background: #0005;
  padding: 0.15rem 0.6rem;
  border-radius: 8px;
}

.table-mid {
  flex: 1;
  display: flex;
  min-height: 0;
  gap: 0.3rem;
}
.opp-left, .opp-right {
  position: relative;
  width: 56px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  overflow: visible;
}
.opp-left .opp-name, .opp-right .opp-name {
  writing-mode: horizontal-tb;
  font-size: 0.85rem;
  max-width: 92px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  line-height: 1.2;
  text-align: center;
}

.center-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  position: relative;
}

.discard-pool {
  display: grid;
  grid-template-columns: repeat(16, auto);
  gap: 4px;
  justify-content: center;
  align-content: start;
  justify-items: center;
  max-width: 100%;
  max-height: calc(100% - 4.5rem);
  overflow: auto;
  padding: 0.3rem;
  position: relative;
  z-index: 1;
}

/* 場風：棄牌區底部超大字，長者一眼睇到 */
.round-wind-mark {
  flex-shrink: 0;
  margin-top: 0.15rem;
  font-size: clamp(3.2rem, 9vh, 5.5rem);
  font-weight: 900;
  line-height: 1;
  color: #f5d76e;
  text-shadow:
    0 0 12px #000a,
    0 3px 0 #0008,
    0 0 2px #000;
  letter-spacing: 0.05em;
  user-select: none;
  pointer-events: none;
  opacity: 0.95;
}
.round-wind-mark::after {
  content: '風';
  font-size: 0.38em;
  font-weight: 800;
  margin-left: 0.12em;
  vertical-align: middle;
  opacity: 0.85;
}

.claim-banner, .win-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #000c;
  border: 3px solid var(--gold);
  border-radius: 16px;
  padding: 0.8rem 1.4rem;
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  z-index: 10;
  white-space: nowrap;
}
.win-banner {
  border-color: #ff6;
  color: var(--gold);
  font-size: 1.8rem;
  padding: 1rem 1.8rem;
}

.self-area {
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding-bottom: 0.2rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.self-melds, .opp-melds {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  min-height: 0;
}
.meld-group {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: #0004;
  border-radius: 6px;
}

/* Side seats (南／北 when self is 東): melds stack like their vertical hands */
.opp-left .opp-melds,
.opp-right .opp-melds {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  max-height: 28vh;
  overflow: hidden;
}
.opp-left .meld-group,
.opp-right .meld-group {
  flex-direction: column;
  gap: 1px;
}
/* Same footprint as vertical hand backs */
.opp-left .meld-group .tile.tiny,
.opp-right .meld-group .tile.tiny,
.opp-left .opp-flowers .tile.tiny,
.opp-right .opp-flowers .tile.tiny {
  width: 36px;
  height: 26px;
  padding: 1px;
}
.opp-left .meld-group .tile,
.opp-right .meld-group .tile,
.opp-left .opp-flowers .tile,
.opp-right .opp-flowers .tile {
  position: relative;
  overflow: hidden;
}
.opp-left .meld-group .tile .tile-img,
.opp-left .opp-flowers .tile .tile-img {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 36px;
  max-width: none;
  transform: translate(-50%, -50%) rotate(-90deg);
}
.opp-right .meld-group .tile .tile-img,
.opp-right .opp-flowers .tile .tile-img {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 36px;
  max-width: none;
  transform: translate(-50%, -50%) rotate(90deg);
}
.opp-left .opp-flowers,
.opp-right .opp-flowers {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
  gap: 2px;
  max-height: 12vh;
  overflow: hidden;
}


/* Exposed flower tiles (春夏秋冬／梅蘭菊竹) */
.flower-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: center;
  min-height: 0;
  margin: 2px 0;
}
.flower-row .tile {
  opacity: 0.95;
  box-shadow: 0 0 0 2px #e8c54788;
}
.tile.flower {
  /* SVG glyph flowers */
}

.action-bar {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
  padding: 0.15rem 0.3rem;
}
.btn-action {
  min-width: 72px;
  min-height: 56px;
  padding: 0.4rem 0.9rem;
  font-size: 1.45rem;
  font-weight: 900;
  border-radius: 12px;
  border: 3px solid #fff8;
  background: #2563a8;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 0 #0006;
}
.btn-action:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-action:not(:disabled):active { transform: translateY(2px); }
.btn-hu { background: linear-gradient(#e04545, #a01818); border-color: #ffb; }
.btn-pass { background: #555; }
.btn-action.enabled-pulse:not(:disabled) {
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  50% { box-shadow: 0 0 0 4px #ffc85a88; }
}

.self-hand {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  justify-content: center;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  width: 100%;
  min-width: 0;
  padding: 0.25rem 0.4rem 0.4rem;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  scrollbar-width: thin;
}

/* manipulation (not none): browser can pan-scroll the hand; JS preventDefault only after swipe/long-press-reorder */
.self-hand .tile.selectable,
.self-hand .tile.hand-movable {
  touch-action: manipulation;
}
.self-hand .tile.hand-dragging,
.self-hand .tile.hand-reorder-armed {
  touch-action: none;
}

.self-footer {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.05rem;
  font-weight: 700;
}
.wind-badge {
  background: var(--gold);
  color: #222;
  padding: 0.15rem 0.55rem;
  border-radius: 8px;
  font-weight: 900;
}

/* ----- Tiles (real face SVG) ----- */
.tile {
  width: 42px;
  height: 58px;
  border-radius: 6px;
  background: linear-gradient(180deg, var(--tile-face-top, #fffef8) 0%, var(--cream) 100%);
  border: 2px solid var(--cream-edge);
  box-shadow: 0 2px 0 #0005, inset 0 1px 0 #fff;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: var(--ink);
  position: relative;
  flex-shrink: 0;
  line-height: 1;
  padding: 2px;
  overflow: hidden;
}
.tile .tile-face {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

/* ----- Tile face images (hongkong / riichi sets) ----- */
.tile.has-img {
  padding: 2px;
}
.tile .tile-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.tile.tiny .tile-img,
.tile.discard .tile-img {
  /* keep contain inside smaller frames */
}

/* Tile set chooser (Settings) */
.tile-set-choices {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0.6rem 0 1rem;
}
.tile-set-choice {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 3px solid #ffffff55;
  background: #0004;
  color: #fff;
  cursor: pointer;
  text-align: left;
  font-size: 1.25rem;
  font-weight: 800;
  min-height: 72px;
}
.tile-set-choice:hover,
.tile-set-choice:focus {
  outline: 3px solid var(--gold);
  border-color: var(--gold);
}
.tile-set-choice.selected {
  border-color: #ffd76a;
  box-shadow: 0 0 0 3px #ffd76a88, inset 0 0 0 1px #fff6;
  background: #0006;
}
.tile-set-choice .tile-set-name {
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}
.tile-set-preview-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.tile-set-preview-row .tile {
  pointer-events: none;
}

.tile .glyph {
  font-size: 1.35rem;
}

.tile.selectable { cursor: pointer; touch-action: none; }
.tile.hand-movable { cursor: grab; touch-action: none; }
.tile.hand-dragging {
  opacity: 0.9;
  transform: translateY(-10px) scale(1.06);
  box-shadow: 0 10px 18px #0009;
  z-index: 4;
}
.tile.swipe-lift {
  transform: translateY(-18px) scale(1.04);
  box-shadow: 0 8px 16px #0008;
  z-index: 3;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.tile.selectable:hover, .tile.selectable:focus {
  outline: 3px solid var(--gold);
  transform: translateY(-6px);
}
.tile.selected {
  outline: 3px solid #ff6;
  transform: translateY(-10px);
  box-shadow: 0 6px 8px #0006;
}

.tile.back {
  background: linear-gradient(145deg, var(--tile-back-a), var(--tile-back-b));
  border-color: var(--tile-back-border);
  padding: 0;
}
.tile.back .tile-face { display: none; }
.tile.back::after {
  content: '';
  width: 70%;
  height: 70%;
  border: 2px solid var(--tile-back-line);
  border-radius: 4px;
  background: repeating-linear-gradient(
    45deg,
    color-mix(in srgb, var(--tile-back-line) 20%, transparent),
    color-mix(in srgb, var(--tile-back-line) 20%, transparent) 4px,
    transparent 4px,
    transparent 8px
  );
}

.tile.tiny {
  width: 28px;
  height: 38px;
  border-width: 1px;
  padding: 1px;
}

.tile.discard {
  width: 46px;
  height: 64px;
  padding: 2px;
  border-radius: 5px;
}
@media (max-width: 900px) {
  .tile.discard {
    width: 40px;
    height: 56px;
  }
}

.opp-hand.backs {
  display: flex;
  gap: 0;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 90vw;
}
.opp-hand.backs .tile {
  margin: 0;
}
.opp-hand.backs .tile.back {
  width: 18px;
  height: 26px;
}
.opp-hand.vertical {
  flex-direction: column;
  max-height: 42vh;
  overflow: hidden;
}
.opp-hand.vertical .tile.back {
  width: 26px;
  height: 18px;
}

.self-hand .tile {
  width: 48px;
  height: 66px;
}

/* Gap between 13-tile hand and just-drawn tile */
.hand-gap {
  flex-shrink: 0;
  width: 16px;
  min-width: 16px;
  height: 1px;
  align-self: center;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #000e;
  color: #fff;
  padding: 0.75rem 1.4rem;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 700;
  z-index: 100;
  border: 2px solid var(--gold);
  max-width: 90vw;
  text-align: center;
}

/* Landscape phone / small tablet tweaks */
@media (max-height: 500px) {
  .app-header h1 { font-size: 1.6rem; }
  .room-code-huge { font-size: 3rem; }
  .self-hand .tile { width: 40px; height: 56px; }
  .hand-gap { width: 12px; min-width: 12px; }
  .btn-action { min-height: 48px; font-size: 1.25rem; min-width: 60px; }
  .card { padding: 0.8rem 1rem; }
}

@media (min-width: 900px) {
  .self-hand .tile { width: 54px; height: 74px; }
  .hand-gap { width: 20px; min-width: 20px; }
  .opp-left, .opp-right { width: 90px; }
}

/* Portrait rotate hint moved to .phone-rotate-hint (soft, phone-only) */


/* ----- Settings ----- */
.settings-gear {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  border: 2px solid #fff6;
  background: #0006;
  color: #fff;
  font-size: 1.6rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 #0005;
  z-index: 8;
}
.settings-gear:active { transform: translateY(2px); }
.table-topbar .settings-gear {
  position: static;
  width: 44px;
  height: 44px;
  font-size: 1.35rem;
  margin-left: 0.25rem;
  flex-shrink: 0;
}

.settings-card { max-width: 640px; }
.settings-section { margin: 1.2rem 0 0.6rem; }
.settings-section h2 {
  font-size: 1.35rem;
  color: #ffe9a8;
  margin-bottom: 0.7rem;
  font-weight: 800;
}

.felt-swatches {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.felt-swatch {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  padding: 0.55rem;
  border-radius: 14px;
  border: 3px solid #fff3;
  background: #0005;
  cursor: pointer;
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  min-height: 88px;
}
.felt-swatch .swatch-preview {
  height: 44px;
  border-radius: 10px;
  border: 2px solid #fff4;
}
.felt-swatch.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px #e8c54766;
}
.felt-swatch .swatch-name { text-align: center; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: #0005;
  border: 2px solid #fff3;
  border-radius: 14px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.75rem;
}
.toggle-row .toggle-label {
  font-size: 1.25rem;
  font-weight: 800;
}
.toggle-btn {
  min-width: 100px;
  min-height: 52px;
  border-radius: 12px;
  border: 3px solid #fff6;
  font-size: 1.2rem;
  font-weight: 900;
  cursor: pointer;
  background: #2a8f5a;
  color: #fff;
}
.toggle-btn.off {
  background: #555;
}

/* Felt color themes applied on .table-screen / :root */
.table-screen,
body.felt-applied {
  background: radial-gradient(ellipse at center, var(--felt-light) 0%, var(--felt) 45%, var(--felt-dark) 100%);
}

/* ----- Avatars ----- */
.avatar-section { margin: 0.6rem 0 1rem; }
.avatar-current-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 0.6rem;
}
.avatar-preview {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 4px solid var(--gold);
  background: #fff;
  object-fit: cover;
  box-shadow: 0 3px 0 #0005;
}
.avatar-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.avatar-preset {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid #fff4;
  background: #0004;
  padding: 2px;
  cursor: pointer;
  overflow: hidden;
}
.avatar-preset img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.avatar-preset.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px #e8c54766;
}
.avatar-upload-btn {
  display: flex;
  width: 100%;
  margin-bottom: 0.5rem;
}

.seat-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}
.seat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #fff6;
  object-fit: cover;
  background: #fff;
  flex-shrink: 0;
}
.seat-slot.you .seat-avatar { border-color: var(--gold); }

.opp-name {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
}
.opp-avatar, .self-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff5;
  object-fit: cover;
  background: #fff;
  flex-shrink: 0;
}
.self-footer .self-avatar {
  width: 36px;
  height: 36px;
  border-color: var(--gold);
}

/* Deal animation overlay hint */
.deal-banner {
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  background: #000b;
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 0.45rem 1.1rem;
  font-size: 1.25rem;
  font-weight: 800;
  z-index: 12;
  pointer-events: none;
}


/* Seat chat bubble (above hand / seat) — one per seat, independent timers */
.seat-chat-bubble {
  position: absolute;
  z-index: 8;
  max-width: min(220px, 70vw);
  padding: 0.45rem 0.75rem;
  border-radius: 14px;
  background: #fffef5;
  color: #1a1a1a;
  border: 2px solid #d4a017;
  box-shadow: 0 4px 14px #0007;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.seat-chat-bubble.is-show {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.seat-chat-bubble[hidden] { display: none !important; }
#seat-chat-self {
  bottom: calc(100% - 0.2rem);
  left: 50%;
  transform: translate(-50%, 6px) scale(0.96);
}
#seat-chat-self.is-show {
  transform: translate(-50%, 0) scale(1);
}
#seat-chat-top {
  top: 100%;
  left: 50%;
  margin-top: 0.25rem;
  transform: translate(-50%, -4px) scale(0.96);
}
#seat-chat-top.is-show {
  transform: translate(-50%, 0) scale(1);
}
#seat-chat-left {
  left: calc(100% + 4px);
  top: 40%;
  transform: translateY(-50%) scale(0.96);
  writing-mode: horizontal-tb;
}
#seat-chat-left.is-show {
  transform: translateY(-50%) scale(1);
}
#seat-chat-right {
  right: calc(100% + 4px);
  top: 40%;
  transform: translateY(-50%) scale(0.96);
}
#seat-chat-right.is-show {
  transform: translateY(-50%) scale(1);
}

/* Preset chat popup (replaces drawer + free text) */
.chat-popup {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0.6rem;
  pointer-events: none;
}
.chat-popup[hidden] { display: none !important; }
.chat-popup-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: #0007;
  pointer-events: auto;
  cursor: pointer;
}
.chat-popup-card {
  position: relative;
  z-index: 1;
  width: min(520px, 96vw);
  max-height: min(70vh, 520px);
  overflow: auto;
  background: #1a2e24;
  border: 2px solid #f0d78c;
  border-radius: 18px;
  box-shadow: 0 12px 40px #000a;
  padding: 0.7rem 0.8rem 0.9rem;
  pointer-events: auto;
}
.chat-popup-hint {
  margin: 0 0 0.55rem;
  font-size: 0.95rem;
  color: #c8e6d0;
  font-weight: 600;
}

/* ----- Host chat controls ----- */
.host-chat-controls {
  margin: 0.8rem 0;
  padding: 0.6rem;
  background: #0004;
  border-radius: 12px;
  border: 1px solid #fff2;
}
.host-chat-inline {
  margin-top: 0.4rem;
}
.host-chat-inline .toggle-row {
  padding: 0.45rem 0.6rem;
  min-height: auto;
}
.host-chat-inline .toggle-btn {
  min-width: 64px;
  min-height: 40px;
  font-size: 1rem;
}

/* ----- Chat panel ----- */
/* old chat drawer styles removed */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 800;
  color: #ffe9a8;
  margin-bottom: 0.35rem;
}
.chat-close {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid #fff4;
  background: #0005;
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
}
.chat-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}
.chat-preset-btn {
  min-height: 48px;
  padding: 0.4rem 0.85rem;
  border-radius: 12px;
  border: 2px solid #f0d78c88;
  background: #0d3d28;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
}
.chat-preset-btn:active { transform: scale(0.97); background: #145c3a; }
.chat-preset-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-voice-mute {
  background: #3a7ad0 !important;
  color: #fff !important;
}
.btn-voice-mute.is-muted {
  background: #777 !important;
}

.table-screen { position: relative; }

.think-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.5rem;
}
.think-btn {
  min-height: 52px;
  min-width: 72px;
  padding: 0.4rem 0.8rem;
  font-size: 1.15rem;
  font-weight: 900;
  border-radius: 12px;
  border: 3px solid #fff5;
  background: #234;
  color: #fff;
  cursor: pointer;
}
.think-btn.selected {
  border-color: var(--gold);
  background: #1f6b45;
  box-shadow: 0 0 0 3px #e8c54755;
}
.room-settings-summary {
  font-size: 1.05rem !important;
  opacity: 1 !important;
  background: #0005;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  margin: 0.5rem 0;
}
.pill-think {
  background: #a05a10cc;
  border-color: #ffc85a;
  font-size: 1.1rem;
}

.spectator-box {
  margin: 0.8rem 0;
  padding: 0.6rem;
  background: #0004;
  border-radius: 12px;
  border: 1px solid #fff2;
}
.spectator-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-height: 28px;
}
.spectator-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: #0006;
  border: 1px solid #fff3;
  border-radius: 999px;
  padding: 0.2rem 0.55rem 0.2rem 0.2rem;
  font-weight: 700;
  font-size: 0.95rem;
}
.spectator-chip img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}
.pill-spectate {
  background: #4a3a8acc;
  border-color: #cbb6ff;
}
#btn-spectate {
  border: 2px solid #fff6;
  margin-top: 0.25rem;
}


.tile-style-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding: 0.6rem;
  background: #0004;
  border-radius: 12px;
  margin-bottom: 0.7rem;
  min-height: 70px;
}
.settings-hint-local {
  font-size: 0.95rem;
  opacity: 0.8;
  margin: -0.3rem 0 0.6rem;
  text-align: center;
}


/* Latest discarded tile — chronological river highlight */
.tile.latest-discard {
  outline: 3px solid var(--gold, #f0c14a);
  transform: translateY(-4px);
  z-index: 2;
}


/* —— Clear turn indicator (elderly) —— */
.pill-turn {
  max-width: min(70vw, 28rem);
  white-space: normal;
  text-align: center;
  line-height: 1.25;
}
.pill-turn.is-you {
  background: #c41e3acc;
  color: #fff;
  border-color: #ffec8b;
  box-shadow: none;
  animation: none;
  font-size: 1.35rem;
  font-weight: 900;
}
.pill-turn.is-other {
  background: #1a4d8ccc;
  border-color: #9cf;
  font-size: 1.2rem;
}
.pill-turn.is-claim {
  background: #7a1f9bcc;
  border-color: #f8f;
  animation: turn-pulse 1.4s ease-in-out infinite;
}

@keyframes turn-pulse {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.04); filter: brightness(1.12); }
}

.opp {
  position: relative;
  border-radius: 12px;
  transition: box-shadow 0.2s, opacity 0.2s, background 0.2s;
  padding: 0.15rem;
}
.opp.seat-dim { opacity: 0.55; }
.opp.seat-active {
  opacity: 1;
  background: #ffd54a33;
  box-shadow: 0 0 0 3px #ffd54a, 0 0 20px #ffc107aa;
  animation: seat-glow 1.3s ease-in-out infinite;
}
.opp-name.active-turn {
  outline: none;
  background: #ffd54a;
  color: #1a1000;
  font-weight: 900;
  font-size: 1.05rem;
  padding: 0.25rem 0.7rem;
  box-shadow: 0 0 10px #ffc107;
}

@keyframes seat-glow {
  0%, 100% { box-shadow: 0 0 0 3px #ffd54a, 0 0 14px #ffc10788; }
  50% { box-shadow: 0 0 0 4px #ffe082, 0 0 26px #ffec8bcc; }
}

.self-area {
  position: relative;
  border-radius: 16px;
  padding: 0.25rem 0.35rem;
}
/* No gold frame on own seat when your turn — text badge only */

.self-turn-badge {
  position: absolute;
  top: -0.15rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  background: transparent;
  color: #ffe082;
  font-size: 1.55rem;
  font-weight: 900;
  padding: 0.1rem 0.4rem;
  border: none;
  border-radius: 0;
  box-shadow: none;
  text-shadow: 0 2px 6px #000c, 0 0 10px #0008;
  animation: none;
  pointer-events: none;
  white-space: nowrap;
}

.turn-callout {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  background: #0d2a5ecc;
  border: 3px solid #ffd54a;
  border-radius: 14px;
  padding: 0.55rem 1.2rem;
  font-size: 1.35rem;
  font-weight: 900;
  color: #fff;
  text-align: center;
  max-width: 90%;
  box-shadow: 0 6px 20px #0009;
  pointer-events: none;
}
.turn-callout .wind-tag {
  display: inline-block;
  background: #ffd54a;
  color: #1a1000;
  border-radius: 8px;
  padding: 0.1rem 0.45rem;
  margin-right: 0.35rem;
  font-weight: 900;
}

.self-footer .self-name-label.self-turn-name {
  background: #ffd54a;
  color: #1a1000;
  font-weight: 900;
  padding: 0.15rem 0.55rem;
  border-radius: 8px;
}
.wind-badge.self-turn-wind {
  background: #ffd54a;
  color: #1a1000;
  box-shadow: 0 0 10px #ffc107;
}

/* Waiting room: use landscape width, cut vertical scroll */
#screen-waiting.app-header,
#screen-waiting .wait-header {
  padding: 0.45rem 0.8rem 0.2rem;
}
#screen-waiting .wait-header h1 {
  font-size: 1.45rem;
  letter-spacing: 0.12em;
}
.waiting-card {
  max-width: min(1100px, calc(100% - 1.2rem));
  width: calc(100% - 1.2rem);
  margin: 0.35rem auto 0.6rem;
  padding: 0.75rem 1rem 0.85rem;
}
.waiting-card .wait-top {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 0.75rem 1rem;
  align-items: start;
  margin-bottom: 0.55rem;
}
.waiting-card .wait-room-info {
  text-align: center;
  padding: 0.35rem 0.4rem;
  background: #0004;
  border-radius: 12px;
  border: 1px solid #fff2;
}
.waiting-card .room-code-huge {
  font-size: clamp(2rem, 4.5vw, 2.8rem);
  margin: 0.1rem 0 0.15rem;
  letter-spacing: 0.28em;
}
.waiting-card .room-label { margin-bottom: 0; font-size: 1rem; }
.waiting-card .wait-code-hint { margin: 0.1rem 0 0.35rem; font-size: 0.95rem; }
.waiting-card .status-line {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
}
.waiting-card .seat-list {
  margin: 0 0 0.4rem;
  gap: 0.4rem;
}
.waiting-card .spectator-box {
  margin: 0;
  padding: 0.35rem 0.45rem;
}
.waiting-card .spectator-box .field-label {
  margin-bottom: 0.25rem;
  font-size: 1rem;
}
.waiting-card .host-settings-wide {
  margin: 0.35rem 0 0.45rem;
  padding: 0.55rem 0.65rem;
}
.waiting-card .host-settings-title {
  margin-bottom: 0.4rem;
  font-size: 1.05rem;
}
.waiting-card .host-settings-grid {
  display: grid;
  grid-template-columns: minmax(200px, 0.9fr) minmax(280px, 1.4fr);
  gap: 0.55rem 1rem;
  align-items: start;
}
.waiting-card .host-toggles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.55rem;
}
.waiting-card .host-toggles .toggle-row {
  margin: 0;
  padding: 0.25rem 0.35rem;
  min-height: 48px;
}
.waiting-card .host-presets .field-label {
  margin: 0.35rem 0 0.25rem;
  font-size: 1rem;
}
.waiting-card .host-presets .field-label:first-child { margin-top: 0; }
.waiting-card .think-presets {
  gap: 0.3rem;
  margin-bottom: 0.15rem;
}
.waiting-card .think-btn {
  min-height: 44px;
  padding: 0.25rem 0.55rem;
  font-size: 0.95rem;
}
.waiting-card .host-settings-foot {
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
  line-height: 1.35;
}
.waiting-card .wait-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  justify-content: center;
  margin-top: 0.35rem;
}
.waiting-card .wait-actions .btn-xl {
  margin: 0;
  min-width: 10rem;
  flex: 1 1 12rem;
  max-width: 20rem;
}
.waiting-card .wait-actions .btn-ghost {
  margin: 0;
  flex: 0 1 auto;
}
.waiting-card #start-hint {
  margin: 0.35rem 0 0;
  text-align: center;
}
.waiting-card .room-settings-summary {
  margin: 0.25rem 0;
  font-size: 0.95rem;
  line-height: 1.35;
}

@media (max-width: 820px) {
  .waiting-card .wait-top {
    grid-template-columns: 1fr;
  }
  .waiting-card .host-settings-grid {
    grid-template-columns: 1fr;
  }
  .waiting-card .host-toggles {
    grid-template-columns: 1fr 1fr;
  }
}

/* Discard tile tap info (elderly) */
.tile.discard.tappable {
  cursor: pointer;
  touch-action: manipulation;
}
.tile.discard.tappable:active {
  transform: translateY(-2px) scale(1.06);
}
.tile.discard.info-selected {
  outline: 3px solid #7ec8ff;
  outline-offset: 1px;
  z-index: 3;
}
.discard-info {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000a;
  padding: 1rem;
}
.discard-info[hidden] { display: none !important; }
.discard-info-card {
  background: #0a3d2acc;
  border: 3px solid var(--gold, #e8c547);
  border-radius: 18px;
  padding: 1rem 1.25rem 1.1rem;
  max-width: min(420px, 94vw);
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px #000a;
}
.discard-info-tile {
  display: flex;
  justify-content: center;
  margin-bottom: 0.55rem;
}
.discard-info-tile .tile {
  width: 72px;
  height: 100px;
}
.discard-info-title {
  font-size: 1.85rem;
  font-weight: 900;
  color: var(--gold, #e8c547);
  margin: 0 0 0.55rem;
}
.discard-info-body {
  text-align: left;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.55;
  margin: 0 0 0.9rem;
}
.discard-info-body p {
  margin: 0.35rem 0;
  padding: 0.35rem 0.55rem;
  background: #0005;
  border-radius: 10px;
}
.discard-info-close {
  width: 100%;
  margin: 0;
}

/* Claimed discard still in river — framed */
.tile.discard.discard-claimed {
  position: relative;
  outline: 3px solid #ff6b6b;
  outline-offset: 1px;
  box-shadow: 0 0 0 2px #0008;
  opacity: 0.92;
}
.tile.discard .discard-claimed-tag {
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translateX(-50%);
  background: #c41e3a;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 900;
  line-height: 1;
  padding: 0.12rem 0.25rem;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
}

/* Multi-hand match: host schedule + table status */
.match-mode-presets .match-mode-btn,
.waiting-card .match-mode-presets .match-mode-btn {
  min-width: 5.5rem;
  min-height: 52px;
  font-size: 1.15rem;
  font-weight: 800;
}
.match-count-presets .match-count-btn,
.waiting-card .match-count-presets .match-count-btn {
  min-width: 3.2rem;
  min-height: 52px;
  font-size: 1.25rem;
  font-weight: 800;
}
.glory-title-input,
.waiting-card .glory-title-input {
  width: 100%;
  max-width: 100%;
  margin: 0.15rem 0 0.35rem;
  font-size: 1.15rem;
  min-height: 52px;
  padding: 0.45rem 0.7rem;
}
.match-hand-pill {
  flex-shrink: 0;
  margin-top: 0.1rem;
  font-size: clamp(1.15rem, 3.2vh, 1.6rem);
  font-weight: 800;
  color: #ffe9a8;
  text-shadow: 0 1px 4px #000a;
  letter-spacing: 0.04em;
  user-select: none;
  pointer-events: none;
}
.chip-bal {
  color: #ffe08a;
  font-weight: 800;
  margin-left: 0.2em;
  white-space: nowrap;
  text-shadow: 0 1px 2px #000a;
}

.opp-meta {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.05rem;
  min-width: 0;
  max-width: 100%;
}
.opp-meta-top {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
  max-width: 100%;
}
.opp-wind-chip {
  flex-shrink: 0;
  font-weight: 900;
  color: #ffe9a8;
}
.opp-name .chip-bal {
  margin-left: 0;
  font-size: 0.95em;
  line-height: 1.1;
}
.opp-top .opp-meta {
  align-items: center;
}
.opp-top .opp-name .chip-bal {
  text-align: center;
}

.opp-name .opp-name-text {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.15rem;
  justify-content: center;
  max-width: 100%;
}
.opp-left .opp-name .chip-bal,
.opp-right .opp-name .chip-bal {
  display: block;
  width: 100%;
  margin-left: 0;
  font-size: 1.05em;
}
.opp-left .opp-meta { align-items: flex-start; }
.opp-right .opp-meta { align-items: flex-end; }
.opp-right .opp-meta-top { flex-direction: row-reverse; }
.opp-right .opp-name .chip-bal { text-align: right; }
.opp-left .opp-name .chip-bal { text-align: left; }
.self-footer .chip-bal {
  font-size: 1.05em;
}
.match-scores-pill {
  flex-shrink: 0;
  margin-top: 0.15rem;
  font-size: clamp(0.95rem, 2.4vh, 1.2rem);
  font-weight: 700;
  color: #e8f5e9;
  background: #0007;
  border: 2px solid #f5d76e88;
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  max-width: 95%;
  text-align: center;
  line-height: 1.35;
  user-select: none;
  pointer-events: none;
}
/* Dedicated end-of-hand popup — fixed so it is never clipped by the felt */
.win-banner {
  white-space: normal;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 220;
  max-width: min(96vw, 52rem);
  max-height: min(92vh, 40rem);
  overflow-x: hidden;
  overflow-y: auto;
  line-height: 1.35;
  padding: 1.1rem 1.4rem 1.2rem;
  box-shadow: 0 12px 40px #000c, 0 0 0 4px #ff6a;
  pointer-events: auto;
}
.win-banner.win-banner-open {
  display: block;
}
.win-banner[hidden] {
  display: none !important;
}
.win-banner .win-champion {
  display: block;
  margin-top: 0.55rem;
  font-size: 1.2em;
  color: #fff3a0;
}
.win-banner .win-scores {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.78em;
  font-weight: 700;
  color: #cde;
}

.win-banner .win-chip-delta {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffe08a;
  letter-spacing: 0.02em;
}

.win-banner .win-next,
.win-banner .win-countdown {
  display: block;
  margin-top: 0.55rem;
  font-size: 0.85em;
  color: #9cf;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.win-banner .win-hand-missing {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.75em;
  color: #fc8;
}

.win-banner .win-hand-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.45rem 0.55rem;
  margin: 0.75rem auto 0.35rem;
  max-width: min(94vw, 50rem);
  padding: 0.35rem 0.2rem;
}
.win-banner .win-meld-group {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 0.12rem;
  padding: 0.2rem 0.25rem;
  background: #fff1;
  border-radius: 8px;
  border: 1px solid #ffd86a55;
}
.win-banner .win-concealed-group {
  background: #0005;
  border-color: #9cf6;
}
.tile.win {
  width: 58px;
  height: 80px;
  padding: 3px;
  border-radius: 7px;
  border-width: 2px;
  box-shadow: 0 3px 0 #0007, inset 0 1px 0 #fff;
  pointer-events: none;
}
@media (max-width: 900px) {
  .tile.win {
    width: 48px;
    height: 66px;
  }
}
@media (max-width: 600px) {
  .tile.win {
    width: 40px;
    height: 56px;
  }
}
.win-banner .win-leave-btn {
  display: block;
  margin: 0.85rem auto 0.15rem;
  min-width: 10rem;
  min-height: 3rem;
  font-size: 1.25rem;
  font-weight: 800;
  pointer-events: auto;
}
.win-banner .win-leave-btn-secondary {
  min-height: 2.6rem;
  font-size: 1.1rem;
  opacity: 0.92;
}
.btn-leave-table {
  margin-left: 0.35rem;
  min-height: 2.4rem;
  padding: 0.25rem 0.85rem;
  font-size: 1rem;
  font-weight: 800;
  border: 2px solid #fff6;
  color: #fff;
  background: #0006;
}
.btn-leave-table:hover { background: #a02828cc; border-color: #f88; }
.opp-hand.winner-hand {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
  border-radius: 8px;
}

.win-banner .win-next-btn {
  display: block;
  margin: 0.75rem auto 0.15rem;
  min-width: 12rem;
  min-height: 3.4rem;
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  pointer-events: auto;
  background: linear-gradient(180deg, #f0c040, #d4920a);
  color: #1a1000;
  border: 3px solid #fff8c8;
  border-radius: 14px;
  box-shadow: 0 4px 0 #8a5a00, 0 8px 18px #0008;
}
.win-banner .win-next-btn:disabled {
  opacity: 0.55;
  box-shadow: none;
}
.win-banner .win-main {
  display: block;
  font-weight: 800;
}
.win-banner .btn.win-leave-btn.btn-ghost {
  background: #0007;
  color: #fff;
  border: 2px solid #fff8;
}
.win-banner .btn.win-leave-btn.btn-ghost:hover {
  background: #a02828cc;
  border-color: #f88;
}

/* =====================================================================
   Phone-friendly layouts (elderly-friendly: large taps, high contrast)
   Breakpoints:
   - Phone narrow / portrait: max-width 600px
   - Phone landscape: max-height 500px + max-width 960px
   - Soft rotate hint: portrait + max-width 480px
   Tablet/desktop (≥601px wide, taller) keeps existing rules.
   ===================================================================== */

:root {
  --discard-cols: 16;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --phone-action-bar-h: 0px;
}

html {
  height: 100%;
  height: 100dvh;
}
body {
  height: 100%;
  height: 100dvh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.discard-pool {
  grid-template-columns: repeat(var(--discard-cols), auto);
}


/* Portrait: 南／北 (left/right) name+score as floating cards beside the thin hand column */
@media (orientation: portrait) and (max-width: 900px) {
  .opp-left, .opp-right {
    width: 36px;
    overflow: visible;
    z-index: 4;
  }
  .opp-left .opp-name,
  .opp-right .opp-name {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 7;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.3rem;
    max-width: min(42vw, 9.5rem);
    width: max-content;
    padding: 0.28rem 0.45rem;
    font-size: 0.78rem;
    line-height: 1.2;
    background: #0a1f14ee;
    border: 1.5px solid #f0d78c99;
    border-radius: 12px;
    box-shadow: 0 3px 10px #0008;
    overflow: visible;
    white-space: normal;
    text-overflow: clip;
  }
  .opp-left .opp-name {
    left: calc(100% + 6px);
    right: auto;
  }
  .opp-right .opp-name {
    right: calc(100% + 6px);
    left: auto;
    flex-direction: row-reverse;
  }
  .opp-left .opp-avatar,
  .opp-right .opp-avatar {
    width: 22px;
    height: 22px;
  }
  .opp-left .opp-meta,
  .opp-right .opp-meta {
    max-width: 7.2rem;
  }
  .opp-left .opp-name-text,
  .opp-right .opp-name-text {
    display: block;
    max-width: 6.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
  }
  .opp-left .opp-name .chip-bal,
  .opp-right .opp-name .chip-bal {
    display: block;
    width: auto;
    margin-top: 0.05rem;
    font-size: 0.9rem;
    font-weight: 900;
    color: #ffe08a;
  }
  .opp-wind-chip {
    font-size: 0.85rem;
    background: #14532d;
    border-radius: 6px;
    padding: 0 0.28rem;
  }
}

/* Soft rotate hint — still playable in portrait (replaces hard red banner) */
.phone-rotate-hint {
  display: none;
  flex-shrink: 0;
  text-align: center;
  background: #1a4a8acc;
  color: #fff;
  font-weight: 800;
  padding: 0.35rem 0.6rem;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  border-bottom: 2px solid #ffd54a66;
  z-index: 30;
}
.phone-rotate-hint[hidden] { display: none !important; }

/* Kill old hard portrait overlay */
@media (orientation: portrait) and (max-width: 700px) {
  body::before {
    content: none;
    display: none;
  }
}

/* ----- Phone portrait / narrow (≤600px) ----- */
@media (max-width: 600px) {
  :root {
    --discard-cols: 8;
    --touch: 52px;
    font-size: 16px;
  }

  /* Soft rotate hint: JS removes [hidden] on narrow portrait */
  .phone-rotate-hint:not([hidden]) {
    display: block;
  }
  @media (orientation: landscape) {
    .phone-rotate-hint { display: none !important; }
  }

  .app-header {
    padding: 0.7rem 0.75rem 0.35rem;
  }
  .app-header h1 {
    font-size: 1.75rem;
    letter-spacing: 0.1em;
  }
  .app-header.compact h1 { font-size: 1.4rem; }
  .subtitle { font-size: 0.95rem; }

  .card {
    margin: 0.5rem auto 1rem;
    padding: 1rem 1rem;
    width: calc(100% - 1rem);
    max-width: none;
  }
  .lobby-card .big-input,
  .big-input {
    height: 58px;
    font-size: 1.4rem;
  }
  .code-input { font-size: 1.75rem; }
  .btn-xl { min-height: 60px; font-size: 1.4rem; }
  .btn { min-height: 52px; font-size: 1.2rem; }

  .avatar-presets {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.4rem;
  }
  .avatar-preview { width: 80px; height: 80px; }

  /* Waiting: single column, large controls */
  .waiting-card {
    max-width: none;
    width: calc(100% - 0.8rem);
    padding: 0.65rem 0.7rem 0.8rem;
  }
  .waiting-card .wait-top {
    grid-template-columns: 1fr;
  }
  .waiting-card .host-settings-grid {
    grid-template-columns: 1fr;
  }
  .waiting-card .host-toggles {
    grid-template-columns: 1fr;
  }
  .waiting-card .host-toggles .toggle-row {
    min-height: 52px;
    padding: 0.45rem 0.55rem;
  }
  .waiting-card .toggle-btn {
    min-width: 88px;
    min-height: 48px;
  }
  .waiting-card .think-btn {
    min-height: 48px;
    font-size: 1.05rem;
  }
  .waiting-card .seat-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }
  .seat-slot .wind { font-size: 1.1rem; }
  .seat-slot .name { font-size: 1rem; }
  .seat-avatar { width: 48px; height: 48px; }
  .waiting-card .room-code-huge {
    font-size: clamp(2.2rem, 12vw, 3.2rem);
  }
  .waiting-card .wait-actions {
    flex-direction: column;
  }
  .waiting-card .wait-actions .btn-xl {
    max-width: none;
    width: 100%;
    flex: none;
  }

  /* Table top bar — compact wrap */
  .table-topbar {
    gap: 0.3rem;
    padding: 0.3rem 0.35rem;
    padding-left: max(0.35rem, var(--safe-left));
    padding-right: max(0.35rem, var(--safe-right));
  }
  .pill {
    min-height: 32px;
    font-size: 0.85rem;
    padding: 0.15rem 0.5rem;
  }
  .pill-turn {
    min-height: 36px;
    font-size: 1rem;
    max-width: 100%;
    flex: 1 1 100%;
    order: -1;
  }
  .pill-turn.is-you { font-size: 1.1rem; }
  .btn-leave-table {
    min-height: 40px;
    font-size: 0.9rem;
    padding: 0.2rem 0.55rem;
  }
  .table-topbar .settings-gear {
    width: 40px;
    height: 40px;
  }

  .table-felt {
    padding: 0.15rem 0.2rem;
    gap: 0.15rem;
    /* leave room for fixed action bar */
    padding-bottom: calc(0.15rem + var(--phone-action-bar-h));
  }

  .opp-name {
    font-size: 0.8rem;
    padding: 0.1rem 0.4rem;
  }
  .opp-name.active-turn {
    font-size: 0.9rem;
    padding: 0.15rem 0.45rem;
  }

  /* Side hands stay thin; name/score use floating cards (see portrait block) */
  .opp-left, .opp-right {
    width: 36px;
  }
  .opp-hand.backs .tile.back {
    width: 14px;
    height: 20px;
  }
  .opp-hand.vertical .tile.back {
    width: 20px;
    height: 14px;
  }
  .opp-hand.vertical {
    max-height: 28vh;
  }
  .opp-left .meld-group .tile.tiny,
  .opp-right .meld-group .tile.tiny,
  .opp-left .opp-flowers .tile.tiny,
  .opp-right .opp-flowers .tile.tiny {
    width: 26px;
    height: 18px;
  }
  .opp-left .meld-group .tile .tile-img,
  .opp-left .opp-flowers .tile .tile-img,
  .opp-right .meld-group .tile .tile-img,
  .opp-right .opp-flowers .tile .tile-img {
    width: 18px;
    height: 26px;
  }
  .opp-left .opp-melds,
  .opp-right .opp-melds {
    max-height: 18vh;
  }

  .opp-top .opp-hand.backs .tile.back {
    width: 14px;
    height: 20px;
  }
  .opp-top .tile.tiny {
    width: 20px;
    height: 28px;
  }

  .tile.discard {
    width: 30px;
    height: 42px;
  }
  .tile.tiny {
    width: 22px;
    height: 30px;
  }

  .discard-pool {
    gap: 2px;
    padding: 0.15rem;
    max-height: calc(100% - 3.2rem);
  }

  .round-wind-mark {
    font-size: clamp(1.8rem, 7vh, 2.8rem);
  }
  .match-hand-pill {
    font-size: clamp(0.95rem, 2.8vh, 1.2rem);
  }
  .match-scores-pill {
    font-size: clamp(0.8rem, 2.2vh, 1rem);
    padding: 0.15rem 0.5rem;
    max-width: 100%;
  }

  .claim-banner, .win-banner {
    white-space: normal;
    max-width: 94vw;
    font-size: 1.15rem;
    padding: 0.65rem 0.9rem;
  }

  /* Self area: hand large + scroll; actions fixed bottom */
  .self-area {
    gap: 0.2rem;
    padding: 0.15rem 0.2rem;
    padding-bottom: 0;
    width: 100%;
  }
  .self-turn-badge {
    font-size: 1.15rem;
    top: -0.05rem;
  }
  .self-melds {
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
    padding: 0 0.2rem;
  }
  .self-hand {
    justify-content: flex-start;
    gap: 3px;
    padding: 0.2rem 0.3rem 0.25rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-x;
  }
  .self-hand .tile {
    width: 40px;
    height: 56px;
  }
  .hand-gap { width: 10px; min-width: 10px; }

  .self-footer {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
    font-size: 0.95rem;
    padding: 0 0.2rem 0.15rem;
  }
  .btn-draw {
    min-height: 44px;
    min-width: 88px;
    font-size: 1.05rem;
  }

  /* Fixed bottom action bar — never off-screen */
  .action-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.4rem 0.45rem;
    padding-bottom: max(0.4rem, var(--safe-bottom));
    padding-left: max(0.45rem, var(--safe-left));
    padding-right: max(0.45rem, var(--safe-right));
    background: #0a1a12f2;
    border-top: 2px solid #ffd54a88;
    box-shadow: 0 -4px 16px #0008;
    width: 100%;
  }
  .btn-action {
    flex: 1 1 auto;
    min-width: 56px;
    max-width: 88px;
    min-height: 52px;
    font-size: 1.3rem;
    padding: 0.3rem 0.45rem;
  }

  /* Chat: full-width drawer on phone */
  .chat-panel {
    width: min(100vw, 100%);
    max-width: 100%;
    border-left: none;
    border-top: 3px solid var(--gold);
    top: auto;
    height: min(55vh, 420px);
    bottom: var(--phone-action-bar-h, 0px);
  }
  .chat-preset-btn { min-height: 44px; font-size: 1rem; }
  .chat-input, .chat-send { min-height: 48px; }

  /* Win / discard popups fit viewport */
  .win-banner {
    max-width: 96vw;
    max-height: min(88dvh, 92vh);
    padding: 0.75rem 0.85rem 0.9rem;
    font-size: 1.25rem;
    top: 48%;
  }
  .win-banner .win-hand-row {
    gap: 0.3rem;
    margin-top: 0.5rem;
  }
  .tile.win {
    width: 34px;
    height: 48px;
    padding: 2px;
  }
  .win-banner .win-next-btn {
    min-width: 10rem;
    min-height: 3rem;
    font-size: 1.25rem;
    width: calc(100% - 0.5rem);
    max-width: 20rem;
  }
  .win-banner .win-leave-btn {
    min-height: 2.8rem;
    width: calc(100% - 0.5rem);
    max-width: 20rem;
  }

  .discard-info {
    padding: 0.5rem;
    align-items: flex-end;
    padding-bottom: max(0.5rem, var(--safe-bottom));
  }
  .discard-info-card {
    max-width: 100%;
    max-height: min(85dvh, 90vh);
    overflow-y: auto;
    padding: 0.85rem 1rem;
  }
  .discard-info-tile .tile {
    width: 56px;
    height: 78px;
  }
  .discard-info-title { font-size: 1.5rem; }
  .discard-info-body { font-size: 1.1rem; }

  .toast {
    bottom: calc(4.5rem + var(--safe-bottom));
    font-size: 1.05rem;
    max-width: 94vw;
  }

  .turn-callout {
    font-size: 1.1rem;
    padding: 0.4rem 0.75rem;
  }

  .settings-card { max-width: none; }
  .felt-swatches { gap: 0.5rem; }
  .felt-swatch { min-height: 76px; font-size: 1rem; }
  .toggle-row {
    padding: 0.7rem 0.75rem;
    min-height: 56px;
  }
  .toggle-btn {
    min-width: 88px;
    min-height: 48px;
  }

  .settings-gear {
    top: max(0.4rem, var(--safe-top));
    right: max(0.5rem, var(--safe-right));
    width: 48px;
    height: 48px;
  }
}

/* Very narrow portrait (~360px) — a bit tighter tiles, still ≥44px taps */
@media (max-width: 380px) {
  :root { --discard-cols: 7; }
  .self-hand .tile {
    width: 36px;
    height: 50px;
  }
  .btn-action {
    min-width: 48px;
    min-height: 48px;
    font-size: 1.2rem;
  }
  .waiting-card .seat-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ----- Phone landscape (short height) ----- */
@media (max-height: 500px) and (max-width: 960px) {
  :root {
    --discard-cols: 12;
    font-size: 15px;
  }

  .phone-rotate-hint { display: none !important; }

  .table-topbar {
    gap: 0.25rem;
    padding: 0.2rem 0.35rem;
  }
  .pill {
    min-height: 28px;
    font-size: 0.8rem;
    padding: 0.1rem 0.45rem;
  }
  .pill-turn {
    min-height: 32px;
    font-size: 0.95rem;
    flex: 0 1 auto;
    order: 0;
    max-width: min(50vw, 18rem);
  }
  .btn-leave-table {
    min-height: 36px;
    font-size: 0.85rem;
  }
  .table-topbar .settings-gear {
    width: 36px;
    height: 36px;
    font-size: 1.15rem;
  }

  .table-felt {
    padding: 0.1rem 0.25rem;
    gap: 0.1rem;
    padding-bottom: calc(0.1rem + var(--phone-action-bar-h));
  }

  .opp-left, .opp-right { width: 34px; }
  .opp-hand.backs .tile.back {
    width: 13px;
    height: 18px;
  }
  .opp-hand.vertical .tile.back {
    width: 18px;
    height: 12px;
  }
  .opp-hand.vertical { max-height: 55vh; }
  .opp-top .opp-hand.backs .tile.back {
    width: 12px;
    height: 17px;
  }

  .tile.discard {
    width: 28px;
    height: 38px;
  }
  .discard-pool {
    gap: 2px;
    max-height: calc(100% - 2.4rem);
  }

  .round-wind-mark {
    font-size: clamp(1.4rem, 8vh, 2.2rem);
  }
  .match-hand-pill { font-size: 0.95rem; }
  .match-scores-pill { font-size: 0.8rem; }

  .self-area { gap: 0.1rem; padding: 0.1rem; }
  .self-turn-badge { font-size: 1rem; }
  .self-hand .tile {
    width: 38px;
    height: 52px;
  }
  .hand-gap { width: 8px; min-width: 8px; }

  .self-footer {
    gap: 0.35rem;
    font-size: 0.9rem;
  }
  .btn-draw {
    min-height: 40px;
    min-width: 72px;
    font-size: 0.95rem;
  }

  .action-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    flex-wrap: nowrap;
    gap: 0.3rem;
    padding: 0.25rem 0.4rem;
    padding-bottom: max(0.25rem, var(--safe-bottom));
    padding-left: max(0.4rem, var(--safe-left));
    padding-right: max(0.4rem, var(--safe-right));
    background: #0a1a12f2;
    border-top: 2px solid #ffd54a88;
  }
  .btn-action {
    flex: 1 1 0;
    min-width: 52px;
    min-height: 44px;
    font-size: 1.15rem;
    padding: 0.2rem 0.35rem;
  }

  .chat-panel {
    width: min(320px, 45vw);
    height: auto;
    top: 0;
    bottom: var(--phone-action-bar-h, 0px);
  }

  .win-banner {
    max-height: min(90dvh, 94vh);
    max-width: 94vw;
    font-size: 1.15rem;
    padding: 0.55rem 0.85rem 0.7rem;
  }
  .tile.win {
    width: 32px;
    height: 44px;
  }
  .win-banner .win-next-btn {
    min-height: 2.6rem;
    font-size: 1.15rem;
  }

  .toast {
    bottom: calc(3.6rem + var(--safe-bottom));
  }

  /* Lobby/waiting still usable when rotated */
  .card { padding: 0.6rem 0.85rem; margin: 0.35rem auto 0.6rem; }
  .app-header { padding: 0.35rem 0.6rem 0.15rem; }
  .app-header h1 { font-size: 1.45rem; }
  .waiting-card .host-toggles {
    grid-template-columns: 1fr 1fr;
  }
  .waiting-card .seat-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Phone class from JS — ensure action-bar space + no page sideways scroll */
body.is-phone,
body.is-phone-landscape {
  overflow-x: hidden;
}
body.is-phone #app,
body.is-phone-landscape #app {
  overflow-x: hidden;
  max-width: 100vw;
}
body.is-phone .table-screen,
body.is-phone-landscape .table-screen {
  overflow: hidden;
}
body.is-phone .screen.active,
body.is-phone-landscape .screen.active {
  overflow-x: hidden;
}

/* When table screen active on phone, prevent lobby scroll bleed */
body.is-phone #screen-table.active,
body.is-phone-landscape #screen-table.active {
  overflow: hidden;
}

/* Soft hint only on very narrow portrait (JS may also toggle) */
@media (orientation: portrait) and (max-width: 480px) {
  .phone-rotate-hint:not([hidden]) {
    display: block;
  }
}

#discard-pay-presets .discard-pay-btn {
  font-size: 0.95rem;
  padding: 0.55rem 0.7rem;
  white-space: nowrap;
}

.discard-pay-help {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  opacity: 0.85;
  line-height: 1.35;
}


/* App logo — 快樂麻雀 */
.app-logo {
  display: block;
  width: 120px;
  height: 120px;
  margin: 0 auto 0.75rem;
  border-radius: 26px;
  object-fit: cover;
  box-shadow:
    0 0 0 4px rgba(232, 197, 71, 0.35),
    0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ----- Lobby screen: edge-to-edge, wide two-column ----- */
#screen-lobby {
  position: relative;
  width: 100%;
  min-height: 0;
}
#screen-lobby > .settings-gear {
  top: max(0.5rem, var(--safe-top, 0px));
  right: max(0.65rem, var(--safe-right, 0px));
}

#screen-lobby.screen.active {
  display: flex;
  flex-direction: column;
  overflow: auto;
}

/* [hidden] must win over lobby flex display rules */
#lobby-onboard[hidden],
#lobby-main[hidden],
.lobby-onboard-shell[hidden],
.lobby-layout[hidden] {
  display: none !important;
}


.lobby-brand {
  text-align: center;
  padding: 0.85rem 0.5rem 0.35rem;
  flex-shrink: 0;
}
.lobby-brand h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--gold);
  text-shadow: 0 2px 0 #0006;
  margin: 0;
}
.lobby-brand .subtitle {
  font-size: 1.1rem;
  opacity: 0.9;
  color: #ffe9a8;
  margin-top: 0.3rem;
}

.lobby-brand--inline {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  padding: 0.25rem 0 0.5rem;
}
.lobby-brand--inline .app-logo {
  margin: 0;
}
.lobby-brand-text {
  text-align: center;
  min-width: 0;
}

/* Onboarding shell: full width, not a skinny strip */
.lobby-onboard-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  flex: 1;
  min-height: 0;
  padding: 0.35rem max(0.75rem, 0px) 1rem;
  box-sizing: border-box;
}
.lobby-onboard-shell .lobby-onboard {
  width: 100%;
  max-width: none;
  margin: 0.5rem 0 0;
  flex: 1;
}
.onboard-grid {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.onboard-title {
  text-align: center;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--gold);
  margin: 0 0 1rem;
  line-height: 1.4;
  text-shadow: 0 1px 0 #0006;
}

/* Main lobby: stacked on narrow, 2-col on wide */
.lobby-layout {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
  max-width: none;
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0.5rem max(0.75rem, 0px) 1rem;
  box-sizing: border-box;
}
#screen-lobby .lobby-panel,
#screen-lobby .lobby-card,
.lobby-panel,
.lobby-card {
  max-width: none;
  width: 100%;
  margin: 0;
  border: 2px solid rgba(232, 197, 71, 0.28);
  background: rgba(0, 0, 0, 0.42);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}
.lobby-col-left,
.lobby-col-right {
  min-width: 0;
}
.lobby-panel-title {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: 0.1em;
  margin: 0 0 0.75rem;
  text-align: center;
  text-shadow: 0 1px 0 #0006;
}
.lobby-rooms-panel {
  display: flex;
  flex-direction: column;
  min-height: 12rem;
}
.lobby-rooms-panel .public-rooms {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 0;
}
.lobby-hint {
  margin-top: 0.35rem;
}

.lobby-profile {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0 0 1.25rem;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
}
.lobby-avatar-summary {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--gold);
  background: #fff;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}
.lobby-profile-text {
  min-width: 0;
  flex: 1;
  text-align: left;
}
.lobby-welcome {
  font-size: 0.95rem;
  opacity: 0.8;
  margin: 0;
}
.lobby-name-summary {
  font-size: 1.55rem;
  font-weight: 800;
  color: #fff;
  margin: 0.15rem 0 0.35rem;
  line-height: 1.2;
  word-break: break-word;
}
.btn-edit-profile {
  appearance: none;
  background: transparent;
  border: none;
  color: #ffe9a8;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 0.25rem 0;
  min-height: 40px;
}
.btn-edit-profile:active { opacity: 0.75; }

/* Wide / tablet / landscape: left–right lobby (≥860px) */
@media (min-width: 860px) {
  .lobby-layout {
    display: grid;
    grid-template-columns: minmax(300px, 0.95fr) minmax(340px, 1.25fr);
    gap: 1rem 1.25rem;
    align-items: stretch;
    padding: 0.75rem 1.1rem 1rem;
    overflow: hidden;
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
  }
  #screen-lobby.screen.active {
    overflow: hidden; /* panels scroll internally */
  }
  #screen-lobby:has(#lobby-onboard:not([hidden])) {
    overflow: auto;
  }
  .lobby-col-left {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1.2rem 1.35rem;
  }
  .lobby-col-right {
    overflow: hidden;
    padding: 1.2rem 1.35rem;
    min-height: 0;
  }
  .lobby-brand--inline {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    gap: 1rem;
  }
  .lobby-brand--inline .app-logo {
    width: 88px;
    height: 88px;
    border-radius: 20px;
    flex-shrink: 0;
  }
  .lobby-brand--inline .lobby-brand-text {
    text-align: left;
  }
  .lobby-brand--inline h1 {
    font-size: 2.15rem;
    letter-spacing: 0.14em;
  }
  .lobby-brand--inline .subtitle {
    font-size: 1.05rem;
    margin-top: 0.2rem;
  }
  .lobby-panel-title {
    text-align: left;
    font-size: 1.65rem;
  }
  .lobby-rooms-panel .public-rooms-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
    padding-right: 0.15rem;
  }
  .lobby-rooms-panel .public-rooms-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
  }

  /* Onboard: use width on wide screens */
  .lobby-onboard-shell {
    padding: 0.5rem 1.1rem 1.25rem;
    overflow-y: auto;
  }
  .lobby-onboard-shell .lobby-brand h1 {
    font-size: 2.6rem;
  }
  .lobby-onboard-shell .lobby-onboard {
    padding: 1.5rem 1.75rem;
  }
  .onboard-grid {
    display: grid;
    grid-template-columns: minmax(220px, 0.85fr) minmax(280px, 1.15fr);
    gap: 1.25rem 1.75rem;
    align-items: start;
  }
  .onboard-name-block .big-input {
    margin-bottom: 0;
  }
  .lobby-onboard .btn-xl {
    margin-top: 1rem;
  }
}

/* Extra-wide tablets / desktop */
@media (min-width: 1100px) {
  .lobby-layout {
    grid-template-columns: minmax(340px, 0.85fr) minmax(420px, 1.35fr);
    gap: 1.15rem 1.5rem;
    padding: 0.85rem 1.5rem 1.15rem;
  }
  .lobby-brand--inline .app-logo {
    width: 100px;
    height: 100px;
  }
  .lobby-brand--inline h1 {
    font-size: 2.35rem;
  }
}

/* Narrow phone portrait: full-width stack, edge padding */
@media (max-width: 859px) {
  .lobby-layout,
  .lobby-onboard-shell {
    padding-left: max(0.65rem, 0px);
    padding-right: max(0.65rem, 0px);
  }
  .lobby-panel,
  .lobby-onboard-shell .lobby-onboard {
    padding: 1.1rem 1rem;
  }
}

@media (max-width: 600px) {
  .app-logo {
    width: 92px;
    height: 92px;
    border-radius: 20px;
  }
  .lobby-brand h1,
  .lobby-brand--inline h1 {
    font-size: 2rem;
    letter-spacing: 0.1em;
  }
  .onboard-title { font-size: 1.25rem; }
  .lobby-avatar-summary { width: 64px; height: 64px; }
  .lobby-name-summary { font-size: 1.35rem; }
  .lobby-panel-title { font-size: 1.35rem; }
  .lobby-layout,
  .lobby-onboard-shell {
    padding-left: max(0.5rem, 0px);
    padding-right: max(0.5rem, 0px);
  }
}

/* —— Public room list (lobby) —— */
.public-rooms {
  margin-top: 0.35rem;
  width: 100%;
}
.public-rooms-empty {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: #ffe9a8;
  opacity: 0.9;
  margin: 0.75rem 0 0.25rem;
  padding: 1rem 0.75rem;
  background: rgba(255, 255, 255, 0.06);
  border: 2px dashed rgba(255, 255, 255, 0.22);
  border-radius: 14px;
}
.public-rooms-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.public-room-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.9rem 1rem;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(232, 197, 71, 0.35);
  border-radius: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.public-room-info {
  flex: 1 1 160px;
  min-width: 0;
  text-align: left;
}
.public-room-code {
  font-size: 1.55rem;
  font-weight: 800;
  color: #fff;
  margin: 0;
  letter-spacing: 0.06em;
  line-height: 1.25;
}
.public-room-meta {
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffe9a8;
  margin: 0.25rem 0 0;
  line-height: 1.4;
}
.public-room-host {
  font-size: 1rem;
  font-weight: 600;
  opacity: 0.85;
  margin: 0.15rem 0 0;
}
.public-room-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  flex-shrink: 0;
}
.public-room-actions .btn {
  width: auto;
  min-width: 110px;
  min-height: 52px;
  margin: 0;
  font-size: 1.15rem;
  padding: 0.55rem 1rem;
}
.public-room-badge {
  display: inline-block;
  font-size: 0.95rem;
  font-weight: 800;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  margin-right: 0.35rem;
  vertical-align: middle;
}
.public-room-badge.wait {
  background: #2e7d32;
  color: #fff;
}
.public-room-badge.play {
  background: #c62828;
  color: #fff;
}
.public-room-badge.ended {
  background: #546e7a;
  color: #fff;
}
@media (max-width: 600px) {
  .public-room-code { font-size: 1.35rem; }
  .public-room-meta { font-size: 1.05rem; }
  .public-room-actions { width: 100%; }
  .public-room-actions .btn { flex: 1; min-width: 0; }
}

/* Light table side-space (tablet+/desktop; skip short phone landscape) */
@media (min-width: 900px) and (min-height: 560px) {
  .table-felt {
    padding-left: 0.2rem;
    padding-right: 0.2rem;
  }
  .opp-left, .opp-right {
    width: 96px;
  }
  .opp-left .opp-name, .opp-right .opp-name {
    max-width: 92px;
    font-size: 0.9rem;
  }
}
@media (min-width: 1200px) and (min-height: 560px) {
  .opp-left, .opp-right {
    width: 110px;
  }
  .opp-left .opp-name, .opp-right .opp-name {
    max-width: 106px;
  }
  .table-mid {
    gap: 0.45rem;
  }
}

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


/* Mid-game: player left — continue with bot or leave */
.absent-modal {
  position: fixed;
  inset: 0;
  z-index: 280;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: #000a;
}
.absent-modal[hidden] { display: none !important; }
.absent-modal-card {
  width: min(520px, 96vw);
  background: #0d3d28ee;
  border: 3px solid #f5d76e;
  border-radius: 20px;
  padding: 1.25rem 1.4rem 1.4rem;
  box-shadow: 0 12px 40px #000a;
  text-align: center;
}
.absent-modal-title {
  margin: 0 0 0.6rem;
  font-size: clamp(1.4rem, 4.5vw, 1.85rem);
  color: #ffe08a;
  font-weight: 800;
}
.absent-modal-msg {
  margin: 0 0 1.1rem;
  font-size: clamp(1.05rem, 3.2vw, 1.25rem);
  line-height: 1.45;
  color: #f2fff6;
  font-weight: 600;
}
.absent-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.absent-modal-actions .btn {
  width: 100%;
  min-height: 3.2rem;
  font-size: 1.2rem;
}
.absent-modal-actions .btn-ghost {
  background: #0005;
  color: #e8f5e9;
  border: 2px solid #ffffff55;
}


.claim-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.45rem 0.65rem;
  white-space: normal;
  max-width: min(92vw, 520px);
}
.claim-countdown {
  display: inline-block;
  font-size: 1.35em;
  font-weight: 900;
  color: #ffe08a;
  background: #0008;
  border: 2px solid #f5d76eaa;
  border-radius: 999px;
  padding: 0.15rem 0.75rem;
  letter-spacing: 0.02em;
  min-width: 5.5em;
  text-align: center;
}
.claim-countdown-urgent {
  color: #fff;
  background: #c62828ee;
  border-color: #ff8a80;
  animation: claim-pulse 0.7s ease-in-out infinite;
}
@keyframes claim-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}


/* 出銃 options with always-visible explanations */
.discard-pay-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
}
.discard-pay-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  border: 2px solid #ffffff44;
  background: #0005;
  color: #f2fff6;
  cursor: pointer;
  font: inherit;
  line-height: 1.3;
}
.discard-pay-option .discard-pay-name {
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffe08a;
}
.discard-pay-option .discard-pay-desc {
  font-size: 0.95rem;
  font-weight: 600;
  color: #d7efe0;
  opacity: 0.95;
}
.discard-pay-option.selected {
  border-color: var(--gold, #f5d76e);
  background: #1a5c3488;
  box-shadow: 0 0 0 2px #f5d76e55;
}
.discard-pay-option.selected .discard-pay-name {
  color: #fff3c4;
}
