:root {
  color-scheme: light;
  --ink: #101827;
  --muted: #667085;
  --panel: #ffffff;
  --line: #cbd5e1;
  --table: #0f172a;
  --red: #dc2626;
  --yellow: #facc15;
  --green: #16a34a;
  --blue: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #eef3f8;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button {
  font: inherit;
}

.hidden {
  display: none !important;
}

.app {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: clamp(14px, 3vw, 28px);
}

@media (min-width: 1280px) {
  .app {
    margin-left: max(28px, calc((100vw - 1120px - 340px) / 2));
    margin-right: 340px;
  }
}

.setup-screen {
  width: min(560px, 100%);
  margin: 26px auto;
  padding: 28px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 50px rgba(15, 23, 42, .14);
}

.brand-row,
.game-header,
.hand-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 48px;
  line-height: .9;
  color: #e11d48;
  font-weight: 950;
}

.brand-row p,
.game-header p {
  margin-top: 8px;
  color: var(--muted);
}

.mini-card {
  width: 72px;
  height: 98px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  box-shadow: 0 16px 28px rgba(15, 23, 42, .22);
  color: #fff;
  font-size: 28px;
  font-weight: 950;
}

.fan-red {
  background: var(--red);
  transform: rotate(7deg);
}

.mode-tabs,
.setup-grid,
.hand-actions {
  display: grid;
  gap: 12px;
}

.mode-tabs {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-top: 26px;
}

.mode-tab,
.primary-btn,
.ghost-btn,
.success-btn,
.danger-btn,
.small-action {
  min-height: 44px;
  border-radius: 8px;
  border: 2px solid var(--ink);
  cursor: pointer;
  font-weight: 850;
}

.mode-tab {
  background: #fff;
}

.mode-tab.active,
.primary-btn {
  border-color: #e11d48;
  background: #e11d48;
  color: #fff;
}

.setup-grid {
  grid-template-columns: 1fr 1fr;
  margin-top: 18px;
}

.count-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.count-panel.muted {
  opacity: .52;
}

