:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-soft: #475569;
  --muted: #94a3b8;
  --line: #e2e8f0;
  --teal: #0ea5b7;
  --teal-deep: #0b7c8a;
  --indigo: #6366f1;
  --amber: #f59e0b;
  --good: #16a34a;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, 0.35), transparent 60%),
    radial-gradient(1000px 500px at -10% 10%, rgba(14, 165, 183, 0.35), transparent 55%),
    linear-gradient(180deg, #0b1220, #131c31 60%, #0b1220);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px;
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(11, 18, 32, 0.65);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { font-size: 26px; }
.brand-name {
  font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 20px;
  color: #fff; letter-spacing: 0.2px;
}
.topnav { display: flex; gap: 10px; }

/* ---- buttons ---- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 0; border-radius: 999px; padding: 10px 18px;
  text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--teal), var(--indigo)); color: #fff; box-shadow: 0 6px 16px rgba(99,102,241,.35); }
.btn-primary:hover { box-shadow: 0 8px 22px rgba(99,102,241,.5); }
.btn-ghost { background: rgba(255,255,255,.08); color: #e2e8f0; }
.btn-ghost:hover { background: rgba(255,255,255,.16); }
.btn-light { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.btn-light:hover { background: #f1f5f9; }
.btn-danger { background: rgba(239,68,68,.12); color: #fecaca; }
.btn-danger:hover { background: rgba(239,68,68,.2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- layout ---- */
main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 28px 22px 56px; }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 22px; }

/* ---- hero ---- */
.hero { text-align: center; color: #fff; margin: 10px 0 30px; }
.hero h1 { font-family: 'Fredoka', sans-serif; font-size: clamp(32px, 6vw, 52px); margin: 0 0 10px; line-height: 1.05; }
.hero p { color: #cbd5e1; font-size: 17px; max-width: 560px; margin: 0 auto 22px; }
.hero .cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---- card gallery ---- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 30px 0 14px; }
.section-head h2 { color: #fff; font-family: 'Fredoka', sans-serif; margin: 0; font-size: 22px; }
.section-head .count { color: var(--muted); font-size: 14px; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card-tile {
  background: var(--panel); border-radius: var(--radius); padding: 18px;
  text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,.5);
  display: flex; flex-direction: column; gap: 10px;
  transition: transform .12s ease, box-shadow .15s ease;
  position: relative; overflow: hidden;
}
.card-tile:hover { transform: translateY(-3px); box-shadow: 0 16px 36px rgba(15,23,42,.22); }
.card-tile .tile-title { font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 19px; line-height: 1.15; }
.card-tile .tile-meta { color: var(--ink-soft); font-size: 13px; }
.tile-mini { display: grid; gap: 3px; margin-top: 4px; padding: 6px; border-radius: 8px; background: linear-gradient(135deg, var(--teal), var(--indigo)); }
.tile-mini-cell {
  aspect-ratio: 1; border-radius: 4px; background: #fff; color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 2px; overflow: hidden; line-height: 1.08; word-break: break-word; hyphens: auto;
}
.tile-mini-cell span {
  display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden;
}
.tile-mini-cell.free { background: linear-gradient(135deg, #fde68a, #fcd34d); color: #78350f; font-weight: 700; }
.tile-mini.s3 .tile-mini-cell { font-size: 9px; -webkit-line-clamp: 4; }
.tile-mini.s4 .tile-mini-cell { font-size: 7px; -webkit-line-clamp: 4; }
.tile-mini.s5 .tile-mini-cell { font-size: 6px; -webkit-line-clamp: 3; }
.badge { position: absolute; top: 12px; right: 12px; background: var(--amber); color: #422006; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---- home live checklist ---- */
.checklist-panel { margin-bottom: 10px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-head h2 { font-family: 'Fredoka', sans-serif; margin: 0 0 2px; font-size: 22px; }
.home-checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 2px 14px; }
.home-checklist .check-item { font-size: 14px; }
.phrase-count { color: var(--muted); font-weight: 400; white-space: nowrap; }

/* ---- create form ---- */
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px; }
.panel h1 { font-family: 'Fredoka', sans-serif; margin: 0 0 4px; font-size: 26px; }
.panel .sub { color: var(--ink-soft); margin: 0 0 22px; }
.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.field .hint { color: var(--muted); font-weight: 400; font-size: 13px; }
.input, .textarea {
  width: 100%; font: inherit; padding: 11px 13px; border: 1.5px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,165,183,.15); }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 180px; }

.size-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.size-opt { flex: 1; min-width: 90px; cursor: pointer; }
.size-opt input { position: absolute; opacity: 0; }
.size-opt .chip {
  display: block; text-align: center; padding: 12px; border-radius: 12px;
  border: 1.5px solid var(--line); font-weight: 600; transition: all .15s;
}
.size-opt .chip small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.size-opt input:checked + .chip { border-color: var(--teal); background: linear-gradient(135deg, rgba(14,165,183,.1), rgba(99,102,241,.1)); box-shadow: 0 0 0 3px rgba(14,165,183,.12); }

.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--teal); }

