:root {
  --bg: #0b1220;
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.08);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.68);
  --border: rgba(255, 255, 255, 0.12);
  --shadow: rgba(0, 0, 0, 0.35);
  --accent: #7c5cff;
  --accent2: #12b981;
  --danger: #fb7185;
  --tile-scale-board: 1;
  --tile-scale-hand: 1;
  /* legacy fallback */
  --tile-scale: 1;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
input,
textarea,
[contenteditable] {
  -webkit-user-select: text;
  user-select: text;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  color: var(--text);
  background: radial-gradient(1200px 800px at 20% 10%, rgba(124, 92, 255, 0.16), transparent 60%),
    radial-gradient(1000px 700px at 90% 20%, rgba(18, 185, 129, 0.12), transparent 55%),
    radial-gradient(900px 650px at 45% 90%, rgba(255, 172, 79, 0.08), transparent 55%), var(--bg);
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-root {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.legalBar {
  position: fixed;
  left: 10px;
  bottom: 10px;
  z-index: 9999;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
}

.legalBar a {
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
}

.legalBar a:hover {
  text-decoration: underline;
}

.legalBar .sep {
  opacity: 0.6;
}

.screen {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
}

.screen.game {
  place-items: stretch;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card {
  width: min(860px, 100%);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(12px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  padding: 16px;
  display: grid;
  gap: 12px;
}

.title {
  font-weight: 900;
  letter-spacing: 0.2px;
  font-size: clamp(26px, 4vw, 44px);
  text-align: center;
}

.title.small {
  font-size: 18px;
  text-align: left;
}

.subtitle {
  color: rgba(255, 255, 255, 0.72);
  text-align: center;
  font-size: 14px;
  line-height: 1.25;
}

.meta {
  color: rgba(255, 255, 255, 0.55);
  text-align: center;
  font-size: 12px;
}

.room-discovery {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.waiting-rooms {
  width: min(720px, 100%);
  display: grid;
  gap: 8px;
  justify-items: center;
}

.waiting-title {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
}

.waiting-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.room-chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}

.room-chip:hover:enabled {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
}

.room-list {
  width: min(720px, 100%);
  display: grid;
  gap: 8px;
}

.room-entry {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  text-align: left;
}

.room-entry:hover:enabled {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
}

.room-entry:disabled {
  opacity: 0.6;
  cursor: default;
}

.room-entry-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.room-entry-title {
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-entry-meta {
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.hero {
  width: min(640px, 100%);
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
}

.hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.row.wrap {
  flex-wrap: wrap;
}

.row.space {
  justify-content: space-between;
}

.lang-inline {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.lang-select {
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
}

.btn {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}

.btn:hover:enabled {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.95), rgba(18, 185, 129, 0.85));
  border-color: rgba(255, 255, 255, 0.18);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.04);
}

.btn.danger {
  border-color: rgba(251, 113, 133, 0.4);
  color: rgba(255, 255, 255, 0.92);
}

.note {
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  line-height: 1.35;
}

.note.ok {
  border-color: rgba(18, 185, 129, 0.35);
}

.note.warn {
  border-color: rgba(255, 172, 79, 0.4);
}

.note.chat {
  display: grid;
  gap: 8px;
}

.note.chat.compact .chat-log {
  max-height: 140px;
}

.chat-log {
  max-height: 220px;
  overflow: auto;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.18);
  display: grid;
  gap: 6px;
}

.chat-line {
  font-size: 12px;
  line-height: 1.25;
}

.note.chat form input {
  flex: 1;
}

.form {
  display: grid;
  gap: 12px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 640px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

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

.field span {
  font-size: 12px;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  outline: none;
}

.field.disabled {
  opacity: 0.55;
}

.field.check {
  grid-auto-flow: column;
  grid-template-columns: 18px 1fr;
  align-items: center;
}

.field.check input {
  width: 18px;
  height: 18px;
}

.rules h3 {
  margin: 14px 0 6px;
  font-size: 14px;
}

.rules ul {
  margin: 0 0 12px 16px;
  padding: 0;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1.35;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex: 0 0 auto;
}

.top-actions-compact {
  display: none;
  margin-left: auto;
  align-items: center;
}

.btn.icon {
  width: 36px;
  height: 36px;
  padding: 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn.icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.topbar[data-compact="1"] {
  padding: 6px 10px;
  gap: 10px;
}

.topbar[data-compact="1"] .title {
  display: none;
}

.topbar[data-compact="1"] .top-actions {
  display: none;
}

.topbar[data-compact="1"] .subtitle {
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar[data-compact="1"] .top-actions-compact {
  display: inline-flex;
}

.brand {
  display: grid;
  gap: 2px;
}

.board-wrap {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  gap: 12px;
  padding: 14px;
  flex-direction: row;
}
.board-wrap > .panel {
  min-width: 0;
}
.board-wrap > .panel:not(.side-panel) {
  flex: 1.2 1 0;
}
.board-wrap > .side-panel {
  flex: 0.8 1 0;
}

@media (max-width: 880px) {
  .board-wrap {
    flex-direction: column;
  }
}

.side-info {
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  display: grid;
  gap: 10px;
}

.board-wrap[data-side="collapsed"] .side-info {
  display: none;
}

.split-center {
  display: flex;
  gap: 10px;
  align-items: center;
}

.split-left,
.split-right {
  flex: 1 1 0;
  display: flex;
}

.split-left {
  justify-content: flex-end;
}

.split-right {
  justify-content: flex-start;
}

.panel {
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(10px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  padding: 14px;
  display: grid;
  gap: 12px;
  min-height: 0;
}

.screen.game .panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.screen.game .side-panel {
  overflow: auto;
}

.h {
  font-weight: 800;
  font-size: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
}

.status {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.status.ok .pill {
  border-color: rgba(18, 185, 129, 0.35);
}

.status.warn .pill {
  border-color: rgba(255, 172, 79, 0.35);
}

.status.ready .pill {
  border-color: rgba(124, 92, 255, 0.35);
}

.ends {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  color: rgba(255, 255, 255, 0.82);
}

.end b {
  color: rgba(255, 255, 255, 0.96);
}

.board {
  padding: 10px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  min-height: 86px;
}

.screen.game .board {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.board-spiral {
  position: relative;
  width: 100%;
  height: clamp(220px, 46vh, 520px);
  overflow: auto;
  overscroll-behavior: contain;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.12);
}

.screen.game .board-spiral {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}

.chat-toast-stack {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  display: grid;
  gap: 6px;
  width: min(360px, calc(100% - 16px));
  pointer-events: none;
  z-index: 6;
}

.chat-toast {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(10px);
  color: rgba(255, 255, 255, 0.92);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

.board-spiral-inner {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.board-tile {
  position: absolute;
  width: calc(48px * var(--tile-scale-board));
  height: calc(48px * var(--tile-scale-board));
  display: grid;
  place-items: center;
}

.board-tile .tile-svg {
  width: calc(48px * var(--tile-scale-board));
  height: calc(24px * var(--tile-scale-board));
  transform: rotate(var(--tile-rot, 0deg));
  transform-origin: 50% 50%;
}

.board-tile .tile-svg.double {
  width: calc(24px * var(--tile-scale-board));
  height: calc(48px * var(--tile-scale-board));
  transform: rotate(0deg);
}

.tile-svg {
  width: calc(96px * var(--tile-scale-hand));
  height: calc(48px * var(--tile-scale-hand));
  flex: 0 0 auto;
}

.tile-svg.double {
  width: calc(48px * var(--tile-scale-hand));
  height: calc(96px * var(--tile-scale-hand));
}

.tile-svg.playable rect {
  stroke: rgba(18, 185, 129, 0.55);
  stroke-width: 2;
}

.hand {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 4px;
  align-items: center;
}

@media (max-height: 720px) {
  .topbar {
    padding: 10px 12px;
  }
  .board-wrap {
    padding: 10px;
  }
  .panel {
    padding: 12px;
  }
  .btn {
    padding: 9px 12px;
  }
}

.tile-back {
  width: calc(96px * var(--tile-scale-hand));
  height: calc(48px * var(--tile-scale-hand));
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.35), rgba(18, 185, 129, 0.25));
  position: relative;
  overflow: hidden;
}

.tile-back::after {
  content: "";
  position: absolute;
  inset: -20px;
  background: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0 8px, rgba(255, 255, 255, 0) 8px 16px);
  transform: rotate(12deg);
}

.tile-btn {
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.tile-btn.selected .tile-svg rect {
  stroke: rgba(124, 92, 255, 0.8);
  stroke-width: 3;
}

.tile-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 10;
}

.overlay-card {
  width: min(720px, 100%);
  max-height: calc(100vh - 36px);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(12px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  padding: 16px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

.overlay-title {
  font-weight: 900;
  font-size: 18px;
}

.overlay-body {
  overflow: auto;
}

.overlay-body .h {
  margin-bottom: 6px;
}

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(10px);
  font-size: 13px;
  z-index: 12;
  max-width: min(560px, 92vw);
}