.count-panel span {
  color: var(--muted);
  font-size: 14px;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.stepper button {
  width: 38px;
  height: 38px;
  border: 1px solid #9ca3af;
  border-radius: 4px;
  background: #f8fafc;
  font-weight: 900;
  cursor: pointer;
}

.stepper strong {
  font-size: 24px;
}

.primary-btn {
  width: 100%;
  margin-top: 22px;
}

.online-panel {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.online-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.text-input {
  min-height: 42px;
  border: 1px solid #b8c3d4;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

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

.online-info {
  color: var(--muted);
  line-height: 1.45;
}

.game-screen {
  display: grid;
  gap: 16px;
}

.game-header,
.players-bar,
.hand-section,
.chat-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px 16px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .08);
}

.game-header h2 {
  color: #e11d48;
  font-size: 34px;
  font-weight: 950;
}

.direction-text {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  color: #475569;
  font-weight: 900;
  flex-wrap: wrap;
}

.direction-text span {
  flex: 0 0 auto;
}

.direction-text b {
  display: block;
  width: min(520px, 100%);
  min-width: 0;
  overflow: hidden;
  color: #e11d48;
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.direction-text.reverse b {
  color: #2563eb;
}

.ghost-btn {
  background: #eef2f7;
  color: var(--ink);
  border-color: transparent;
  padding: 0 16px;
}

.success-btn {
  background: #22c55e;
  border-color: transparent;
  padding: 0 16px;
}

.danger-btn {
  background: #f97316;
  border-color: transparent;
  padding: 0 16px;
}

button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

.players-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.player-chip {
  padding: 10px;
  border: 1px solid #d4dde9;
  border-radius: 8px;
  background: #f8fafc;
  text-align: center;
}

.player-chip.active {
  background: #111827;
  color: #fff;
}

.player-chip .uno-mark {
  color: #facc15;
  font-size: 12px;
  font-weight: 900;
}

.player-chip .thinking-mark {
  margin-top: 3px;
  color: #93c5fd;
  font-size: 12px;
  font-weight: 900;
}

.table {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(220px, 1.2fr) minmax(210px, .9fr);
  align-items: center;
  gap: 22px;
  min-height: 360px;
  padding: 22px;
  border-radius: 8px;
  background: var(--table);
  color: #e5e7eb;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08), 0 20px 45px rgba(15, 23, 42, .18);
}

.pile-column,
.play-column {
  text-align: center;
}

.pile-label {
  display: block;
  margin-bottom: 10px;
  color: #94a3b8;
  font-size: 14px;
}

.small-action {
  margin-top: 12px;
  padding: 0 16px;
  background: #f8fafc;
  color: var(--ink);
}

.play-zone-label {
  display: inline-block;
  max-width: 100%;
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-weight: 900;
}

.play-stack {
  position: relative;
  width: 150px;
  height: 178px;
  margin: 0 auto;
}

.stack-shadow {
  position: absolute;
  width: 112px;
  height: 156px;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, .75);
  opacity: .64;
  box-shadow: 0 12px 24px rgba(0, 0, 0, .28);
}

.stack-shadow.one {
  left: 9px;
  top: 12px;
  background: var(--blue);
  transform: rotate(-11deg);
}

.stack-shadow.two {
  left: 26px;
  top: 8px;
  background: var(--yellow);
  transform: rotate(9deg);
}

.play-stack .uno-card {
  position: absolute;
  left: 20px;
  top: 0;
  z-index: 3;
  transform: rotate(-2deg);
}

.penalty-text {
  margin-top: 10px;
  color: #fbbf24;
  font-weight: 900;
}

.rule-panel {
  padding: 16px;
  border: 1px solid #3b82f6;
  border-radius: 8px;
  background: #172554;
}

.rule-panel strong {
  color: #bfdbfe;
}

.rule-panel p {
  margin-top: 8px;
  color: #dbeafe;
  line-height: 1.45;
}

.hand-section {
  overflow: hidden;
}

.chat-panel {
  display: grid;
  gap: 10px;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-head span {
  color: #64748b;
  font-size: 12px;
  font-weight: 950;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.chat-list li {
  padding: 9px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  color: #334155;
  line-height: 1.35;
}

.chat-meta {
  display: block;
  color: #64748b;
  font-size: 12px;
  font-weight: 850;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(120px, .8fr) minmax(180px, 1fr) auto;
  gap: 8px;
}

.chat-target {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  padding: 0 10px;
}

.turn-log-panel {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 300px;
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 40px rgba(15, 23, 42, .14);
  overflow: hidden;
}

.turn-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #111827;
  color: #fff;
  cursor: grab;
  touch-action: none;
}

.turn-log-panel.dragging {
  user-select: none;
}

.turn-log-panel.dragging .turn-log-head {
  cursor: grabbing;
}

.turn-log-head span {
  color: #facc15;
  font-size: 12px;
  font-weight: 950;
}

.turn-log-list {
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  margin: 0;
  padding: 12px;
  overflow-y: auto;
  list-style: none;
}

.turn-log-list li {
  padding: 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  color: #334155;
  line-height: 1.4;
}

.turn-log-list li.latest-log {
  border-color: #facc15;
  background: #fffbeb;
  color: #713f12;
  box-shadow: 0 0 0 3px rgba(250, 204, 21, .22);
}

.hand-actions {
  grid-template-columns: repeat(5, auto);
}

.hand {
  display: flex;
  gap: 9px;
  margin-top: 14px;
  padding-top: 14px;
  padding-bottom: 10px;
  overflow-x: auto;
}

.uno-card {
  position: relative;
  width: 78px;
  height: 110px;
  min-width: 78px;
  border: 2px solid rgba(255, 255, 255, .92);
  border-radius: 8px;
  color: #fff;
  overflow: hidden;
  box-shadow: 0 14px 28px rgba(0, 0, 0, .34), 0 2px 0 rgba(255, 255, 255, .35) inset;
}

.uno-card.playable {
  cursor: pointer;
  outline: 3px solid #22c55e;
}

.uno-card.selected {
  transform: translateY(-14px);
  outline: 4px solid #facc15;
  box-shadow: 0 20px 34px rgba(0, 0, 0, .42), 0 0 0 4px rgba(250, 204, 21, .28);
}

.ai-flying-card {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  transform-origin: center;
}

.uno-card.dimmed {
  opacity: .55;
}

.uno-card.card-large {
  width: 112px;
  height: 156px;
  min-width: 112px;
}

.uno-card::before {
  content: "";
  position: absolute;
  inset: 4px;
  z-index: 4;
  border-radius: 6px;
  background: linear-gradient(140deg, rgba(255, 255, 255, .38), rgba(255, 255, 255, .08) 28%, transparent 46%);
  pointer-events: none;
  mix-blend-mode: screen;
}

.uno-card::after {
  content: "";
  position: absolute;
  inset: 5px;
  z-index: 5;
  border: 1px solid rgba(255, 255, 255, .34);
  border-radius: 5px;
  pointer-events: none;
}

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

.card-yellow {
  background: var(--yellow);
  color: var(--ink);
}

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

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

.card-wild {
  background: #111827;
}

.card-back {
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, .22), transparent 18%),
    repeating-linear-gradient(135deg, #111827 0 8px, #1f2937 8px 16px);
}

.uno-oval {
  position: absolute;
  inset: 18px 10px;
  z-index: 1;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 3px rgba(17, 24, 39, .16);
  transform: rotate(-26deg);
}

.card-yellow .uno-oval {
  background: #fff7cc;
}

.uno-main {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 31px;
  font-weight: 950;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .22);
}

