:root {
  --bg: #0f1220;
  --panel: #171b2e;
  --panel2: #1e2340;
  --text: #e8ecff;
  --muted: #8b93b8;
  --accent: #7c5cff;
  --accent2: #22c55e;
  --danger: #ef4444;
  --border: #2a3157;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; }

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 12px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .3px;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  cursor: pointer;
  transition: transform .1s, opacity .1s;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .45; cursor: default; }

.primary {
  background: linear-gradient(135deg, #7c5cff, #5b8cff);
  border: none;
  font-weight: 700;
}
.ghost { background: transparent; }

.status {
  font-weight: 700;
  color: #c9d2ff;
  min-height: 22px;
}

.players {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.player {
  flex: 1 1 120px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 13px;
}
.player.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.player .name { font-weight: 700; }
.player .meta { color: var(--muted); font-size: 12px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px;
}

h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 0 0 7px;
}

.table {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 54px;
}
.set {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  padding: 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .035);
  border: 1px solid transparent;
}
.set.editing {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.tile.small.selected {
  transform: translateY(-4px);
}
.empty { color: var(--muted); font-size: 13px; padding: 6px 2px; }

.rack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 64px;
}
.rack-group {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.rack-label {
  flex: 0 0 22px;
  width: 22px;
  line-height: 58px;
  text-align: center;
  font-size: 14px;
}
.rack-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}

.tile {
  position: relative;
  width: 44px;
  height: 58px;
  border-radius: 9px;
  background: linear-gradient(180deg, #f7f8ff, #dfe4f7);
  color: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  border: 2px solid transparent;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
  transition: transform .12s, box-shadow .12s;
  user-select: none;
}
.tile.small {
  width: 34px;
  height: 44px;
  font-size: 15px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35);
}
.tile.c1 { color: #d21f3c; }
.tile.c2 { color: #1d4ed8; }
.tile.c3 { color: #111; }
.tile.c4 { color: #15803d; }

.tile.joker {
  background: linear-gradient(135deg, #2b1a4d, #5b2ea6);
  color: #fff;
  font-size: 22px;
}
.tile.small.joker { font-size: 18px; }

.tile.selected {
  transform: translateY(-10px);
  border-color: var(--accent);
  box-shadow: 0 10px 18px rgba(124, 92, 255, .45), 0 3px 0 rgba(0, 0, 0, .35);
}

.tile .dot {
  position: absolute;
  top: 4px;
  right: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.tile .dot.c1 { background: #d21f3c; }
.tile .dot.c2 { background: #1d4ed8; }
.tile .dot.c3 { background: #111; }
.tile .dot.c4 { background: #16a34a; }

.hint {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}
.hint.error { color: #ff8a8a; }

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.controls .primary { grid-column: 1 / -1; }

.log {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 110px;
  overflow: auto;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  width: 100%;
  max-width: 380px;
}
.modal-card h2 {
  color: var(--text);
  font-size: 18px;
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 8px;
}
.choice {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.result-line {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.result-line:last-child { border-bottom: none; }