/* Chainbloom — mobile-first, dark garden aesthetic. */

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

:root {
  --bg-top: #14202a;
  --bg-bottom: #0b0f16;
  --card: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --text: #eef3f8;
  --text-dim: #9fb0c0;
  --accent: #ff7eb6;
  --accent-2: #6ee7ff;
  --gold: #ffd166;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom) 70%);
  background-attachment: fixed;
  user-select: none;
  -webkit-user-select: none;
}

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

/* ---------- screens ---------- */
.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  padding: calc(12px + var(--safe-top)) 16px calc(12px + var(--safe-bottom));
  animation: fadein 0.25s ease;
}
.screen.active { display: flex; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.screen-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px; min-height: 44px;
}
.screen-head h2 { font-size: 22px; font-weight: 700; flex: 1; text-align: center; }
.head-meta { min-width: 44px; text-align: right; color: var(--gold); font-weight: 600; font-size: 14px; }

.btn-back {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--card-border);
  color: var(--text); font-size: 20px; cursor: pointer;
}
.btn-back:active { transform: scale(0.94); }

.scroll { overflow-y: auto; flex: 1; padding-bottom: 20px; }

/* ---------- home ---------- */
#screen-home { justify-content: center; gap: 36px; text-align: center; }
.home-hero .logo-flower {
  font-size: 64px; line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 24px rgba(255, 126, 182, 0.45));
  animation: sway 5s ease-in-out infinite;
}
@keyframes sway { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.logo {
  font-size: 44px; font-weight: 800; letter-spacing: -1px; margin-top: 8px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--text-dim); margin-top: 8px; font-size: 15px; }

.menu { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 340px; margin: 0 auto; }
.menu-row { display: flex; gap: 12px; }
.menu-row .btn { flex: 1; }

.btn {
  padding: 16px 20px; border-radius: var(--radius); border: 1px solid var(--card-border);
  background: var(--card); color: var(--text); font-size: 17px; font-weight: 600;
  cursor: pointer; transition: transform 0.08s ease, background 0.2s;
  backdrop-filter: blur(8px);
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, #ff7eb6, #b86bff);
  border: none; box-shadow: 0 6px 24px rgba(255, 126, 182, 0.35);
}
.btn-daily { background: linear-gradient(135deg, rgba(255, 209, 102, 0.25), rgba(255, 126, 182, 0.18)); }
.btn-small { padding: 12px 14px; font-size: 15px; }
.btn-danger { background: rgba(255, 77, 109, 0.18); border-color: rgba(255, 77, 109, 0.4); }
.btn:disabled { opacity: 0.45; cursor: default; }

.streak-chip {
  background: var(--gold); color: #2a1c00; font-size: 12px; font-weight: 800;
  border-radius: 20px; padding: 2px 8px; margin-left: 6px; vertical-align: 2px;
}
.petal-balance { color: var(--gold); font-weight: 700; font-size: 15px; }

