* { box-sizing: border-box; }
:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #d1d5db;
  --accent: #2563eb;
  --danger: #b91c1c;
  --ok: #047857;
  --shadow: 0 10px 30px rgba(17,24,39,0.08);
  --radius: 18px;
}
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
body { padding-bottom: calc(env(safe-area-inset-bottom) + 18px); }
.topbar { padding: 18px 16px 8px; display: flex; justify-content: space-between; align-items: start; gap: 12px; }
h1 { margin: 0; font-size: 1.5rem; }
h2, h3 { margin-top: 0; }
.subtitle { margin: 4px 0 0; color: var(--muted); }
.app-shell { max-width: 1280px; margin: 0 auto; padding: 8px 12px 24px; }
.screen { display: none; }
.screen.active { display: block; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card.muted { background: #eef2ff; }
.rules { margin: 0; padding-left: 20px; }
label { display: block; font-size: 0.95rem; margin-bottom: 12px; }
input { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-top: 6px; font-size: 16px; background: #fff; }
button { border: none; background: var(--accent); color: #fff; border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 600; cursor: pointer; }
button.secondary { background: #e5e7eb; color: #111827; }
button.danger { background: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.button-row.compact button { padding: 10px 12px; font-size: 14px; }
.divider { text-align: center; color: var(--muted); margin: 12px 0; position: relative; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); position: absolute; top: 50%; width: 36%; }
.divider::before { left: 0; }
.divider::after { right: 0; }
.small-label { display: block; color: var(--muted); font-size: 0.8rem; margin-bottom: 4px; }
.game-code { font-size: 1.6rem; font-weight: 800; letter-spacing: .08em; }
.lobby-head, .section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.status-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin-top: 12px; }
.player-list { display: grid; gap: 10px; }
.player-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.player-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; background: #dbeafe; color: #1d4ed8; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.host { background: #dcfce7; color: #047857; }
.badge.me { background: #fef3c7; color: #92400e; }
.table-wrap { overflow: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 900px; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: center; background: #fff; }
th:first-child, td:first-child { position: sticky; left: 0; z-index: 2; background: #f9fafb; text-align: left; min-width: 190px; }
thead th { position: sticky; top: 0; background: #f3f4f6; z-index: 3; }
.score-input { width: 86px; min-width: 86px; text-align: center; padding: 10px 6px; font-weight: 600; }
.readonly-cell { font-weight: 800; color: var(--ok); }
.row-muted { color: var(--muted); background: #f9fafb; }
.mobile-only { display: none; }
.desktop-only { display: block; }
.mobile-tabs { display: flex; gap: 8px; overflow: auto; padding-bottom: 6px; }
.mobile-tab { white-space: nowrap; }
.mobile-tab.active { background: #111827; color: #fff; }
.mobile-scores { display: grid; gap: 10px; }
.score-card { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.score-card h3 { margin: 0; padding: 12px 14px; background: #f9fafb; font-size: 1rem; }
.score-row { display: grid; grid-template-columns: 1.3fr .7fr; gap: 10px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); }
.score-row.computed { background: #f9fafb; }
.score-row label { margin: 0; font-size: .95rem; }
.score-row input { margin-top: 0; text-align: center; }
.dialog-form menu { display: flex; justify-content: end; gap: 10px; padding: 0; margin: 18px 0 0; }
#playerDialog { border: none; border-radius: 18px; width: min(92vw, 460px); box-shadow: var(--shadow); }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 16px); transform: translateX(-50%); background: #111827; color: #fff; padding: 12px 16px; border-radius: 999px; box-shadow: var(--shadow); z-index: 20; }
.hidden { display: none !important; }
.chip { display: inline-block; background: #dcfce7; color: #166534; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 800; }
@media (max-width: 860px) {
  .status-grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.3rem; }
  .app-shell { padding: 8px 10px 24px; }
  .card { padding: 14px; }
  .mobile-only { display: block; }
  .desktop-only { display: none; }
}


.category-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #eef2ff;
  color: #1f2937;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 700;
  width: 100%;
  text-align: left;
}
.category-btn.mobile-label {
  padding: 10px 12px;
}
.category-btn:hover {
  background: #e0e7ff;
}


.simple-list { display: grid; gap: 10px; }
.simple-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
}
.simple-item-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #111827;
  color: #fff;
  font-weight: 800;
}
.small-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 8px;
}
@media (max-width: 860px) {
  .small-grid { grid-template-columns: 1fr; }
}


.app-view { display: none; }
.app-view.active { display: block; }
.live-header { position: sticky; top: 0; z-index: 5; }
.compact-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  background: rgba(243,244,246,0.98);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 25;
}
.nav-btn {
  background: #e5e7eb;
  color: #111827;
  border-radius: 14px;
  padding: 12px 8px;
  font-size: 13px;
}
.nav-btn.active {
  background: #111827;
  color: white;
}
.menu-list {
  display: grid;
  gap: 10px;
}
@media (max-width: 860px) {
  .compact-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}


.scorebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.leader-ticker {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.35;
}
.turn-box {
  border: 1px solid var(--line);
  background: #f9fafb;
  border-radius: 14px;
  padding: 10px 12px;
  min-width: 180px;
}
.turn-info {
  font-size: 1rem;
  font-weight: 800;
}
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-top: 6px;
  font-size: 16px;
  background: #fff;
}
@media (max-width: 860px) {
  .leader-ticker { font-size: .95rem; }
  .turn-box { width: 100%; }
}


.turn-quick-btn {
  margin-top: 10px;
  width: 100%;
}
.simple-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.simple-actions button {
  padding: 8px 10px;
  font-size: 13px;
}


.profile-pill {
  display: inline-flex;
  align-items: center;
  background: #eef2ff;
  color: #1d4ed8;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}


.player-submeta {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}


.badge.active-turn {
  background: #fee2e2;
  color: #b91c1c;
}
.mobile-tab.active-turn {
  outline: 2px solid #b91c1c;
  outline-offset: 1px;
}
.score-card.active-turn {
  border: 2px solid #b91c1c;
}


.update-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  top: calc(env(safe-area-inset-top) + 10px);
  z-index: 40;
  background: #111827;
  color: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(17,24,39,0.25);
  padding: 12px 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}
.update-banner button {
  white-space: nowrap;
}
