*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0b1020;
  --panel: #141b2f;
  --border: #2a3555;
  --text: #e8eefc;
  --muted: #8b9bb8;
  --accent: #5b8cff;
  --danger: #ff5c7a;
  --ok: #3dd68c;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html,
body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 800px at 50% -10%, #1a2450 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

.app {
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.header h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(90deg, #7aa2ff, #b8f0ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.status-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  font-size: 0.7rem;
  color: var(--muted);
  border: 1px solid var(--border);
  background: rgba(20, 27, 47, 0.8);
  border-radius: 999px;
  padding: 4px 8px;
}

.pill.online {
  color: var(--ok);
  border-color: rgba(61, 214, 140, 0.35);
}

.pill.offline {
  color: #ffcc66;
  border-color: rgba(255, 204, 102, 0.35);
}

.pill.update {
  color: var(--accent);
  border-color: rgba(91, 140, 255, 0.45);
  cursor: pointer;
}

.btn-pill {
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-pill.off {
  color: var(--danger);
  border-color: rgba(255, 92, 122, 0.4);
  opacity: 0.85;
}

.account-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(20, 27, 47, 0.75);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
}

.account-label {
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn.tiny {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.8rem;
}

.auth-panel,
.play-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(100%, 300px);
}

.auth-panel[hidden],
.play-panel[hidden],
.stats-panel[hidden],
.auth-error[hidden] {
  display: none !important;
}

.auth-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.google-btn {
  min-height: 44px;
  display: flex;
  justify-content: center;
  width: 100%;
}

.auth-hint,
.auth-error {
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted);
  text-align: center;
}

.auth-error {
  color: var(--danger);
}

.stats-panel {
  width: 100%;
  background: rgba(10, 14, 26, 0.55);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: left;
  line-height: 1.45;
}

.stats-panel strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 10px;
  align-items: start;
}

.board-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

#board {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: #0a0e1a;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat,
.preview {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  text-align: center;
}

.stat .label,
.preview .label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat .value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.1rem;
}

#next {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
}

.overlay {
  position: absolute;
  inset: 8px;
  border-radius: 10px;
  background: rgba(8, 12, 24, 0.82);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  padding: 16px;
  z-index: 2;
}

.board-wrap {
  position: relative;
}

.overlay.visible {
  display: flex;
}

.overlay h2 {
  font-size: 1.4rem;
}

.overlay p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #2a3a66, #1c2744);
  color: var(--text);
  font-weight: 700;
  font-size: 0.95rem;
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.98);
  filter: brightness(1.1);
}

.btn.primary {
  background: linear-gradient(180deg, #4f7dff, #355fd6);
  border-color: #6b93ff;
}

.btn.ghost {
  background: transparent;
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: auto;
}

.controls .btn {
  min-height: 56px;
  font-size: 1.25rem;
  line-height: 1;
}

.controls .wide {
  grid-column: span 2;
}

.hint {
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  line-height: 1.35;
}

@media (min-width: 520px) {
  .app {
    width: 480px;
  }

  .layout {
    grid-template-columns: 1fr 96px;
  }
}