/* ---------- journey ---------- */
.world-card {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.world-card.locked { opacity: 0.55; }
.world-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.world-title h3 { font-size: 18px; }
.world-title span { color: var(--text-dim); font-size: 13px; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.level-cell {
  aspect-ratio: 1; border-radius: 14px; border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.04); color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; cursor: pointer; gap: 2px;
}
.level-cell:active { transform: scale(0.94); }
.level-cell .stars { font-size: 9px; letter-spacing: 1px; color: var(--gold); }
.level-cell.locked { color: var(--text-dim); opacity: 0.5; cursor: default; }
.level-cell.cleared { border-color: rgba(255, 209, 102, 0.5); }

/* ---------- daily ---------- */
.daily-card {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 28px 22px; text-align: center; display: flex; flex-direction: column; gap: 18px;
  margin: auto 0;
}
.daily-date { font-size: 22px; font-weight: 800; color: var(--gold); }
.daily-blurb { color: var(--text-dim); font-size: 14px; }
.daily-stats { display: flex; justify-content: center; gap: 40px; }
.daily-stats .stat span { font-size: 34px; font-weight: 800; display: block; }
.daily-stats .stat label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
#daily-status { font-size: 14px; color: var(--text-dim); min-height: 18px; }

.archive-title { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; }
.archive-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.archive-chip {
  aspect-ratio: 1; border-radius: 12px; border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.04); color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; cursor: pointer; gap: 1px;
}
.archive-chip span { font-size: 13px; color: var(--text); }
.archive-chip:active { transform: scale(0.92); }
.archive-chip.won { border-color: rgba(167, 240, 112, 0.55); color: #a7f070; }
.archive-chip.lost { border-color: rgba(255, 77, 109, 0.45); color: #ff4d6d; }

/* ---------- versus ---------- */
.versus-setup { display: flex; flex-direction: column; gap: 14px; }
.versus-setup h3 { font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-top: 8px; }
.slot-row {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border: 1px solid var(--card-border); border-radius: 14px; padding: 10px 14px;
}
.slot-dot { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; }
.slot-name { flex: 1; font-weight: 600; }
.slot-row select {
  background: rgba(0, 0, 0, 0.3); color: var(--text); border: 1px solid var(--card-border);
  border-radius: 10px; padding: 8px 10px; font-size: 14px;
}
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; padding: 12px; border-radius: 12px; border: 1px solid var(--card-border);
  background: var(--card); color: var(--text-dim); font-size: 14px; font-weight: 600; cursor: pointer;
}
.seg button.active { background: rgba(110, 231, 255, 0.16); color: var(--text); border-color: var(--accent-2); }

/* ---------- editor ---------- */
#screen-editor { gap: 10px; }
#editor-board-wrap { flex: 1; position: relative; min-height: 200px; }
#editor-board { position: absolute; inset: 0; touch-action: manipulation; }

/* ---------- stats card ---------- */
.stats-card {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px;
}
.stats-card .stats-row { display: flex; justify-content: space-around; text-align: center; }
.stats-card .stat span { font-size: 22px; font-weight: 800; display: block; }
.stats-card .stat label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }

/* ---------- puzzles ---------- */
.puzzle-grid { grid-template-columns: repeat(5, 1fr); }
.level-cell .budget { font-size: 10px; color: var(--text-dim); }

/* ---------- season ---------- */
.btn-season { background: linear-gradient(135deg, rgba(167, 240, 112, 0.18), rgba(110, 231, 255, 0.14)); }
.season-progress { margin-bottom: 12px; }
.season-tier-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.xp-bar { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.xp-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.4s ease; }
#season-buy { margin-bottom: 12px; }
.tier-row {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border: 1px solid var(--card-border); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px;
  font-size: 13px;
}
.tier-row.reached { border-color: rgba(167, 240, 112, 0.4); }
.tier-row .tier-n { font-weight: 800; width: 30px; color: var(--text-dim); }
.tier-row .tier-free { flex: 1; }
.tier-row .tier-premium { flex: 1; color: var(--gold); }
.tier-row .tier-premium.locked { color: var(--text-dim); opacity: 0.6; }

/* ---------- weekly ---------- */
.weekly-blurb { color: var(--text-dim); font-size: 14px; margin-bottom: 14px; line-height: 1.5; }
.weekly-row {
  display: flex; align-items: center; gap: 12px; background: var(--card);
  border: 1px solid var(--card-border); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
}
.weekly-row .day { font-weight: 800; width: 44px; }
.weekly-row .status { flex: 1; color: var(--text-dim); font-size: 14px; }
.weekly-row .status strong { color: var(--gold); }
.weekly-row .btn { padding: 10px 16px; font-size: 14px; }
.weekly-row.done { border-color: rgba(167, 240, 112, 0.4); }

/* ---------- achievements ---------- */
.ach-row {
  display: flex; align-items: center; gap: 14px; background: var(--card);
  border: 1px solid var(--card-border); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
}
.ach-row.locked { opacity: 0.45; }
.ach-row .medal { font-size: 24px; }
.ach-row .ach-info { flex: 1; }
.ach-row h4 { font-size: 15px; }
.ach-row p { font-size: 13px; color: var(--text-dim); }
.ach-row .ach-petals { color: var(--gold); font-weight: 700; font-size: 13px; white-space: nowrap; }

