/* ------------------------------------------------------------------ */
/* Online layer: lobby, room chip, live-table extras                    */
/* ------------------------------------------------------------------ */

body[data-view="lobby"] .topbar,
body[data-view="lobby"] .game-view,
body[data-view="lobby"] .event-console {
  display: none;
}

body[data-view="table"] .online-lobby {
  display: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

/* The lobby hides the topbar, so it carries its own theme control. */
.lobby-theme-toggle {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  z-index: 4;
}

.online-lobby {
  position: relative;
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
  place-items: center;
  overflow: hidden;
}

.lobby-orbit {
  position: absolute;
  border: 1px solid rgba(124, 235, 223, 0.14);
  border-radius: 50%;
  pointer-events: none;
}

.lobby-orbit--a {
  width: 78vw;
  aspect-ratio: 1;
  animation: lobbyOrbit 46s linear infinite;
}

.lobby-orbit--b {
  width: 52vw;
  aspect-ratio: 1;
  border-color: rgba(238, 200, 109, 0.12);
  animation: lobbyOrbit 34s linear infinite reverse;
}

@keyframes lobbyOrbit {
  from { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.04); }
  to { transform: rotate(360deg) scale(1); }
}

.lobby-stage {
  position: relative;
  z-index: 2;
  display: grid;
  width: min(100%, 760px);
  gap: 16px;
}

.lobby-hero {
  display: grid;
  justify-items: center;
  text-align: center;
}

.lobby-hero h1 {
  margin: 6px 0 8px;
}

.lobby-hero > p {
  max-width: 520px;
  margin: 0;
  color: rgba(226, 245, 245, 0.74);
  font-size: 13px;
  line-height: 1.8;
}

.lobby-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(152, 213, 211, 0.22);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.05), transparent 24%),
    radial-gradient(circle at 92% 0%, rgba(94, 223, 212, 0.12), transparent 30%),
    linear-gradient(180deg, rgba(18, 35, 48, 0.96), rgba(7, 16, 26, 0.98));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 20px 44px rgba(0, 0, 0, 0.34);
}

.lobby-field {
  display: grid;
  gap: 6px;
}

.lobby-field > span {
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.24em;
}

.lobby-field input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(152, 213, 211, 0.28);
  border-radius: 8px;
  background: rgba(4, 12, 20, 0.72);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 0.04em;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.lobby-field input:focus {
  border-color: color-mix(in srgb, var(--cyan) 72%, white);
  box-shadow: 0 0 0 3px rgba(94, 223, 212, 0.14);
}

.lobby-field--code input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-align: center;
}

.lobby-entry-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.lobby-entry-actions .launch-button {
  width: 100%;
}

.lobby-join {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.lobby-join .landing-rules {
  min-height: 46px;
  padding-inline: 18px;
}

.lobby-note {
  margin: 0;
  color: rgba(169, 187, 185, 0.78);
  font-size: 12px;
  line-height: 1.7;
}

.lobby-note[data-tone="error"] {
  color: #ff9cae;
}

.lobby-note[data-tone="ok"] {
  color: #8ff0c0;
}

.lobby-room-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}

.lobby-code {
  display: block;
  margin-top: 4px;
  color: #fff6dc;
  font-family: var(--font-display);
  font-size: clamp(30px, 6vw, 42px);
  font-weight: 900;
  letter-spacing: 0.24em;
  text-shadow: 0 0 22px rgba(238, 200, 109, 0.35);
}

.lobby-link {
  margin: 6px 0 0;
  color: rgba(169, 187, 185, 0.72);
  font-family: var(--font-display);
  font-size: 11px;
  word-break: break-all;
}

.lobby-share {
  display: flex;
  gap: 8px;
}

.lobby-share .landing-rules {
  min-height: 40px;
  padding-inline: 14px;
}

.lobby-mode {
  display: grid;
  gap: 8px;
}

.lobby-mode .mode-choice-row {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.lobby-seats {
  display: grid;
  gap: 8px;
}

.lobby-seat {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(152, 213, 211, 0.18);
  border-left: 2px solid var(--row-accent, var(--cyan));
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.045), rgba(8, 18, 28, 0.72));
  color: var(--text);
  font-family: var(--font-ui);
  text-align: left;
}