.card-large .uno-main {
  font-size: 46px;
}

.card-red .uno-main {
  color: var(--red);
  text-shadow: none;
}

.card-blue .uno-main {
  color: var(--blue);
  text-shadow: none;
}

.card-green .uno-main {
  color: var(--green);
  text-shadow: none;
}

.card-yellow .uno-main {
  color: var(--ink);
  text-shadow: none;
}

.uno-corner {
  position: absolute;
  left: 7px;
  top: 6px;
  z-index: 6;
  font-size: 14px;
  font-weight: 950;
  line-height: 1;
}

.uno-corner.bottom {
  inset: auto 7px 6px auto;
  transform: rotate(180deg);
}

.uno-logo {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--yellow);
  font-size: 28px;
  font-weight: 950;
  text-shadow: 0 2px 0 var(--red);
  transform: rotate(-20deg);
}

.skip-symbol {
  width: 34px;
  height: 34px;
  border: 5px solid currentColor;
  border-radius: 50%;
}

.skip-symbol::after {
  content: "";
  position: absolute;
  width: 31px;
  border-top: 5px solid currentColor;
  transform: translate(-31px, 14px) rotate(-32deg);
}

.wild-grid {
  width: 44px;
  height: 58px;
  border-radius: 20px;
  overflow: hidden;
  transform: rotate(-18deg);
  box-shadow: 0 0 0 3px #111827;
}

.wild-grid span {
  float: left;
  width: 50%;
  height: 50%;
}

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

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

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

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

.color-dialog,
.winner-dialog {
  width: min(360px, calc(100% - 36px));
  border: 0;
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .35);
}

.color-dialog::backdrop,
.winner-dialog::backdrop {
  background: rgba(15, 23, 42, .56);
}

.color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.color-choice {
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-weight: 950;
  cursor: pointer;
}

.color-choice.yellow {
  color: var(--ink);
}

.color-cancel {
  width: 100%;
  margin-top: 12px;
}

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

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

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

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

.winner-dialog .primary-btn {
  margin-top: 18px;
}

@media (max-width: 1180px) {
  .app {
    width: 100%;
    margin: 0 auto;
  }

  .turn-log-panel {
    position: static;
    width: 100%;
    max-height: 260px;
  }

  .turn-log-head {
    cursor: default;
    touch-action: auto;
  }
}

@media (max-width: 900px) {
  .app {
    padding: 18px;
  }

  .table {
    grid-template-columns: 1fr 1fr;
    min-height: auto;
  }

  .rule-panel {
    grid-column: 1 / -1;
    width: 100%;
    margin: 0 auto;
  }

  .players-bar {
    grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  }
}

@media (max-width: 640px) {
  .setup-screen {
    padding: 20px;
    margin: 8px auto;
  }

  .setup-grid,
  .mode-tabs {
    grid-template-columns: 1fr;
  }

  .online-actions {
    grid-template-columns: 1fr;
  }

  .brand-row,
  .game-header,
  .hand-head {
    align-items: flex-start;
  }

  .game-header {
    flex-direction: column;
  }

  .game-header .ghost-btn {
    width: 100%;
  }

  .direction-text {
    width: 100%;
  }

  .table {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
  }

  .play-stack {
    width: 128px;
    height: 152px;
  }

  .stack-shadow {
    width: 96px;
    height: 134px;
  }

  .stack-shadow.two {
    left: 22px;
  }

  .play-stack .uno-card {
    left: 16px;
  }

  .hand-head {
    flex-direction: column;
  }

  .hand-actions {
    width: 100%;
    grid-template-columns: 1fr 1fr;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  .hand-actions button {
    padding: 0 10px;
  }

  .uno-card {
    width: 68px;
    height: 96px;
    min-width: 68px;
  }

  .uno-card.card-large {
    width: 96px;
    height: 134px;
    min-width: 96px;
  }

  .uno-main {
    font-size: 27px;
  }

  .card-large .uno-main {
    font-size: 40px;
  }
}

@media (max-width: 420px) {
  .app {
    padding: 10px;
  }

  .game-header,
  .players-bar,
  .hand-section,
  .chat-panel,
  .setup-screen {
    padding: 12px;
  }

  .hand-actions {
    gap: 8px;
  }
}
