/* ═══════════════════════════════════════════════
   TableroHouse · Mobile-first CSS
   ═══════════════════════════════════════════════ */

:root {
  --primary:        #4338ca;
  --primary-light:  #6366f1;
  --primary-dark:   #3730a3;
  --accent:         #f59e0b;
  --success:        #10b981;
  --danger:         #ef4444;
  --warning:        #f59e0b;
  --bg:             #f3f4f6;
  --surface:        #ffffff;
  --surface-2:      #f9fafb;
  --border:         #e5e7eb;
  --text:           #111827;
  --text-2:         #374151;
  --text-muted:     #9ca3af;
  --radius:         1.25rem;
  --radius-sm:      .8rem;
  --radius-lg:      1.75rem;
  --shadow:         0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:      0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:      0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
  --nav-h:          84px;
  --top-h:          64px;
  --safe-b:         env(safe-area-inset-bottom, 20px);
  --safe-t:         env(safe-area-inset-top, 30px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; image-orientation: from-image; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body { font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--text); overflow-x: hidden; line-height: 1.5; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font: inherit; }
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; object-fit: cover; }

.hidden    { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }

/* ── LOGIN ──────────────────────────────────── */
.screen-login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.25rem; position: relative; overflow: hidden; }
.login-bg { position: absolute; inset: 0; background: linear-gradient(160deg, #1e1b4b 0%, #312e81 40%, #4338ca 70%, #818cf8 100%); z-index: 0; }
.login-card { position: relative; z-index: 1; background: var(--surface); border-radius: var(--radius-lg); padding: 2rem 1.75rem; width: 100%; max-width: 400px; box-shadow: 0 25px 50px rgba(0,0,0,.35); }
.login-logo { text-align: center; margin-bottom: 2rem; }
.logo-dice { font-size: 3.5rem; display: block; margin-bottom: .5rem; }
.app-title { font-size: 1.8rem; font-weight: 800; color: var(--primary-dark); letter-spacing: -.02em; }
.app-subtitle { color: var(--text-muted); font-size: .9rem; margin-top: .25rem; }

/* ── FORMS ──────────────────────────────────── */
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; color: var(--text-2); margin-bottom: .4rem; }
.field input, .field textarea, .field select { width: 100%; padding: .75rem 1rem; border: 2px solid var(--border); border-radius: var(--radius-sm); font-size: 1rem; color: var(--text); background: var(--surface); transition: border-color .15s, box-shadow .15s; outline: none; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(67,56,202,.15); }
.field textarea { resize: vertical; min-height: 80px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

/* ── BUTTONS ────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; padding: .75rem 1.25rem; border-radius: var(--radius-sm); font-size: 1rem; font-weight: 600; transition: all .15s; cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(.97); }
.btn-secondary { background: var(--surface-2); color: var(--text-2); border: 2px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-full { width: 100%; }
.btn-sm { padding: .5rem .875rem; font-size: .875rem; }
.btn-icon { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-2); transition: background .15s; }
.btn-icon:hover { background: var(--surface-2); }
.btn-icon svg { width: 20px; height: 20px; }

/* ── ALERTS ─────────────────────────────────── */
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .9rem; margin-bottom: 1rem; }
.alert-error   { background: #fef2f2; border: 1px solid #fca5a5; color: #b91c1c; }
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.alert-info    { background: #eff6ff; border: 1px solid #93c5fd; color: #1d4ed8; }
.alert-warning { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; }

/* ── APP SHELL ──────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar { position: sticky; top: 0; z-index: 100; height: calc(var(--top-h) + var(--safe-t)); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: var(--safe-t) 1.25rem 0; gap: .75rem; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.topbar-title { flex: 1; font-size: 1.3rem; font-weight: 800; color: var(--text); letter-spacing: -0.015em; margin-top: .4rem; }

.main-content { flex: 1; padding: 1rem 1rem calc(var(--nav-h) + var(--safe-b) + 8rem); overflow-y: auto; }

.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 100; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--border); display: flex; align-items: center; box-shadow: 0 -1px 3px rgba(0,0,0,.08); }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .25rem; padding: .5rem .25rem; color: var(--text-muted); font-size: .65rem; font-weight: 500; transition: color .15s; }
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--primary); }
.nav-item:active { transform: scale(.92); }
.nav-add { color: var(--primary) !important; }
.nav-add-btn { width: 52px; height: 52px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--primary-light)); display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 16px rgba(67,56,202,.45); color: #fff; margin-top: -16px; position: relative; transition: transform .2s ease-out; }
.nav-add-btn:active { transform: scale(0.9) translateY(2px); }
.nav-add-btn::after { content: ''; position: absolute; inset: -5px; border-radius: 50%; border: 3px solid var(--primary-light); opacity: 0; animation: nav-pulse 2.5s infinite; }
@keyframes nav-pulse { 0% { transform: scale(1); opacity: .5; } 100% { transform: scale(1.4); opacity: 0; } }
.nav-add-btn svg { width: 26px; height: 26px; }
.nav-item span { font-size: 11px; margin-top: 4px; font-weight: 700; letter-spacing: 0.2px; }

/* ── CARDS ──────────────────────────────────── */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-body { padding: 1rem; }
.card-header { padding: 1rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 1rem; font-weight: 700; }

/* ── STAT CARDS ─────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1.25rem; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .25rem; }
.stat-card.accent-1 { border-left: 4px solid var(--primary); }
.stat-card.accent-2 { border-left: 4px solid var(--accent); }
.stat-card.accent-3 { border-left: 4px solid var(--success); }
.stat-card.accent-4 { border-left: 4px solid var(--danger); }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: .75rem; color: var(--text-muted); font-weight: 500; }
.stat-icon  { font-size: 1.5rem; }

/* ── GAME CARDS ─────────────────────────────── */
.games-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.game-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; cursor: pointer; transition: transform .15s, box-shadow .15s; position: relative; }
.game-card:active { transform: scale(.97); }
.game-thumb { aspect-ratio: 4/3; background: var(--surface-2); overflow: hidden; display: flex; align-items: center; justify-content: center; }
.game-thumb img { width: 100%; height: 100%; object-fit: cover; }
.game-thumb-placeholder { font-size: 3rem; color: var(--text-muted); }
.game-card-body { padding: .625rem; }
.game-card-name { font-size: .85rem; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-card-meta { font-size: .72rem; color: var(--text-muted); margin-top: .2rem; display: flex; align-items: center; gap: .4rem; }
.play-badge { position: absolute; top: .5rem; right: .5rem; background: rgba(0,0,0,.55); color: #fff; font-size: .7rem; font-weight: 700; padding: .2rem .45rem; border-radius: 99px; backdrop-filter: blur(4px); }
.never-badge { position: absolute; top: .5rem; left: .5rem; background: rgba(239,68,68,.85); color: #fff; font-size: .65rem; font-weight: 700; padding: .15rem .4rem; border-radius: 99px; }

/* ── GAME DETAIL ────────────────────────────── */
.game-hero { aspect-ratio: 16/9; background: var(--surface-2); border-radius: var(--radius); overflow: hidden; margin-bottom: 1rem; display: flex; align-items: center; justify-content: center; }
.game-hero img { width: 100%; height: 100%; object-fit: cover; }
.game-hero-placeholder { font-size: 5rem; }
.game-title { font-size: 1.4rem; font-weight: 800; margin-bottom: .5rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.chip { display: inline-flex; align-items: center; gap: .25rem; padding: .25rem .65rem; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.chip-primary { background: #ede9fe; color: var(--primary-dark); }
.chip-accent  { background: #fef3c7; color: #92400e; }
.chip-success { background: #d1fae5; color: #065f46; }
.chip-gray    { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.chip-danger  { background: #fee2e2; color: #991b1b; }
.section-title { font-size: .85rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin: 1.25rem 0 .75rem; }
.play-timeline { display: flex; flex-direction: column; gap: .5rem; }
.play-entry { background: var(--surface); border-radius: var(--radius-sm); padding: .75rem 1rem; display: flex; justify-content: space-between; align-items: center; box-shadow: var(--shadow); }
.play-entry-date { font-weight: 700; font-size: .9rem; }
.play-entry-meta { font-size: .8rem; color: var(--text-muted); }
.play-entry-del { color: var(--text-muted); padding: .25rem; border-radius: .25rem; transition: color .15s; }
.play-entry-del:hover { color: var(--danger); }

/* ── ADD/EDIT FORM ──────────────────────────── */
.photo-upload-area { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.25rem 1rem; text-align: center; background: var(--surface-2); transition: all .15s; margin-bottom: 1.5rem; position: relative; display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.photo-preview { width: 100%; border-radius: var(--radius-sm); object-fit: contain; max-height: 250px; background: #000; }
.photo-upload-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.photo-upload-text { font-size: .9rem; color: var(--text-muted); margin-bottom: .75rem; }
.photo-upload-hint { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }
/* Photo source buttons */
.photo-source-row { display: flex; gap: .6rem; justify-content: center; }
.photo-source-btn { flex: 1; max-width: 160px; display: flex; align-items: center; justify-content: center; gap: .4rem; padding: .65rem .875rem; border-radius: var(--radius-sm); font-size: .875rem; font-weight: 600; cursor: pointer; border: 2px solid var(--border); background: var(--surface); color: var(--text-2); transition: all .15s; }
.photo-source-btn:hover { border-color: var(--primary); color: var(--primary); background: #ede9fe; }
.photo-source-btn:active { transform: scale(.96); }
.photo-source-btn span { font-size: 1.1rem; }
/* Photo change bar (shown after preview) */
.photo-change-row { display: flex; gap: .4rem; justify-content: center; margin-top: .5rem; flex-wrap: wrap; }
.photo-change-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem; padding: .5rem .75rem; border-radius: var(--radius-sm); font-size: .68rem; font-weight: 700; cursor: pointer; border: 1.5px solid var(--border); background: var(--surface); color: var(--text-2); transition: all .15s; min-width: 76px; }
.photo-change-btn span, .photo-change-btn i, .photo-change-btn emoji { font-size: 1.25rem; margin-bottom: 2px; }
.photo-change-btn:hover { border-color: var(--primary); color: var(--primary); }
/* ── CROP MODAL ────────────────────────────── */
.crop-overlay { position: fixed; inset: 0; background: #000; z-index: 400; display: flex; flex-direction: column; }
.crop-header { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; background: rgba(0,0,0,.7); }
.crop-header-title { color: #fff; font-weight: 700; font-size: 1rem; }
.crop-cancel-btn { color: #aaa; font-size: .9rem; font-weight: 600; padding: .4rem .75rem; border-radius: 99px; border: 1.5px solid #444; background: transparent; cursor: pointer; }
.crop-cancel-btn:hover { color: #fff; border-color: #fff; }
.crop-viewport { flex: 1; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #111; }
.crop-img-layer { position: absolute; transform-origin: center center; }
.crop-img-layer img { display: block; user-select: none; -webkit-user-select: none; }
.crop-dim { position: absolute; inset: 0; pointer-events: none; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.55); cursor: move; touch-action: none; }
.crop-handle { position: absolute; width: 22px; height: 22px; background: #fff; border-radius: 3px; }
.crop-handle-tl { top: -11px; left: -11px; cursor: nw-resize; }
.crop-handle-tr { top: -11px; right: -11px; cursor: ne-resize; }
.crop-handle-bl { bottom: -11px; left: -11px; cursor: sw-resize; }
.crop-handle-br { bottom: -11px; right: -11px; cursor: se-resize; }
.crop-corner-l { position: absolute; top: 0; left: 0; width: 20px; height: 20px; border-top: 3px solid #fff; border-left: 3px solid #fff; }
.crop-corner-r { position: absolute; top: 0; right: 0; width: 20px; height: 20px; border-top: 3px solid #fff; border-right: 3px solid #fff; }
.crop-corner-bl2 { position: absolute; bottom: 0; left: 0; width: 20px; height: 20px; border-bottom: 3px solid #fff; border-left: 3px solid #fff; }
.crop-corner-br2 { position: absolute; bottom: 0; right: 0; width: 20px; height: 20px; border-bottom: 3px solid #fff; border-right: 3px solid #fff; }
.crop-footer { display: flex; gap: .75rem; padding: 1rem; background: rgba(0,0,0,.7); }
.crop-confirm-btn { flex: 1; padding: .875rem; border-radius: var(--radius-sm); font-size: 1rem; font-weight: 700; background: var(--primary); color: #fff; cursor: pointer; border: none; transition: background .15s; }
.crop-confirm-btn:hover { background: var(--primary-dark); }
.crop-rotate-btn { width: 50px; padding: .875rem; border-radius: var(--radius-sm); font-size: 1.2rem; background: rgba(255,255,255,.1); color: #fff; cursor: pointer; border: 1.5px solid rgba(255,255,255,.2); transition: background .15s; }
.crop-rotate-btn:hover { background: rgba(255,255,255,.2); }
.ai-analyze-bar { background: linear-gradient(135deg, #ede9fe, #ddd6fe); border-radius: var(--radius); padding: .875rem 1rem; display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.ai-analyze-bar .ai-icon { font-size: 1.5rem; }
.ai-analyze-bar .ai-text { flex: 1; }
.ai-analyze-bar .ai-title { font-size: .9rem; font-weight: 700; color: var(--primary-dark); }
.ai-analyze-bar .ai-sub   { font-size: .75rem; color: #7c3aed; }
.type-checkboxes { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .4rem; }
.type-check { display: none; }
.type-label { padding: .35rem .75rem; border-radius: 99px; border: 2px solid var(--border); font-size: .8rem; font-weight: 600; cursor: pointer; transition: all .15s; color: var(--text-2); background: var(--surface); }
.type-check:checked + .type-label { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── STATS ──────────────────────────────────── */
.period-tabs { display: flex; gap: .4rem; margin-bottom: 1.25rem; background: var(--surface-2); padding: .3rem; border-radius: var(--radius-sm); }
.period-tab { flex: 1; padding: .45rem; border-radius: .45rem; font-size: .8rem; font-weight: 600; color: var(--text-muted); transition: all .15s; text-align: center; }
.period-tab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.chart-container { background: var(--surface); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.chart-title { font-size: .9rem; font-weight: 700; margin-bottom: .75rem; }
.chart-wrap { position: relative; height: 200px; }
.sell-card { background: var(--surface); border-radius: var(--radius); padding: .875rem 1rem; box-shadow: var(--shadow); display: flex; gap: .875rem; align-items: center; margin-bottom: .6rem; }
.sell-card-img { width: 52px; height: 52px; border-radius: var(--radius-sm); object-fit: cover; background: var(--surface-2); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; }
.sell-card-info { flex: 1; min-width: 0; }
.sell-card-name { font-weight: 700; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sell-card-meta { font-size: .78rem; color: var(--text-muted); margin-top: .15rem; }
.sell-card-badge { font-size: .7rem; font-weight: 700; padding: .2rem .5rem; border-radius: 99px; white-space: nowrap; flex-shrink: 0; }

/* ── AI SUGGESTIONS ─────────────────────────── */
.ai-suggestion-card { background: linear-gradient(135deg, #1e1b4b, #4338ca); border-radius: var(--radius); color: #fff; padding: 1.25rem; margin-bottom: 1rem; }
.ai-suggestion-title { font-size: 1rem; font-weight: 700; margin-bottom: .25rem; display: flex; align-items: center; gap: .5rem; }
.ai-suggestion-item { background: rgba(255,255,255,.12); border-radius: var(--radius-sm); padding: .625rem .875rem; margin-top: .5rem; font-size: .875rem; }
.ai-suggestion-item strong { display: block; font-weight: 700; }
.ai-suggestion-item span { opacity: .85; font-size: .8rem; }

/* ── SEARCH ─────────────────────────────────── */
.search-bar { position: relative; margin-bottom: 1rem; }
.search-bar input { width: 100%; padding: .75rem 1rem .75rem 2.75rem; border: 2px solid var(--border); border-radius: var(--radius); font-size: .95rem; background: var(--surface); outline: none; transition: border-color .15s; }
.search-bar input:focus { border-color: var(--primary); }
.search-icon { position: absolute; left: .875rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-icon svg { width: 18px; height: 18px; }
.filter-chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: none; margin-bottom: 1rem; }
.filter-chips::-webkit-scrollbar { display: none; }
.filter-chip { padding: .35rem .875rem; border-radius: 99px; border: 2px solid var(--border); font-size: .8rem; font-weight: 600; white-space: nowrap; color: var(--text-2); background: var(--surface); transition: all .15s; cursor: pointer; }
.filter-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── RECENT ACTIVITY ────────────────────────── */
.recent-list { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1.5rem; }
.recent-item { display: flex; align-items: center; gap: 1rem; padding: .875rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; transition: transform .12s, box-shadow .12s; border: 2px solid transparent; }
.recent-item:active { transform: scale(.98); }
.recent-item-img { width: 70px; height: 70px; border-radius: var(--radius-sm); background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 2rem; overflow: hidden; flex-shrink: 0; }
.recent-item-img img { width: 100%; height: 100%; object-fit: cover; }
.recent-item-name { font-size: .95rem; font-weight: 800; color: var(--text); line-height: 1.2; margin-bottom: .1rem; }
.recent-item-date { font-size: .75rem; color: var(--text-muted); font-weight: 500; }

/* ── SETTINGS ───────────────────────────────── */
.settings-section { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem; overflow: hidden; }
.settings-section-title { font-size: .75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; padding: .75rem 1rem .25rem; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.settings-row { padding: 1rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 1rem; cursor: pointer; transition: background .15s; }
.settings-row:last-child { border-bottom: none; }
.settings-row:hover { background: var(--surface-2); }
.settings-row-icon { font-size: 1.5rem; flex-shrink: 0; }
.settings-row-info { flex: 1; }
.settings-row-title { font-weight: 600; font-size: .95rem; }
.settings-row-sub   { font-size: .8rem; color: var(--text-muted); margin-top: .1rem; }
.settings-row-chevron svg { width: 18px; height: 18px; color: var(--text-muted); }

/* ── MODAL ──────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: flex-end; justify-content: center; padding: 1rem; backdrop-filter: blur(2px); }
.modal-box { background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) var(--radius) var(--radius); width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; animation: slideUp .25s ease; }
@keyframes slideUp { from { transform: translateY(100px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: .75rem; }

/* ── TOAST ──────────────────────────────────── */
.toast { position: fixed; bottom: calc(var(--nav-h) + var(--safe-b) + 1rem); left: 50%; transform: translateX(-50%); z-index: 300; background: var(--text); color: #fff; padding: .75rem 1.25rem; border-radius: 99px; font-size: .9rem; font-weight: 500; box-shadow: var(--shadow-lg); white-space: nowrap; animation: fadeInUp .2s ease; }
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); color: #1c1917; }
@keyframes fadeInUp { from { transform: translateX(-50%) translateY(12px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }

/* ── LOADING ────────────────────────────────── */
.loading-spinner { display: flex; align-items: center; justify-content: center; padding: 3rem; }
.loading-spinner::after { content: ''; width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--text-muted); }
.empty-state-icon { font-size: 4rem; margin-bottom: 1rem; }
.empty-state h3   { font-size: 1.1rem; font-weight: 700; color: var(--text-2); margin-bottom: .5rem; }
.empty-state p    { font-size: .9rem; }

/* ── MISC ───────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.badge { display: inline-block; padding: .15rem .5rem; border-radius: 99px; font-size: .7rem; font-weight: 700; }
.badge-danger   { background: #fee2e2; color: var(--danger); }
.badge-success  { background: #d1fae5; color: var(--success); }
.badge-warning  { background: #fef3c7; color: #92400e; }
.badge-primary  { background: #ede9fe; color: var(--primary-dark); }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-header h2 { font-size: 1.25rem; font-weight: 800; }

/* ── PLAYER PICKER ───────────────────────── */
.pp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: .6rem; padding: .25rem 0; }
.pp-player { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .5rem .25rem; border-radius: var(--radius-sm); border: 2px solid var(--border); background: var(--surface); cursor: pointer; transition: all .15s; position: relative; }
.pp-player.selected { border-color: var(--primary); background: #ede9fe; }
.pp-player:active { transform: scale(.96); }
.pp-name { font-size: .68rem; font-weight: 600; color: var(--text-2); text-align: center; line-height: 1.2; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pp-check { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; background: var(--primary); color: #fff; border-radius: 50%; font-size: .7rem; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.pp-add-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem; padding: .5rem; border-radius: var(--radius-sm); border: 2px dashed var(--border); background: var(--surface-2); cursor: pointer; min-height: 80px; transition: all .15s; color: var(--text-muted); }
.pp-add-btn:hover { border-color: var(--primary); color: var(--primary); background: #ede9fe; }
.pp-color-swatch { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; transition: border-color .15s, transform .15s; }
.pp-color-swatch.active { border-color: var(--text); transform: scale(1.15); }
.pp-emoji-swatch.active { border-color: var(--primary); background: #ede9fe; transform: scale(1.1); }

/* ── WINNER PICKER ── */
.winner-chip { padding: .4rem .75rem; border-radius: 2rem; border: 2px solid var(--border); background: var(--surface); color: var(--text-2); font-size: .85rem; font-weight: 600; cursor: pointer; transition: all .15s; }
.winner-chip.active { border-color: #f59e0b; background: #fffbeb; color: #92400e; box-shadow: 0 2px 8px rgba(245,158,11,.2); }

/* ── LEADERBOARD ── */
.leaderboard-card { background: var(--surface); border-radius: var(--radius); border: 2px solid var(--border); overflow: hidden; margin-bottom: 2rem; }
.lb-list { display: flex; flex-direction: column; }
.lb-item { display: flex; align-items: center; gap: .75rem; padding: .875rem 1rem; border-bottom: 1px solid var(--border); }
.lb-item:last-child { border-bottom: none; }
.lb-rank { width: 24px; font-weight: 800; color: var(--text-muted); font-size: .9rem; }
.lb-info { flex: 1; min-width: 0; }
.lb-name { font-weight: 700; color: var(--text); font-size: .95rem; }
.lb-meta { font-size: .75rem; color: var(--text-muted); }
.lb-count { font-weight: 700; color: var(--primary); font-size: .85rem; background: #ede9fe; padding: .2rem .5rem; border-radius: .4rem; }

/* ── RECOMMEND BANNER (dashboard) ─────────── */
.recommend-banner { background: linear-gradient(135deg, #1e1b4b 0%, #4338ca 60%, #7c3aed 100%); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; align-items: center; gap: .875rem; cursor: pointer; margin-top: 1.25rem; transition: transform .15s, box-shadow .15s; box-shadow: 0 4px 16px rgba(67,56,202,.3); }
.recommend-banner:active { transform: scale(.98); }
.recommend-banner-icon { font-size: 2rem; flex-shrink: 0; }
.recommend-banner-text { flex: 1; }
.recommend-banner-title { color: #fff; font-size: 1rem; font-weight: 800; letter-spacing: -.01em; }
.recommend-banner-sub { color: rgba(255,255,255,.75); font-size: .78rem; margin-top: .2rem; line-height: 1.4; }

/* ── RECOMMEND VIEW ──────────────────────── */
.rec-intro { text-align: center; padding: 1.25rem 0 .75rem; }
.rec-intro-icon { font-size: 2.5rem; margin-bottom: .4rem; }
.rec-intro-text { font-size: .875rem; color: var(--text-muted); line-height: 1.5; }
.rec-section { background: var(--surface); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: .75rem; }
.rec-label { font-size: .8rem; font-weight: 700; color: var(--text-2); margin-bottom: .6rem; }
/* Number counter */
.rec-number-row { display: flex; align-items: center; gap: .75rem; }
.rec-num-btn { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--border); font-size: 1.3rem; font-weight: 700; display: flex; align-items: center; justify-content: center; color: var(--primary); background: var(--surface); transition: all .15s; }
.rec-num-btn:hover { background: #ede9fe; border-color: var(--primary); }
.rec-num-val { font-size: 1.4rem; font-weight: 800; color: var(--text); min-width: 2.5rem; text-align: center; }
.rec-clear-btn { background: var(--surface-2); border: 1.5px solid var(--border); border-radius: 99px; padding: .25rem .6rem; font-size: .75rem; color: var(--text-muted); cursor: pointer; }
.rec-clear-btn:hover { color: var(--danger); border-color: var(--danger); }
/* Chips */
.rec-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.rec-chip { padding: .4rem .875rem; border-radius: 99px; border: 2px solid var(--border); font-size: .82rem; font-weight: 600; cursor: pointer; color: var(--text-2); background: var(--surface); transition: all .15s; }
.rec-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.rec-chip:hover:not(.active) { border-color: var(--primary); color: var(--primary); }
/* Results */
.rec-results-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; font-size: .85rem; color: var(--text-muted); font-weight: 600; }
.rec-shuffle-btn { background: var(--surface-2); border: 1.5px solid var(--border); border-radius: 99px; padding: .35rem .875rem; font-size: .8rem; font-weight: 600; cursor: pointer; color: var(--text-2); transition: all .15s; }
.rec-shuffle-btn:hover { border-color: var(--primary); color: var(--primary); }
.rec-results { display: flex; flex-direction: column; gap: .625rem; }
.rec-result-card { background: var(--surface); border-radius: var(--radius); padding: .875rem; display: flex; align-items: center; gap: .875rem; cursor: pointer; box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s; border: 2px solid transparent; }
.rec-result-card:active { transform: scale(.98); }
.rec-result-card.rec-top { border-color: var(--primary); background: #fafafe; box-shadow: 0 4px 16px rgba(67,56,202,.15); }
.rec-result-img { width: 60px; height: 60px; border-radius: var(--radius-sm); overflow: hidden; flex-shrink: 0; background: var(--surface-2); display: flex; align-items: center; justify-content: center; position: relative; }
.rec-result-img img { width: 100%; height: 100%; object-fit: cover; }
.rec-img-placeholder { font-size: 1.8rem; }
.rec-top-badge { position: absolute; bottom: -2px; left: 50%; transform: translateX(-50%); background: var(--primary); color: #fff; font-size: .6rem; font-weight: 700; padding: .1rem .35rem; border-radius: 99px; white-space: nowrap; }
.rec-rank-badge { position: absolute; bottom: -2px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.5); color: #fff; font-size: .6rem; font-weight: 700; padding: .1rem .3rem; border-radius: 99px; }
.rec-result-info { flex: 1; min-width: 0; }
.rec-result-name { font-size: .95rem; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-result-meta { font-size: .75rem; color: var(--text-muted); margin-top: .15rem; }
.rec-result-reasons { font-size: .72rem; color: var(--primary); font-weight: 600; margin-top: .2rem; }
.rec-play-btn { width: 36px; height: 36px; border-radius: 50%; background: #ede9fe; border: none; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background .15s; }
.rec-play-btn:hover { background: var(--primary); color: #fff; }
.rec-empty { text-align: center; padding: 2rem 1rem; color: var(--text-muted); font-size: .9rem; line-height: 1.6; }

.ws-player:active { transform: scale(.95); }
@keyframes scaleUp {
  from { transform: scale(.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.player-score-input { border-radius: var(--radius-sm); border: 2px solid var(--border); outline: none; text-align: center; }
.player-score-input:focus { border-color: var(--primary); }
.bgg-item:hover { background: var(--primary-light) !important; color: var(--primary-dark); }

@media (min-width: 700px) {
  .main-content { max-width: 100%; padding: 2rem 3rem calc(var(--nav-h) + 6rem); }
  .bottomnav    { max-width: 500px; left: 50%; transform: translateX(calc(-50%)); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .topbar       { max-width: 100%; padding: 0 3rem; justify-content: center; }
  .topbar-title { flex: 0 1 auto; text-align: center; }
  
  .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 1.5rem; }
  .games-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1.5rem; }
  .dashboard-quick-actions { grid-template-columns: 1fr 1fr; gap: 1.5rem; }
  
  /* Log play responsive */
  #form-play { max-width: 600px; margin: 0 auto; }
  .pp-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 1rem; }
  #form-play .field-row { grid-template-columns: 1fr 1fr; gap: 1.5rem; }
}

@media (min-width: 1024px) {
  .main-content { max-width: 1200px; margin: 0 auto; padding-bottom: calc(var(--nav-h) + 8rem); }
  .topbar       { max-width: 1200px; margin: 0 auto; position: sticky; left: 0; right: 0; }
  .games-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  #form-play { max-width: 700px; }
}
