:root {
  --bg: #ffffff;
  --bg2: #f4f5f7;
  --text: #14171c;
  --hint: #6c7480;
  --line: #d7dbe1;
  --line-strong: #9aa3ae;
  --btn: #2f7cf6;
  --btn-text: #ffffff;
  --card: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.08);
  --radius: 16px;
  --filled: #14171c;
  --mark: #98a2b3;
  --accent-soft: rgba(47, 124, 246, 0.12);
  --danger: #d92d20;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17212b;
    --bg2: #1f2a36;
    --text: #eef2f6;
    --hint: #9aa7b4;
    --line: #33414f;
    --line-strong: #4d5f70;
    --btn: #4b8cf7;
    --btn-text: #ffffff;
    --card: #1f2a36;
    --shadow: none;
    --filled: #e9eef4;
    --mark: #6f8090;
    --accent-soft: rgba(75, 140, 247, 0.18);
    --danger: #ff6b5e;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; overflow-x: hidden; }

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
}

#bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 6px;
  min-height: 44px;
}

#bar h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
#bar .grow { flex: 1; }
#bar .muted { color: var(--hint); font-size: 13px; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 4px 16px calc(16px + env(safe-area-inset-bottom));
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  min-height: 52px;
  padding: 0 18px;
  font-size: 17px;
  font-weight: 600;
  background: var(--bg2);
  color: var(--text);
  width: 100%;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.06s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.985); }
.btn.primary { background: var(--btn); color: var(--btn-text); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { min-height: 44px; font-size: 15px; padding: 0 14px; width: auto; }
.btn[disabled] { opacity: 0.45; }
.btn.danger { color: var(--danger); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0 0 12px;
}
.card h2 { font-size: 15px; margin: 0 0 10px; font-weight: 650; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

.diffs { display: grid; gap: 10px; margin-bottom: 14px; }
.diff {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 16px;
  background: var(--card); cursor: pointer; text-align: left;
  color: var(--text); font-family: inherit; font-size: 16px; width: 100%;
}
.diff b { font-weight: 650; }
.diff .sz { color: var(--hint); font-size: 13px; }
.diff .dot { width: 10px; height: 10px; border-radius: 50%; }
.diff:active { background: var(--bg2); }

.game-row { padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; background: var(--card); }
.game-row .top { display: flex; align-items: baseline; gap: 8px; }
.game-row .t { font-weight: 650; }
.game-row .meta { color: var(--hint); font-size: 13px; margin-top: 2px; }
.game-row .actions { display: flex; gap: 8px; margin-top: 10px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg2); color: var(--hint); }
.badge.on { background: var(--accent-soft); color: var(--btn); }

/* ---- board ---- */
.room-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.room-head .title { font-weight: 650; font-size: 16px; }
.progress { height: 6px; border-radius: 999px; background: var(--bg2); overflow: hidden; margin: 6px 0 4px; }
.progress > i { display: block; height: 100%; background: var(--btn); width: 0; transition: width 0.25s ease; }
.progress-label { display: flex; justify-content: space-between; color: var(--hint); font-size: 12.5px; }

.board-scroll { flex: 1; min-height: 0; min-width: 0; display: flex; align-items: flex-start; justify-content: center; overflow: auto; padding: 8px 0 4px; }
.board {
  display: grid;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.cell, .clue { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cell { background: var(--card); position: relative; cursor: pointer; }
.cell.blk-r { border-right-color: var(--line-strong); }
.cell.blk-b { border-bottom-color: var(--line-strong); }
.cell.filled { background-color: var(--filled); }
.cell.owned.filled { background-image: linear-gradient(var(--tint), var(--tint)); }
.cell.owned.crossed { background-image: linear-gradient(var(--tint-soft), var(--tint-soft)); }
.cell.filled::after { content: ''; position: absolute; inset: 0; }
.cell.crossed::before, .cell.crossed::after {
  content: '';
  position: absolute; left: 22%; right: 22%; top: 50%;
  height: 1.5px; background: var(--mark); border-radius: 2px;
}
.cell.crossed::before { transform: rotate(45deg); }
.cell.crossed::after { transform: rotate(-45deg); }

.clue { display: flex; align-items: center; justify-content: center; overflow: hidden; }
.clue.top { border-bottom-color: var(--line-strong); flex-direction: column; justify-content: flex-end; padding-bottom: 3px; }
.clue.left { border-right-color: var(--line-strong); flex-direction: row; justify-content: flex-end; padding-right: 4px; }
.clue span { color: var(--hint); line-height: 1.15; font-variant-numeric: tabular-nums; }
.clue span.done { color: var(--line-strong); text-decoration: line-through; opacity: 0.6; }
.clue.left span + span { margin-left: 5px; }
.corner { border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }

.controls { display: grid; gap: 8px; padding-top: 8px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode {
  min-height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px; font-family: inherit;
}
.mode.on { border-color: var(--btn); background: var(--accent-soft); color: var(--btn); }
.mode .sw { width: 18px; height: 18px; border-radius: 4px; border: 1px solid currentColor; }
.mode .sw.fill { background: currentColor; }
.mode .sw.cross { position: relative; }
.mode .sw.cross::before, .mode .sw.cross::after {
  content: ''; position: absolute; left: 2px; right: 2px; top: 50%; height: 1.5px; background: currentColor;
}
.mode .sw.cross::before { transform: rotate(45deg); }
.mode .sw.cross::after { transform: rotate(-45deg); }
.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.acts .btn { min-height: 46px; font-size: 14px; padding: 0 6px; background: var(--card); border: 1px solid var(--line); }

.online { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--hint); }
.online i { width: 7px; height: 7px; border-radius: 50%; background: var(--hint); }
.online.live i { background: #31c48d; }

/* ---- overlays ---- */
.sheet {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(10, 14, 20, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px;
}
.sheet .panel {
  background: var(--bg); border-radius: 20px; padding: 20px;
  width: 100%; max-width: 480px; box-shadow: var(--shadow);
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.sheet h2 { margin: 0 0 8px; font-size: 20px; }
.sheet p { margin: 0 0 10px; color: var(--hint); }
.emphasis { color: var(--text); font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #14171c; color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: 90vw; transition: 0.2s ease; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.skeleton { color: var(--hint); padding: 40px 0; text-align: center; }
