:root {
  color-scheme: light;
  --bg: #f4f2ec;
  --ink: #1e2228;
  --muted: #68707a;
  --line: #d9d4c8;
  --panel: #fffdf8;
  --panel-strong: #fff7dc;
  --red: #e7473c;
  --yellow: #f5c247;
  --green: #2f9d68;
  --blue: #2f6fc8;
  --wild: #242832;
  --accent: #111827;
  --shadow: 0 16px 40px rgba(34, 29, 21, 0.11);
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui,
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0)),
    var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.ghost {
  background: transparent;
  color: var(--accent);
}

.danger {
  border-color: #a5342d;
  background: #a5342d;
}

.uno-button {
  border-color: #c82118;
  background: #e7473c;
  color: #fff;
  font-weight: 950;
}

.text-button {
  min-height: 30px;
  padding: 0 8px;
  border-color: transparent;
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: rgba(255, 253, 248, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 45%, rgba(255, 255, 255, 0.85) 46% 54%, transparent 55%),
    conic-gradient(from 45deg, var(--red), var(--yellow), var(--green), var(--blue), var(--red));
  color: #111;
  font-weight: 950;
  box-shadow: inset 0 0 0 3px #1d2028;
}

.top-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #ece8dc;
  color: #343a40;
  font-size: 12px;
  font-weight: 700;
}

.badge.red {
  background: #ffe4df;
  color: #8e2b23;
}

.badge.green {
  background: #dff4e8;
  color: #16633e;
}

.badge.blue {
  background: #dfe9fb;
  color: #174b94;
}

.page {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.login-screen {
  min-height: calc(100vh - 72px);
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel h1,
.section-title,
.room-title h1 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel h1 {
  font-size: clamp(30px, 5vw, 48px);
}

.login-panel p {
  color: var(--muted);
  line-height: 1.7;
}

.field-grid {
  display: grid;
  gap: 12px;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #343a40;
  font-weight: 700;
}

.toggle-line input {
  width: auto;
}

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

.field span {
  color: #353b43;
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #20242b;
  box-shadow: 0 0 0 3px rgba(32, 36, 43, 0.12);
}

textarea {
  min-height: 170px;
  resize: vertical;
  font-family: "Cascadia Code", Consolas, monospace;
  line-height: 1.5;
}

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-pad {
  padding: 18px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title h2 {
  margin: 0;
  font-size: 20px;
}

.room-list {
  display: grid;
  gap: 10px;
}

.room-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.room-row h3 {
  margin: 0 0 8px;
}

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

.empty {
  display: grid;
  place-items: center;
  min-height: 240px;
  border: 1px dashed #c8c1b4;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 22px;
}

.room-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.room-main {
  display: grid;
  gap: 16px;
}

.room-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
}

.room-title h1 {
  font-size: clamp(24px, 4vw, 38px);
}

.title-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.table-zone {
  min-height: 420px;
  display: grid;
  gap: 16px;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(47, 157, 104, 0.14), rgba(47, 111, 200, 0.08)),
    #f7fbf2;
}

.center-piles {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 180px));
  justify-content: center;
  gap: 18px;
  align-items: center;
}

