:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #687386;
  --line: #d9e0ea;
  --blue: #246bfe;
  --blue-soft: #dbe7ff;
  --red: #e5484d;
  --red-soft: #ffe1e2;
  --green: #0f8b5f;
  --shadow: 0 18px 45px rgba(35, 45, 65, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

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

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

.join-panel {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 28px;
  align-items: center;
  min-height: calc(100vh - 56px);
  padding: 36px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  max-width: 680px;
  font-size: clamp(2rem, 6vw, 4.4rem);
  line-height: 1;
}

h2 {
  font-size: 1.9rem;
}

.intro {
  max-width: 560px;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.6;
}

.rules-panel {
  max-width: 640px;
  margin-top: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  background: #fff;
}

.rules-panel h2 {
  margin-bottom: 10px;
  font-size: 1.15rem;
}

.rules-panel ol {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.45;
}

.join-form {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  color: var(--text);
  background: #fff;
  outline: none;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

.mode-row,
.action-row {
  display: flex;
  gap: 10px;
}

.mode-button,
.primary-button,
.ghost-button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
}

.mode-button {
  flex: 1;
  color: var(--muted);
  background: #fff;
}

.mode-button.active {
  color: var(--blue);
  border-color: var(--blue);
  background: var(--blue-soft);
}

.primary-button {
  flex: 1;
  color: #fff;
  border-color: var(--blue);
  background: var(--blue);
}

.ghost-button {
  color: var(--text);
  background: #fff;
}

.small-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.84rem;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 0.9rem;
  font-weight: 800;
}

.account-status {
  min-height: 20px;
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

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

.leaderboard-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-weight: 900;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
}

.leaderboard-list li {
  padding-left: 4px;
}

.leaderboard-list li::marker {
  color: var(--blue);
  font-weight: 900;
}

.leaderboard-list span {
  color: var(--text);
  font-weight: 800;
}

.leaderboard-list strong {
  float: right;
  color: var(--green);
  font-size: 0.9rem;
}

.game-panel {
  padding: 24px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.status-box {
  min-width: 230px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.game-actions {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.danger-button {
  min-height: 44px;
  border: 1px solid var(--red);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--red);
  background: var(--red-soft);
  cursor: pointer;
  font-weight: 800;
}

.players {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

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

.player.active {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 139, 95, 0.14);
}

.player-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
}

.dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--blue);
}

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

.player-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}

.sync-panel {
  min-height: 44px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--muted);
  background: #fff;
  font-size: 0.92rem;
  font-weight: 800;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 22px;
  align-items: start;
  min-width: 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(100%, 620px);
  aspect-ratio: 1;
  margin: 0 auto;
  border: 3px solid #1f2937;
  background: #1f2937;
  gap: 1px;
}

.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  border: 0;
  background: #ffffff;
  cursor: default;
  position: relative;
}

.cell.zone-alt {
  background: #f7f9fd;
}

.cell:nth-child(3n) {
  border-right: 2px solid #1f2937;
}

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid #1f2937;
}

.cell.legal {
  cursor: pointer;
  background: #f6fbff;
}

.cell.zone-alt.legal {
  background: #eef7ff;
}

.cell.preview {
  box-shadow: inset 0 0 0 2px rgba(15, 139, 95, 0.16);
}

.cell.bad-preview {
  box-shadow: inset 0 0 0 2px rgba(229, 72, 77, 0.28);
}

.cell.legal::after {
  content: "";
  width: 24%;
  height: 24%;
  border-radius: 50%;
  background: rgba(15, 139, 95, 0.35);
}

.block {
  width: 72%;
  height: 72%;
  border-radius: 7px;
  background: var(--block-color, var(--blue));
  box-shadow:
    inset 5px 5px 0 rgba(255, 255, 255, 0.32),
    inset -5px -6px 0 rgba(0, 0, 0, 0.18),
    0 5px 10px rgba(15, 23, 42, 0.16);
}

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

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

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

.piece-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 82px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  background: #fff;
  cursor: pointer;
  font-weight: 900;
  text-align: left;
  min-width: 0;
  touch-action: none;
  user-select: none;
}

.piece-card.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

.piece-card:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.piece-grid {
  display: grid;
  gap: 3px;
  min-width: 54px;
  min-height: 54px;
}

.mini-block,
.mini-empty {
  width: 18px;
  height: 18px;
}

.mini-block {
  border-radius: 4px;
  background: var(--block-color, var(--blue));
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.34),
    inset -3px -4px 0 rgba(0, 0, 0, 0.18);
}

.mini-empty {
  opacity: 0;
}

.drag-ghost {
  position: fixed;
  z-index: 20;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.24);
  pointer-events: none;
  transform: scale(1.18);
}

.drag-ghost.invalid {
  border-color: var(--red);
  box-shadow: 0 18px 36px rgba(229, 72, 77, 0.26);
}

.drag-ghost .mini-block,
.drag-ghost .mini-empty {
  width: 22px;
  height: 22px;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .app {
    padding: 14px;
  }

  .join-panel {
    grid-template-columns: 1fr;
    align-content: center;
    min-height: calc(100vh - 28px);
    padding: 22px;
  }

  .game-header {
    align-items: stretch;
    flex-direction: column;
  }

  .status-box {
    min-width: 0;
  }

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

  .players {
    grid-template-columns: 1fr;
  }

  .play-area {
    grid-template-columns: 1fr;
  }

  .piece-card {
    grid-template-columns: 1fr;
  }
}
