/* ============ Schulte Grid — styles ============ */
:root {
  --bg: #eef2fb;
  --card: #ffffff;
  --ink: #1c2433;
  --muted: #6b7688;
  --line: #e3e8f2;
  --primary: #4f7cff;
  --primary-dark: #3560e0;
  --accent: #ff8a3d;
  --ok: #22b573;
  --bad: #e5484d;
  --warn: #f5a524;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(28, 36, 51, .08);
  --tap: rgba(79, 124, 255, .12);
  font-size: 16px;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background:
    radial-gradient(1200px 500px at 80% -10%, #dfe8ff 0%, transparent 60%),
    radial-gradient(900px 420px at -10% 110%, #ffe8d6 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 6px;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 13px;
  background: linear-gradient(135deg, var(--primary), #6e9bff);
  color: #fff; font-weight: 800; font-size: 1.35rem;
  display: grid; place-items: center;
  box-shadow: 0 8px 18px rgba(79, 124, 255, .35);
}
.brand-text h1 { font-size: 1.15rem; letter-spacing: .2px; }
.brand-sub { font-size: .74rem; color: var(--muted); }

/* ---------- Layout ---------- */
#main {
  flex: 1;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 16px 26px;
}
.view { display: none; animation: fade .22s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 14px;
}
.card h2 { font-size: 1.25rem; margin-bottom: 6px; }
.card h3 { font-size: 1.02rem; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: .9rem; line-height: 1.55; }
.center { text-align: center; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

.hero { text-align: center; }
.hero .muted { margin: 6px auto 18px; max-width: 460px; }

/* ---------- Buttons ---------- */
.btn {
  border: 0; cursor: pointer; font: inherit; font-weight: 600;
  border-radius: 14px; padding: 12px 18px;
  transition: transform .12s ease, box-shadow .12s ease, background .15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { transform: scale(.96); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #6a8dff);
  color: #fff;
  box-shadow: 0 10px 22px rgba(79, 124, 255, .32);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); }
.btn-soft { background: var(--tap); color: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-danger { background: #fdecec; color: var(--bad); }
.btn-xl { width: 100%; padding: 16px; font-size: 1.12rem; margin-top: 16px; }
.menu-row {
  display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center; margin: 14px 0;
}
.menu-row .btn { flex: 1 1 auto; min-width: 130px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.ico { font-size: 1.05rem; }

/* ---------- Grid size choices ---------- */
.grid-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 12px;
}
.choice {
  background: #f5f8ff;
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 16px 8px;
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s, transform .12s;
}
.choice:hover { transform: translateY(-2px); }
.choice.selected {
  border-color: var(--primary);
  background: #e8eeff;
}
.choice .n { font-size: 1.55rem; font-weight: 800; color: var(--primary-dark); line-height: 1.1; }
.choice .lbl { font-size: .78rem; color: var(--muted); margin-top: 4px; }

/* ---------- Game ---------- */
.game-top {
  display: flex; gap: 10px; justify-content: center;
  margin-bottom: 14px; flex-wrap: wrap;
}
.stat-pill {
  background: var(--card); border-radius: 14px;
  padding: 10px 18px; text-align: center;
  box-shadow: var(--shadow); min-width: 96px;
}
.stat-label { display: block; font-size: .72rem; color: var(--muted); margin-bottom: 2px; letter-spacing: .3px; }
.stat-pill strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }

.board-wrap { position: relative; display: flex; justify-content: center; }
.board {
  display: grid;
  gap: 8px;
  width: min(92vw, 520px);
  padding: 10px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.cell {
  aspect-ratio: 1 / 1;
  border: 0; border-radius: 14px;
  background: #f2f5fd;
  color: var(--ink);
  font-weight: 700;
  font-size: clamp(1.05rem, 5.2vw, 1.75rem);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform .1s ease, background .15s, color .15s, opacity .2s;
}
.cell:active { transform: scale(.93); }
.cell.done {
  background: #e2f6ec;
  color: var(--ok);
  opacity: .45;
  transform: scale(.92);
}
.cell.good { background: var(--ok); color: #fff; }
.cell.bad { background: var(--bad); color: #fff; animation: shake .3s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.countdown {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(238, 242, 251, .82);
  border-radius: 20px;
  z-index: 5;
}
.countdown span {
  font-size: clamp(4rem, 18vw, 7rem);
  font-weight: 800; color: var(--primary);
  animation: pop .9s ease infinite;
}
@keyframes pop {
  0% { transform: scale(.6); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.25); opacity: 0; }
}
.hidden { display: none !important; }

.game-actions { display: flex; gap: 10px; justify-content: center; margin: 16px 0 6px; }

/* ---------- Result ---------- */
.result-card { text-align: center; }
.stars { font-size: 2.2rem; letter-spacing: 6px; margin-bottom: 6px; min-height: 2.6rem; }
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px; margin: 18px 0 6px;
}
.result-item {
  background: #f5f8ff; border-radius: 14px; padding: 14px 10px;
}
.result-item strong {
  display: block; font-size: 1.35rem; margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.badge {
  display: inline-block; margin-top: 12px;
  background: #fff3dd; color: #c77c11;
  padding: 8px 16px; border-radius: 999px; font-weight: 700;
}

/* ---------- Stats ---------- */
.best-list { display: grid; gap: 10px; }
.best-row {
  display: flex; align-items: center; justify-content: space-between;
  background: #f5f8ff; border-radius: 12px; padding: 12px 16px;
}
.best-row .size { font-weight: 800; color: var(--primary-dark); min-width: 64px; }
.best-row .val { font-variant-numeric: tabular-nums; font-weight: 700; }
.best-row .val .sub { display: block; font-size: .74rem; color: var(--muted); font-weight: 500; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; }
.table td { font-variant-numeric: tabular-nums; }

/* ---------- Settings / forms ---------- */
.form-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.form-row label { font-weight: 600; min-width: 96px; }
.form-row input[type="email"],
.form-row input[type="text"] {
  flex: 1 1 200px;
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px; font: inherit; background: #fafbff;
}
.form-row input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.seg { display: inline-flex; background: #eef2fb; border-radius: 12px; padding: 4px; }
.seg-btn {
  border: 0; background: transparent; cursor: pointer;
  padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; color: var(--muted);
}
.seg-btn.active { background: #fff; color: var(--primary-dark); box-shadow: 0 3px 10px rgba(28,36,51,.1); }

/* switch */
.switch { position: relative; width: 52px; height: 30px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: #cdd5e4;
  border-radius: 999px; cursor: pointer; transition: .2s;
}
.slider::before {
  content: ""; position: absolute; width: 24px; height: 24px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* ---------- Sync ---------- */
.sync-block { margin: 10px 0; }
.code-display { margin-top: 14px; text-align: center; }
.code {
  font-size: 2.4rem; font-weight: 800; letter-spacing: 10px;
  color: var(--primary-dark);
  background: #eef2fb; border-radius: 16px; padding: 18px 12px;
  font-variant-numeric: tabular-nums;
}
.sync-status {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
}
#input-code { text-transform: uppercase; letter-spacing: 3px; font-weight: 700; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: #1c2433; color: #fff;
  padding: 12px 22px; border-radius: 999px;
  font-size: .92rem; font-weight: 600;
  box-shadow: 0 12px 30px rgba(0,0,0,.25);
  z-index: 50; max-width: 88vw; text-align: center;
  animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Footer ---------- */
.app-footer {
  text-align: center; padding: 14px 16px 22px; font-size: .78rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .board { gap: 6px; padding: 8px; }
  .cell { border-radius: 11px; }
  .menu-row .btn { min-width: 100%; }
  .code { letter-spacing: 6px; font-size: 1.9rem; }
}