.pile {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed rgba(30, 34, 40, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.deck {
  width: 92px;
  height: 138px;
  border-radius: 8px;
  border: 4px solid #1c2027;
  background:
    linear-gradient(135deg, transparent 43%, #fff 44% 56%, transparent 57%),
    conic-gradient(from 45deg, var(--red), var(--yellow), var(--green), var(--blue), var(--red));
  display: grid;
  place-items: center;
  color: #111;
  font-weight: 950;
  box-shadow: 0 9px 18px rgba(0, 0, 0, 0.18);
}

.turn-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  text-align: center;
}

.player-track {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.player-chip {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.player-chip.current {
  border-color: #171b21;
  box-shadow: inset 0 0 0 2px #171b21;
}

.hand-area {
  display: grid;
  gap: 10px;
}

.selected-card-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.selected-card-panel p {
  margin: 0;
  color: #353b43;
  line-height: 1.55;
}

.hand-toolbar,
.form-row,
.replay-controls,
.color-picker {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.hand {
  display: flex;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 2px 12px;
}

.uno-card {
  width: 82px;
  height: 124px;
  flex: 0 0 auto;
  border: 4px solid #171b21;
  border-radius: 8px;
  display: grid;
  place-items: center;
  position: relative;
  color: #fff;
  font-weight: 950;
  text-align: center;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
  user-select: none;
}

.uno-card.small {
  width: 56px;
  height: 82px;
  border-width: 3px;
  font-size: 12px;
}

.uno-card.selectable {
  cursor: pointer;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease;
}

.uno-card.selectable:hover {
  transform: translateY(-8px);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.2);
}

.uno-card.selected {
  transform: translateY(-14px);
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.24);
  outline: 4px solid #111827;
  outline-offset: 2px;
}

.uno-card.marked-swap {
  outline: 4px solid #f5c247;
  outline-offset: 2px;
}

.uno-card.playable {
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.16),
    0 0 0 3px rgba(47, 157, 104, 0.18);
}

.uno-card.disabled {
  filter: grayscale(0.85);
  opacity: 0.55;
}

.uno-card.red {
  background: var(--red);
}

.uno-card.yellow {
  background: var(--yellow);
  color: #271f08;
}

.uno-card.green {
  background: var(--green);
}

.uno-card.blue {
  background: var(--blue);
}

.uno-card.wild {
  background:
    linear-gradient(135deg, var(--red) 0 25%, var(--yellow) 25% 50%, var(--green) 50% 75%, var(--blue) 75%),
    var(--wild);
}

.uno-card::before {
  content: "";
  position: absolute;
  inset: 16px 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  transform: rotate(-18deg);
}

.card-image {
  position: absolute;
  inset: 8px;
  width: calc(100% - 16px);
  height: calc(100% - 16px);
  object-fit: cover;
  border-radius: 6px;
  z-index: 0;
  opacity: 0.86;
}

.uno-card .card-image + span {
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.56);
  color: #fff;
}

.uno-card span {
  position: relative;
  z-index: 1;
  max-width: 68px;
  overflow-wrap: anywhere;
  line-height: 1.1;
}

.side-stack {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 88px;
}

.roster {
  display: grid;
  gap: 8px;
}

.roster-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.roster-name {
  min-width: 0;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roster-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.chat {
  display: grid;
  grid-template-rows: minmax(240px, 42vh) auto;
  overflow: hidden;
}

.messages {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: #f9f7f1;
}

.message {
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  line-height: 1.45;
}

.message.system {
  background: #eef6ef;
  color: #27563e;
  border-color: #cae6d1;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

details.panel {
  padding: 0;
}

summary {
  cursor: pointer;
  padding: 16px 18px;
  font-weight: 900;
}

details .details-body {
  padding: 0 18px 18px;
}

.custom-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.image-preview {
  width: 110px;
  height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.custom-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 2px solid #16191f;
  background: var(--red);
  cursor: pointer;
}

.swatch[aria-pressed="true"] {
  outline: 3px solid #171b21;
  outline-offset: 2px;
}

.swatch.red {
  background: var(--red);
}

.swatch.yellow {
  background: var(--yellow);
}

.swatch.green {
  background: var(--green);
}

.swatch.blue {
  background: var(--blue);
}

.replay-stage {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.replay-hands {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.replay-hand {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfaf6;
}

.mini-hand {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 6px 0 2px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 36px));
  pointer-events: none;
}

.toast-item {
  padding: 12px 14px;
  border-radius: 8px;
  background: #171b21;
  color: white;
  box-shadow: var(--shadow);
}

.toast-item.error {
  background: #a5342d;
}

.toast-item.info {
  background: #17365f;
}

@media (max-width: 980px) {
  .lobby-grid,
  .room-layout {
    grid-template-columns: 1fr;
  }

  .side-stack {
    position: static;
  }
}

@media (max-width: 680px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .page {
    width: min(100vw - 20px, 1480px);
    padding-top: 12px;
  }

  .room-title,
  .room-row,
  .custom-row {
    grid-template-columns: 1fr;
  }

  .center-piles {
    grid-template-columns: 1fr 1fr;
  }

  .uno-card {
    width: 74px;
    height: 112px;
  }
}