/* ---------- shop ---------- */
.shop-section { font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin: 18px 0 10px; }
.shop-item {
  display: flex; align-items: center; gap: 14px; background: var(--card);
  border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
.swatch { display: flex; gap: 4px; flex-shrink: 0; }
.swatch i { width: 14px; height: 14px; border-radius: 50%; display: block; }
.shop-info { flex: 1; min-width: 0; }
.shop-info h4 { font-size: 16px; }
.shop-info p { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.shop-item .btn { padding: 10px 14px; font-size: 14px; white-space: nowrap; }
.shop-item.active-theme { border-color: var(--accent-2); }
.shop-note { font-size: 12px; color: var(--text-dim); margin-top: 16px; line-height: 1.5; }
.price-tag { color: var(--gold); font-weight: 700; }

/* ---------- wiki ---------- */
.wiki-article {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  margin-bottom: 10px; overflow: hidden;
}
.wiki-article summary {
  padding: 16px; font-weight: 700; font-size: 16px; cursor: pointer; list-style: none;
  display: flex; justify-content: space-between; align-items: center;
}
.wiki-article summary::after { content: '+'; color: var(--text-dim); font-size: 20px; }
.wiki-article[open] summary::after { content: '–'; }
.wiki-body { padding: 0 16px 16px; color: var(--text-dim); font-size: 14px; line-height: 1.65; }
.wiki-body strong { color: var(--text); }
.wiki-body ul { padding-left: 18px; margin: 8px 0; }

/* ---------- settings ---------- */
.settings-list { display: flex; flex-direction: column; gap: 14px; }
.setting-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border: 1px solid var(--card-border); border-radius: 14px;
  padding: 16px; font-weight: 600; cursor: pointer;
}
.setting-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.setting-row input[type="text"] {
  background: rgba(0, 0, 0, 0.3); color: var(--text); border: 1px solid var(--card-border);
  border-radius: 10px; padding: 8px 10px; font-size: 14px; width: 150px; text-align: right;
}

/* ---------- leaderboard modal ---------- */
.lb-list { text-align: left; max-height: 40vh; overflow-y: auto; }
.lb-row { display: flex; gap: 10px; padding: 7px 4px; font-size: 14px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.lb-row .lb-rank { width: 34px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.lb-row .lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .lb-score { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-row.me { background: rgba(110, 231, 255, 0.08); border-radius: 8px; }
.about { color: var(--text-dim); font-size: 12px; text-align: center; margin-top: 20px; line-height: 1.6; }

/* ---------- game ---------- */
#screen-game { padding: calc(8px + var(--safe-top)) 10px calc(8px + var(--safe-bottom)); }
.game-head { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.game-title { flex: 1; text-align: center; font-weight: 700; font-size: 16px; }
.game-moves { min-width: 60px; text-align: right; font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

#hud-players { display: flex; gap: 8px; justify-content: center; margin: 8px 0; flex-wrap: wrap; }
.hud-chip {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 20px;
  background: var(--card); border: 1px solid var(--card-border);
  font-size: 13px; font-weight: 600; transition: all 0.2s;
}
.hud-chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.hud-chip.current { border-color: currentcolor; box-shadow: 0 0 12px -2px currentcolor; }
.hud-chip.dead { opacity: 0.35; text-decoration: line-through; }
.hud-chip .cellcount { color: var(--text-dim); font-variant-numeric: tabular-nums; }

#board-wrap { flex: 1; position: relative; min-height: 0; }
#board { position: absolute; inset: 0; touch-action: manipulation; }

.turn-banner {
  text-align: center; font-size: 14px; font-weight: 600; color: var(--text-dim);
  min-height: 22px; padding: 4px;
}

/* ---------- modal ---------- */
.modal-backdrop[hidden], .toast[hidden] { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5, 8, 12, 0.7); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px;
  animation: fadein 0.25s ease;
}
.modal-card {
  background: linear-gradient(180deg, #1b2734, #121a24);
  border: 1px solid var(--card-border); border-radius: 24px;
  padding: 28px 24px; width: 100%; max-width: 360px; text-align: center;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-card h2 { font-size: 26px; }
.modal-card .big-stars { font-size: 34px; letter-spacing: 6px; }
.modal-card .reward { color: var(--gold); font-weight: 700; font-size: 18px; }
.modal-card p { color: var(--text-dim); font-size: 14px; line-height: 1.5; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: calc(30px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: rgba(20, 28, 38, 0.95); border: 1px solid var(--card-border);
  color: var(--text); padding: 12px 20px; border-radius: 30px; font-size: 14px; font-weight: 600;
  z-index: 60; animation: fadein 0.2s ease; max-width: 90%; text-align: center;
}

@media (min-width: 561px) {
  #app { border-left: 1px solid var(--card-border); border-right: 1px solid var(--card-border); }
}