.lobby-seat.is-you {
  border-color: color-mix(in srgb, var(--cyan) 55%, transparent);
  box-shadow: 0 0 18px rgba(94, 223, 212, 0.12);
}

.lobby-seat--add {
  border-style: dashed;
  border-left-width: 1px;
  color: rgba(226, 245, 245, 0.82);
  cursor: pointer;
}

.lobby-seat--add:hover {
  border-color: color-mix(in srgb, var(--cyan) 60%, transparent);
}

.lobby-seat__index {
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 11px;
}

.lobby-seat__name {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  overflow: hidden;
  font-size: 14px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-tag {
  padding: 2px 6px;
  border: 1px solid rgba(152, 213, 211, 0.3);
  border-radius: 5px;
  color: rgba(226, 245, 245, 0.78);
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.06em;
}

.seat-tag--host {
  border-color: rgba(238, 200, 109, 0.5);
  color: var(--gold);
}

.seat-tag--you {
  border-color: rgba(94, 223, 212, 0.55);
  color: var(--cyan);
}

.seat-state {
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.seat-state--online { color: #8ff0c0; }
.seat-state--offline { color: #ff9cae; }
.seat-state--ai { color: var(--gold); }

.seat-remove {
  width: 26px;
  height: 26px;
  border: 1px solid rgba(255, 156, 174, 0.4);
  border-radius: 6px;
  background: rgba(255, 156, 174, 0.08);
  color: #ff9cae;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.seat-remove:hover {
  background: rgba(255, 156, 174, 0.2);
}

.lobby-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.lobby-actions .launch-button {
  flex: 1 1 220px;
}

.lobby-actions .landing-rules {
  flex: 0 0 auto;
  min-height: 48px;
  padding-inline: 18px;
}

/* ---------------------------------------------------------- room chip */

.room-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid rgba(152, 213, 211, 0.28);
  border-radius: 8px;
  background: rgba(6, 16, 26, 0.72);
  font-family: var(--font-display);
}

.room-chip__label {
  color: var(--text-dim);
  font-size: 8px;
  letter-spacing: 0.24em;
}

.room-chip b {
  color: #fff6dc;
  font-size: 14px;
  letter-spacing: 0.16em;
}

.room-chip__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  box-shadow: 0 0 8px currentColor;
}

.room-chip__dot[data-state="live"] { background: #79d79d; }
.room-chip__dot[data-state="connecting"],
.room-chip__dot[data-state="reconnecting"] {
  background: var(--gold);
  animation: chipPulse 1.2s ease-in-out infinite;
}
.room-chip__dot[data-state="offline"] { background: #ff9cae; }

@keyframes chipPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ------------------------------------------------------- dealt cards */

@keyframes cardDealtIn {
  from {
    opacity: 0;
    transform: translate3d(var(--deal-x, 210px), var(--deal-y, -150px), 0) rotate(-16deg) scale(0.7);
  }
  70% {
    opacity: 1;
    transform: translate3d(0, -6px, 0) rotate(1.5deg) scale(1.02);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.game-card.is-dealt {
  animation: cardDealtIn 560ms cubic-bezier(0.24, 0.8, 0.24, 1) both;
  --deal-x: 190px;
  --deal-y: -140px;
}

.discard-stack.is-empty .discard-card {
  opacity: 0.25;
}

/* ------------------------------------------------------------ toast */

.online-toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 90;
  max-width: min(90vw, 420px);
  padding: 12px 18px;
  border: 1px solid rgba(152, 213, 211, 0.32);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(20, 38, 52, 0.98), rgba(8, 18, 28, 0.98));
  color: var(--text);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.42);
  font-size: 13px;
  text-align: center;
  transform: translate(-50%, 16px);
  opacity: 0;
  transition: opacity 220ms ease, transform 220ms ease;
  pointer-events: none;
}

.online-toast[data-visible="true"] {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------ small screens */
/* ------------------------------------------------ readiness and clocks */

.lobby-limit {
  display: grid;
  gap: 8px;
}

.limit-choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.limit-choice {
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid rgba(152, 213, 211, 0.24);
  border-radius: 7px;
  background: rgba(5, 15, 24, 0.7);
  color: rgba(226, 245, 245, 0.78);
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, color 180ms ease, transform 180ms ease;
}

.limit-choice[aria-pressed="true"] {
  border-color: rgba(94, 223, 212, 0.72);
  background: linear-gradient(180deg, rgba(94, 223, 212, 0.2), rgba(94, 223, 212, 0.06));
  color: #eafffb;
  box-shadow: 0 0 18px rgba(94, 223, 212, 0.16);
}

.limit-choice--infinite[aria-pressed="true"] {
  border-color: rgba(238, 200, 109, 0.68);
  background: linear-gradient(180deg, rgba(238, 200, 109, 0.2), rgba(238, 200, 109, 0.06));
  color: #fff5d6;
}

.limit-choice:disabled {
  cursor: default;
  opacity: 0.55;
}

.lobby-limit__note {
  margin: 0;
  color: rgba(169, 187, 185, 0.7);
  font-size: 11px;
  line-height: 1.6;
}

.seat-ready {
  padding: 3px 7px;
  border: 1px solid rgba(152, 213, 211, 0.22);
  border-radius: 5px;
  color: rgba(169, 187, 185, 0.72);
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.seat-ready.is-ready {
  border-color: rgba(143, 240, 192, 0.5);
  background: rgba(143, 240, 192, 0.1);
  color: #9ff4c8;
  box-shadow: 0 0 12px rgba(143, 240, 192, 0.12);
}

.lobby-seat.is-ready {
  background:
    linear-gradient(90deg, rgba(143, 240, 192, 0.08), rgba(8, 18, 28, 0.72));
}

.ready-button {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid rgba(94, 223, 212, 0.42);
  border-radius: 8px;
  background: rgba(94, 223, 212, 0.08);
  color: #dffcf7;
  font-family: var(--font-ui);
  font-weight: 700;
  cursor: pointer;
}

.ready-button svg {
  width: 18px;
  height: 18px;
}

.ready-button.is-ready {
  border-color: rgba(143, 240, 192, 0.68);
  background: linear-gradient(180deg, rgba(143, 240, 192, 0.2), rgba(143, 240, 192, 0.06));
  color: #b9ffd9;
}

.ready-button:disabled {
  cursor: default;
  opacity: 0.55;
}

.turn-countdown {
  display: inline-block;
  align-self: center;
  margin-top: 6px;
  padding: 7px 10px;
  border: 1px solid rgba(94, 223, 212, 0.3);
  border-radius: 7px;
  background: rgba(4, 12, 20, 0.7);
  color: #dffcf7;
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.08em;
}

.turn-countdown[data-tone="warn"] { color: #ffe3a4; border-color: rgba(238, 200, 109, 0.5); }
.turn-countdown[data-tone="danger"] { color: #ffb3c2; border-color: rgba(255, 156, 174, 0.6); animation: chipPulse 1s ease-in-out infinite; }
.turn-countdown[data-tone="infinite"] { color: #fff2c2; border-color: rgba(238, 200, 109, 0.46); }

.link-tag {
  padding: 2px 6px;
  border: 1px solid rgba(255, 156, 174, 0.5);
  border-radius: 5px;
  color: #ffb3c2;
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.link-tag--replace {
  border-color: rgba(238, 200, 109, 0.55);
  color: #fee4a4;
}

.player-panel.is-disconnected {
  border-color: rgba(255, 156, 174, 0.48);
  background:
    linear-gradient(180deg, rgba(42, 20, 31, 0.82), rgba(8, 15, 24, 0.96));
  filter: saturate(0.72);
}

.player-panel.is-awaiting-replacement {
  border-color: rgba(238, 200, 109, 0.56);
}

.disconnect-overlay {
  position: absolute;
  inset: 0 0 auto;
  z-index: 4;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-bottom: 1px solid rgba(255, 156, 174, 0.4);
  background: linear-gradient(180deg, rgba(71, 24, 38, 0.94), rgba(71, 24, 38, 0.68));
  color: #ffd6de;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.16em;
}

.disconnect-overlay small {
  color: rgba(255, 214, 222, 0.72);
  letter-spacing: 0.04em;
}

.offline-console {
  display: grid;
  gap: 8px;
  padding: 9px;
  border: 1px solid rgba(255, 156, 174, 0.34);
  border-radius: 7px;
  background: rgba(53, 17, 28, 0.72);
}

.offline-console__head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  justify-content: space-between;
  color: #ffd6de;
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.12em;
}

.offline-console__head small {
  color: rgba(255, 214, 222, 0.7);
  font-family: var(--font-ui);
  letter-spacing: 0;
}

.offline-console__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.offline-console__actions button {
  padding: 6px 9px;
  border: 1px solid rgba(152, 213, 211, 0.28);
  border-radius: 6px;
  background: rgba(5, 15, 24, 0.72);
  color: #dffcf7;
  font-family: var(--font-ui);
  font-size: 11px;
  cursor: pointer;
}

.offline-console__actions button:hover {
  border-color: rgba(94, 223, 212, 0.62);
}

.offline-console__actions button.is-danger {
  border-color: rgba(255, 156, 174, 0.48);
  color: #ffb3c2;
}

.offline-console--readonly {
  color: rgba(255, 214, 222, 0.8);
  font-size: 11px;
}

.round-ready-tag {
  padding: 3px 7px;
  border: 1px solid rgba(152, 213, 211, 0.24);
  border-radius: 5px;
  color: rgba(169, 187, 185, 0.76);
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.round-ready-tag.is-ready {
  border-color: rgba(143, 240, 192, 0.5);
  color: #9ff4c8;
}

.score-ready {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 5px;
  border: 1px solid rgba(143, 240, 192, 0.42);
  border-radius: 4px;
  color: #9ff4c8;
  font-family: var(--font-display);
  font-size: 9px;
  font-style: normal;
  letter-spacing: 0.08em;
}

.result-actions {
  align-items: center;
}

.result-actions {
  flex-wrap: wrap;
  gap: 10px;
}

.result-actions button.is-quiet {
  border-color: var(--line-strong);
  background: rgba(6, 16, 26, 0.68);
  color: var(--text-soft);
}

.result-actions button.is-quiet:hover {
  border-color: rgba(152, 213, 211, 0.58);
  color: var(--text);
}

.exit-dialog {
  width: min(92vw, 560px);
}

.exit-shell {
  padding: clamp(22px, 4vw, 34px);
}

.exit-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.exit-heading h2 {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-size: clamp(22px, 4vw, 30px);
}

.exit-message {
  margin: 16px 0 0;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.75;
}

.exit-actions {
  display: grid;
  gap: 9px;
  margin-top: 22px;
}

.exit-action {
  display: inline-flex;
  min-height: 46px;
  padding: 0 15px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: rgba(14, 28, 40, 0.74);
  color: var(--text);
  cursor: pointer;
}

.exit-action svg {
  --icon-size: 16px;
  width: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.exit-action--end {
  border-color: rgba(143, 240, 192, 0.48);
  background: rgba(143, 240, 192, 0.08);
  color: #a8f0ca;
}

.exit-action--danger {
  border-color: rgba(255, 156, 174, 0.48);
  background: rgba(255, 156, 174, 0.08);
  color: #ffb3c2;
}

.exit-action--quiet {
  border-color: transparent;
  background: transparent;
  color: var(--text-dim);
}

.exit-action:hover {
  filter: brightness(1.14);
}

.landing-rules.is-danger {
  border-color: rgba(255, 156, 174, 0.38);
  color: #ffb3c2;
}

.result-ready-clock {
  color: rgba(226, 245, 245, 0.72);
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.08em;
}


@media (max-width: 720px) {
  .online-lobby {
    padding-inline: 14px;
    place-items: start center;
  }

  .lobby-entry-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .lobby-join {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .lobby-mode .mode-choice-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .lobby-code {
    font-size: 34px;
  }

  .limit-choice {
    flex: 1 1 calc(50% - 8px);
  }

  .limit-choice--infinite {
    flex-basis: 100%;
  }

  .ready-button {
    flex: 1 1 100%;
  }

  .offline-console__actions button {
    flex: 1 1 calc(50% - 6px);
  }

  .turn-countdown {
    font-size: 11px;
  }

  .room-chip {
    padding: 5px 9px;
  }

  .room-chip__label {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lobby-orbit,
  .game-card.is-dealt {
    animation: none;
  }
}
