:root {
  --ink: #232946;
  --ink-soft: #5a607e;
  --bg: #f7f7fb;
  --card: #ffffff;
  --red: #e63946;
  --green: #2a9d8f;
  --line: #e4e5ef;
  --radius: 16px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 680px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen { display: none; flex: 1; flex-direction: column; min-height: 0; }
.screen.active { display: flex; }
.hidden { display: none !important; }
.muted { color: var(--ink-soft); font-size: 14px; }

/* ---------- icons ---------- */
.icon { width: 1.1em; height: 1.1em; flex: none; display: inline-block; vertical-align: -0.2em; }
.icon-success { color: var(--green); }
.icon-danger { color: var(--red); }
.card-icon { margin: 0 auto; }
.card-icon svg { width: 52px; height: 52px; display: block; }

/* ---------- buttons ---------- */
.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--ink); color: #fff; box-shadow: 0 4px 14px rgba(35, 41, 70, .25); }
.btn-primary:disabled { background: #b9bccd; box-shadow: none; cursor: default; }
.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn .icon { margin-right: 8px; }
.btn-big { font-size: 18px; padding: 14px 22px; width: 100%; }
.icon-btn {
  border: 0; background: transparent; color: var(--ink);
  width: 42px; height: 42px; border-radius: 50%; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn .icon { width: 22px; height: 22px; }
.icon-btn:active { background: var(--line); }

/* ---------- home ---------- */
#screen-home { padding: 16px 20px 24px; gap: 18px; overflow-y: auto; }

.home-top { display: flex; justify-content: space-between; align-items: center; }
.lives-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 7px 14px; font-weight: 700; font-size: 15px;
}
.lives-pill .heart { color: var(--red); display: inline-flex; }
.lives-pill .heart .icon { width: 16px; height: 16px; }
.lives-timer { font-weight: 500; font-size: 12px; color: var(--ink-soft); }
.name-pill {
  background: var(--card); border: 1.5px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-weight: 600; font-size: 14px; color: var(--ink);
  cursor: pointer; font-family: inherit; max-width: 55%; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

.logo { text-align: center; margin-top: 4px; }
.logo h1 { font-size: 40px; letter-spacing: 1px; margin-top: 2px; }
.tagline { color: var(--ink-soft); font-size: 14px; margin-top: 2px; }

.home-level-card {
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 20px; text-align: center; display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 6px 24px rgba(35, 41, 70, .06);
}
.hl-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--ink-soft); }
.hl-level { font-size: 46px; font-weight: 800; line-height: 1; }
.hl-diff { font-size: 14px; font-weight: 600; color: var(--green); margin-bottom: 8px; }
.no-lives-hint { font-size: 13px; color: var(--red); margin-top: 6px; }

.home-stats { display: flex; gap: 12px; }
.stat {
  flex: 1; background: var(--card); border: 1.5px solid var(--line);
  border-radius: var(--radius); padding: 14px; text-align: center;
}
.stat-v { font-size: 24px; font-weight: 800; }
.stat-l { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

.home-nav { display: flex; flex-direction: column; gap: 10px; }
.offline-note {
  text-align: center; font-size: 13px; color: #b26a00;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.offline-note .icon { width: 15px; height: 15px; }

/* ---------- game ---------- */
#screen-game { min-height: 0; }
.game-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; gap: 8px;
}
.game-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.diff-chip {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  background: var(--line); color: var(--ink-soft); border-radius: 999px; padding: 3px 9px;
}
.hearts { display: flex; gap: 4px; }
.hearts span { color: var(--red); transition: color .2s, transform .2s; display: inline-flex; }
.hearts span .icon { width: 21px; height: 21px; }
.hearts span.lost { color: #d4d5e0; transform: scale(.85); }

#board-wrap { flex: 1; min-height: 0; position: relative; }
#board { display: block; touch-action: none; cursor: pointer; }

/* ---------- sub screens ---------- */
.sub-top { display: flex; align-items: center; gap: 8px; padding: 12px 14px 6px; }
.sub-top h2 { font-size: 20px; }

.tabs { display: flex; gap: 8px; padding: 10px 20px; flex-wrap: wrap; }
.tab {
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink-soft);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab .icon { width: 14px; height: 14px; margin: 0; }
.tab.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.lb-list { overflow-y: auto; padding: 6px 20px 24px; display: flex; flex-direction: column; gap: 8px; }
.lb-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 10px 14px;
}
.lb-row.me { border-color: var(--ink); box-shadow: 0 2px 10px rgba(35, 41, 70, .12); }
.lb-rank { font-weight: 800; width: 34px; text-align: center; font-size: 15px; }
.lb-rank .icon { width: 22px; height: 22px; }
.lb-rank.top1 { color: #d4a017; }
.lb-rank.top2 { color: #8c9bab; }
.lb-rank.top3 { color: #b26a00; }
.lb-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-level { font-size: 12px; color: var(--ink-soft); }
.lb-score { font-weight: 800; }
.lb-empty { text-align: center; color: var(--ink-soft); padding: 30px 10px; font-size: 14px; }

/* ---------- groups ---------- */
.group-actions { padding: 10px 20px; display: flex; flex-direction: column; gap: 10px; }
.row-form { display: flex; gap: 8px; }
.row-form input {
  flex: 1; border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 14px;
  font-size: 15px; font-family: inherit; background: var(--card); color: var(--ink);
  min-width: 0;
}
.row-form input:focus, .col-form input:focus { outline: 2px solid var(--ink); border-color: transparent; }

.group-list { overflow-y: auto; padding: 8px 20px 24px; display: flex; flex-direction: column; gap: 10px; }
.group-card {
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.group-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.group-name { font-weight: 700; font-size: 16px; }
.group-code {
  font-family: ui-monospace, Consolas, monospace; font-weight: 700; letter-spacing: 2px;
  background: var(--bg); border: 1px dashed var(--ink-soft); border-radius: 8px;
  padding: 3px 8px; font-size: 13px; cursor: pointer;
}
.group-meta { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.group-btns { display: flex; gap: 8px; margin-top: 10px; }
.group-btns .btn { padding: 8px 14px; font-size: 13px; }
.btn-danger-ghost { background: transparent; border: 1.5px solid #f2c4c8; color: var(--red); }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(35, 41, 70, .45);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  backdrop-filter: blur(3px);
}
.card {
  background: var(--card); border-radius: 20px; padding: 26px 22px;
  width: 100%; max-width: 340px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
  animation: pop .22s ease-out;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.score-gain { font-size: 26px; font-weight: 800; color: var(--green); }
.score-total { font-size: 14px; color: var(--ink-soft); }

.col-form { display: flex; flex-direction: column; gap: 10px; }
.col-form input {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px;
  font-size: 16px; font-family: inherit; text-align: center; background: var(--bg); color: var(--ink);
}
.code-input {
  font-family: ui-monospace, Consolas, monospace; letter-spacing: 6px;
  text-transform: uppercase; font-weight: 700; font-size: 20px !important;
}

/* ---------- toast ---------- */
.toast {
  position: absolute; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: var(--ink); color: #fff; border-radius: 999px;
  padding: 11px 20px; font-size: 14px; font-weight: 600; z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
  animation: toast-in .25s ease-out; max-width: 85%; text-align: center;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes toast-in { from { transform: translate(-50%, 16px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