.squares-grid { display: grid; gap: 8px; margin-top: 6px; }
.square-input {
  resize: none; min-height: 64px; font-size: 13px; line-height: 1.3; padding: 8px;
  border: 1.5px solid var(--line); border-radius: 10px; font-family: inherit; text-align: center;
  display: flex; transition: border-color .15s, box-shadow .15s;
}
.square-input:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.square-free { display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #fde68a, #fcd34d); border: 1.5px dashed #d97706; border-radius: 10px; font-weight: 700; color: #78350f; font-size: 13px; }

.form-actions { display: flex; gap: 12px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.form-msg { font-weight: 600; }
.form-msg.error { color: #dc2626; }

/* ---- play view ---- */
.play-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.play-title { color: #fff; }
.play-title h1 { font-family: 'Fredoka', sans-serif; margin: 0; font-size: 28px; line-height: 1.1; }
.play-title .meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.play-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.play-layout { display: grid; grid-template-columns: 1fr 320px; gap: 22px; align-items: start; }

.board-wrap { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.board {
  display: grid; gap: 8px;
  background: linear-gradient(135deg, var(--teal), var(--indigo));
  padding: 10px; border-radius: 12px;
}
.cell {
  aspect-ratio: 1; border: 0; border-radius: 9px; background: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 6px; font: inherit; font-weight: 600; color: var(--ink-soft);
  line-height: 1.18; overflow: hidden; word-break: break-word;
  transition: transform .08s ease, background .15s, color .15s, box-shadow .15s;
}
.cell .cell-text { display: block; }
.cell:hover { box-shadow: inset 0 0 0 2px rgba(99,102,241,.4); }
.cell.marked { background: linear-gradient(135deg, var(--good), #15803d); color: #fff; box-shadow: inset 0 0 0 2px rgba(255,255,255,.25); }
.cell.marked::after { content: '✓'; position: absolute; }
.cell.free { background: linear-gradient(135deg, #fde68a, #fcd34d); color: #78350f; cursor: default; }
.cell.win { animation: pop .5s ease; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.08); } 100% { transform: scale(1); } }

/* size-responsive font for cells */
.board.s3 .cell { font-size: clamp(13px, 2.4vw, 19px); }
.board.s4 .cell { font-size: clamp(11px, 1.8vw, 15px); }
.board.s5 .cell { font-size: clamp(9px, 1.5vw, 13px); }

.side {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; position: sticky; top: 86px;
}
.side h3 { margin: 0 0 4px; font-family: 'Fredoka', sans-serif; font-size: 18px; }
.side .side-sub { color: var(--ink-soft); font-size: 13px; margin: 0 0 12px; }
.checklist { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.check-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 9px 8px; border-radius: 10px;
  cursor: pointer; font-size: 14px; line-height: 1.25; transition: background .12s;
}
.check-item:hover { background: #f1f5f9; }
.check-item input { margin-top: 2px; width: 18px; height: 18px; accent-color: var(--good); flex-shrink: 0; }
.check-item.done span { text-decoration: line-through; color: var(--muted); }
.progress { margin-top: 12px; font-size: 13px; color: var(--ink-soft); }
.progress-bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 6px; }
.progress-bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--indigo)); width: 0; transition: width .3s ease; }

.bingo-banner {
  margin-bottom: 18px; padding: 16px 20px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--amber), #f97316); color: #422006;
  font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 20px;
  display: none; align-items: center; gap: 12px; box-shadow: var(--shadow);
}
.bingo-banner.show { display: flex; animation: drop .4s ease; }
@keyframes drop { from { transform: translateY(-12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; display: none; }
#confetti.go { display: block; }

.loading { text-align: center; color: var(--muted); padding: 40px; }

@media (max-width: 820px) {
  .play-layout { grid-template-columns: 1fr; }
  .side { position: static; }
  .checklist { max-height: none; }
}
