* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --purple: #8B2AB8; --purple-dark: #6B1F8E;
  --teal: #2AC4B8; --teal-light: #C8F0EE;
  --orange: #F5A623; --white: #FFFFFF;
  --text-dark: #1A1A2E; --text-gray: #555;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { to { transform: scale(1.2) rotate(10deg); } }
@keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }

body { font-family: 'Nunito', sans-serif; background: white; min-height: 100vh; overflow-x: hidden; }
.screen { display: none; flex-direction: column; min-height: 100vh; position: fixed; inset: 0; overflow-y: auto; }
.screen.active { display: flex; }

/* HEADER */
.app-header { background: var(--purple); height: 54px; padding: 0 12px; display: flex; align-items: center; justify-content: space-between; position: relative; flex-shrink: 0; gap: 8px; }
.app-header h1 { color: white; font-size: 1.15rem; font-weight: 900; letter-spacing: 2px; text-transform: uppercase; flex: 1; text-align: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hdr-left { background: none; border: none; color: white; font-size: 0.85rem; font-weight: 800; cursor: pointer; padding: 4px; flex-shrink: 0; white-space: nowrap; }
.hdr-right-btn { display: none; }
.teal-bar { height: 7px; background: var(--teal); flex-shrink: 0; }

/* AUTH */
.auth-container { max-width: 400px; width: 100%; margin: 0 auto; padding: 24px 24px 40px; }
#auth-screen { background: linear-gradient(160deg, #C8F5F0 0%, #A8EEE8 50%, #C8F5F0 100%); min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; }
.auth-logo { text-align: center; margin-bottom: 20px; margin-top: 20px; }
.auth-tabs { display: flex; background: rgba(255,255,255,0.5); border-radius: 14px; padding: 4px; margin-bottom: 20px; }
.auth-tab { flex: 1; padding: 10px; border: none; background: transparent; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 0.9rem; color: #888; border-radius: 10px; cursor: pointer; transition: all 0.2s; }
.auth-tab.active { background: white; color: var(--purple); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.auth-field { margin-bottom: 14px; }
.auth-field label { display: block; font-size: 0.78rem; font-weight: 800; color: #666; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.auth-field input { width: 100%; padding: 13px 14px; border-radius: 12px; border: 2px solid rgba(255,255,255,0.7); background: white; font-family: 'Nunito', sans-serif; font-size: 1rem; font-weight: 700; color: var(--text-dark); outline: none; transition: border 0.2s; }
/* Password field wrapper */
.password-wrap { position: relative; }
.password-wrap input { padding-right: 44px; }
.show-pw-btn { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; font-size: 1.1rem; color: #aaa; padding: 4px; line-height: 1; }
.auth-btn { width: 100%; padding: 14px; border-radius: 14px; border: none; background: var(--purple); color: white; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 1rem; cursor: pointer; margin-top: 8px; transition: opacity 0.2s; letter-spacing: 0.5px; }
.auth-btn:active { opacity: 0.85; }
.auth-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-link { display: block; width: 100%; text-align: center; background: none; border: none; color: var(--purple); font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 0.85rem; cursor: pointer; margin-top: 12px; padding: 8px; }
.auth-error { color: #C0392B; font-size: 0.82rem; font-weight: 700; margin: 6px 0; min-height: 20px; }
.auth-fine-print { text-align: center; font-size: 0.78rem; color: #888; font-weight: 600; margin-top: 10px; }

/* PAYWALL */
#paywall-screen { background: #F4F0F8; }
.plan-card { background: white; border-radius: 18px; padding: 20px; border: 2px solid #E0D0F0; position: relative; }
.plan-name { font-size: 0.85rem; font-weight: 800; color: #888; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 4px; }
.plan-price { font-size: 2.2rem; font-weight: 900; color: var(--purple); margin-bottom: 14px; }
.plan-price span { font-size: 1rem; font-weight: 700; color: #aaa; }
.plan-save { font-size: 0.78rem; font-weight: 700; color: var(--teal); margin-bottom: 10px; }
.plan-badge { position: absolute; top: -10px; right: 16px; background: var(--teal); color: white; font-size: 0.68rem; font-weight: 800; padding: 3px 10px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.5px; }

/* PROFILES */
#profiles-screen { background: #F4F0F8; }
.profiles-body { flex: 1; padding: 24px 20px 30px; overflow-y: auto; }
.profiles-grid { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; align-items: flex-start; }
.profile-card { background: white; border-radius: 20px; padding: 20px 12px 16px; text-align: center; cursor: pointer; box-shadow: 0 2px 12px rgba(0,0,0,0.08); border: 2px solid transparent; transition: transform 0.15s, box-shadow 0.15s; position: relative; animation: fadeIn 0.3s ease; width: 160px; flex-shrink: 0; }
.profile-card:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(0,0,0,0.13); }
.profile-card:active { transform: scale(0.96); }
.profile-avatar { width: 80px; height: 80px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.9rem; font-weight: 900; color: white; margin: 0 auto 12px; box-shadow: 0 3px 10px rgba(0,0,0,0.2); }
.profile-name { font-size: 1.15rem; font-weight: 800; color: var(--text-dark); margin-bottom: 4px; line-height: 1.2; }
.profile-type { font-size: 0.85rem; font-weight: 700; color: white; padding: 4px 12px; border-radius: 10px; display: inline-block; }
.profile-type.kids { background: var(--teal); }
.profile-type.adults { background: var(--purple); }
.profile-card-actions { display: flex; gap: 6px; margin-top: 12px; }
.profile-action-btn { flex: 1; padding: 9px 4px; border-radius: 10px; border: none; font-family: 'Nunito', sans-serif; font-size: 0.85rem; font-weight: 800; cursor: pointer; transition: background 0.15s; }
.profile-action-btn.hist { background: #E8F4FF; color: #3A7BD5; }
.profile-action-btn.edit { background: #F0E8F8; color: var(--purple); }
.add-profile-card { background: white; border-radius: 20px; padding: 20px 12px 16px; text-align: center; cursor: pointer; box-shadow: 0 2px 12px rgba(0,0,0,0.06); border: 2px dashed #C4A8E0; transition: transform 0.15s; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 160px; width: 160px; flex-shrink: 0; }
.add-profile-card:hover { border-color: var(--purple); transform: translateY(-3px); }
.add-icon { width: 80px; height: 80px; border-radius: 50%; background: #F0E8F8; display: flex; align-items: center; justify-content: center; font-size: 2rem; color: var(--purple); margin-bottom: 12px; }
.add-label { font-size: 0.9rem; font-weight: 800; color: var(--purple); }

/* MODAL */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: white; border-radius: 24px; padding: 28px 24px; width: 100%; max-width: 380px; box-shadow: 0 16px 48px rgba(0,0,0,0.25); }
.modal h2 { font-size: 1.3rem; font-weight: 900; color: var(--text-dark); margin-bottom: 20px; text-align: center; }
.modal-field { margin-bottom: 16px; }
.modal-field label { display: block; font-size: 0.8rem; font-weight: 800; color: #888; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.modal-field input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 2px solid #E0E0E0; font-family: 'Nunito', sans-serif; font-size: 1rem; font-weight: 700; color: var(--text-dark); outline: none; transition: border 0.2s; }
.modal-field input:focus { border-color: var(--purple); }
.type-toggle { display: flex; gap: 10px; }
.type-btn { flex: 1; padding: 10px; border-radius: 12px; border: 2px solid #E0E0E0; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 0.9rem; cursor: pointer; background: white; color: #888; transition: all 0.15s; }
.type-btn.selected { border-color: var(--purple); background: #F0E8F8; color: var(--purple); }
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch { width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; transition: transform 0.15s; }
.color-swatch.selected { border-color: #333; transform: scale(1.15); }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-btn { flex: 1; padding: 13px; border-radius: 12px; border: none; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 0.95rem; cursor: pointer; }
.btn-cancel { background: #eee; color: #555; }
.btn-save { background: var(--purple); color: white; }
.btn-delete { background: #ffeef5; color: #C0392B; border: 2px solid #ffcce0; }

/* HISTORY / ANALYTICS */
#history-screen { background: #F4F0F8; }
.history-body { flex: 1; overflow-y: auto; padding: 16px 14px 24px; }
.history-user-row { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.history-avatar { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; font-weight: 900; color: white; flex-shrink: 0; }
.history-username { font-size: 1.61rem; font-weight: 900; color: var(--text-dark); }
.stat-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; margin-bottom: 16px; }
.stat-card { background: white; border-radius: 16px; padding: 14px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); text-align: center; }
.stat-value { font-size: 2.53rem; font-weight: 900; line-height: 1; }
.stat-label { font-size: 0.98rem; font-weight: 800; color: #aaa; letter-spacing: 1px; text-transform: uppercase; margin-top: 4px; }
.stat-card.purple .stat-value { color: var(--purple); }
.stat-card.teal .stat-value { color: var(--teal); }
.stat-card.orange .stat-value { color: var(--orange); }
.stat-card.green .stat-value { color: #1E7A30; }
.analytics-section-title { font-size: 1.01rem; font-weight: 900; color: #aaa; letter-spacing: 1.5px; text-transform: uppercase; margin: 18px 0 8px; }
.seq-analytics-card { background: white; border-radius: 16px; padding: 14px; margin-bottom: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.seq-analytics-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.seq-analytics-name { font-size: 1.26rem; font-weight: 800; color: var(--text-dark); flex: 1; margin-right: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seq-status-tag { font-size: 0.94rem; font-weight: 800; padding: 3px 8px; border-radius: 8px; white-space: nowrap; flex-shrink: 0; }
.seq-status-tag.mastered { background: #E8F8EE; color: #1E7A30; }
.seq-status-tag.improving { background: #E8F0FF; color: #3A7BD5; }
.seq-status-tag.needs-work { background: #FFF3E0; color: #E65100; }
.seq-status-tag.attempted { background: #F4F0F8; color: var(--purple); }
.sparkline-row { display: flex; align-items: flex-end; gap: 3px; height: 32px; margin-bottom: 6px; }
.spark-bar { flex: 1; border-radius: 3px 3px 0 0; min-width: 6px; }
.spark-bar.perfect { background: #4CAF50; }
.spark-bar.good { background: #8BC34A; }
.spark-bar.mid { background: var(--orange); }
.spark-bar.low { background: #EF5350; }
.seq-analytics-meta { display: flex; gap: 14px; flex-wrap: wrap; }
.seq-meta-item { font-size: 1.03rem; font-weight: 700; color: #888; }
.seq-meta-item span { color: var(--text-dark); font-weight: 900; }
.history-entry { background: white; border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); display: flex; align-items: center; gap: 12px; }
.history-score-badge { width: 74px; height: 74px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 900; flex-shrink: 0; }
.history-score-badge.perfect { background: #E8F8EE; color: #1E7A30; }
.history-score-badge.partial { background: #FFF3E0; color: #E65100; }
.history-score-num { font-size: 1.61rem; line-height: 1; }
.history-score-label { font-size: 0.86rem; opacity: 0.7; margin-top: 2px; }
.history-info { flex: 1; min-width: 0; }
.history-seq-name { font-size: 1.21rem; font-weight: 800; color: var(--text-dark); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-date { font-size: 1.01rem; color: #bbb; font-weight: 600; }
.history-perfect-star { color: #F5A623; margin-left: 4px; }
.history-empty { text-align: center; padding: 50px 20px; color: #bbb; font-size: 1.09rem; font-weight: 700; }
.history-clear-btn { display: block; margin: 20px auto 0; padding: 10px 24px; border-radius: 20px; border: 2px solid #ffcce0; background: #ffeef5; color: #C0392B; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 0.98rem; cursor: pointer; }
.analytics-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.analytics-tab { flex: 1; padding: 11px; border-radius: 10px; border: 2px solid #E0D0F0; background: white; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 1.15rem; color: #aaa; cursor: pointer; transition: all 0.15s; }
.analytics-tab.active { background: var(--purple); border-color: var(--purple); color: white; }

/* SEQUENCE SELECT */
#seq-screen { background: white; }
.seq-body { flex: 1; padding: 16px 12px 20px; overflow-y: auto; }
.seq-who { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.seq-who-avatar { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1rem; font-weight: 900; color: white; }
.seq-who-name { font-size: 1.2rem; font-weight: 900; color: var(--orange); letter-spacing: 1px; text-transform: uppercase; }
.seq-scroll { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 14px; }
.seq-card { cursor: pointer; transition: transform 0.15s; animation: fadeIn 0.2s ease; }
.seq-card:active { transform: scale(0.95); }
.seq-img-wrap { width: 100%; aspect-ratio: 1; border-radius: 12px; border: 6px solid #2E8B3A; overflow: hidden; background: #f5f5f5; display: flex; align-items: center; justify-content: center; font-size: 4rem; margin-bottom: 7px; }
.seq-img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.seq-name { text-align: center; font-size: 1rem; font-weight: 700; color: var(--text-dark); line-height: 1.3; }
.seq-steps { text-align: center; font-size: 0.9rem; color: var(--text-gray); font-weight: 600; }

/* GAME */
#game-screen { background: #f4f4f4; }
.game-body { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
.slots-zone { background: white; padding: 6px 8px; border-bottom: 2px solid #e0e0e0; flex-shrink: 0; }
.slots-label { font-size: 1.1rem; font-weight: 900; color: #444; letter-spacing: 0.5px; text-transform: uppercase; margin-bottom: 8px; text-align: center; }
.slots-row { display: grid; gap: 6px; padding-bottom: 2px; justify-content: center; justify-items: center; }
.slot { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.slot-num { width: 24px; height: 24px; border-radius: 50%; background: var(--purple); color: white; font-size: 0.75rem; font-weight: 900; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.slot-box { width: 100%; aspect-ratio: 1; border-radius: 10px; border: 3px dashed #bbb; background: #fafafa; display: flex; align-items: center; justify-content: center; font-size: 0.65rem; color: #bbb; font-weight: 700; text-align: center; padding: 4px; position: relative; overflow: hidden; transition: border-color 0.2s, background 0.2s; }
.slot-box.drag-over { border-color: var(--purple); background: #f3e8ff; }
.slot-box.correct { border-color: #1E7A30; background: #4CAF50; border-style: solid; box-shadow: 0 0 0 3px #1E7A30; }
.slot-box.correct::after { content: '✓'; position: absolute; top: 3px; right: 5px; font-size: 1rem; font-weight: 900; color: white; text-shadow: 0 1px 3px rgba(0,0,0,0.4); }
.slot-box.wrong { border-color: #bbb; background: #fafafa; border-style: dashed; }
.slot-box.wrong::after { content: ''; }
.slot-box img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.slot-box .slot-emoji { font-size: 2.5rem; }
.slot-lbl { font-size: 0.85rem; font-weight: 700; color: #555; text-align: center; line-height: 1.2; margin-top: 3px; }
.text-hidden .slot-lbl { display: none; }
.text-hidden .bank-card-lbl { visibility: hidden; height: 0; padding: 0; }
.slot-remove { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,0.6); color: white; font-size: 0.8rem; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; font-weight: 900; }
.bank-zone { flex: 1; overflow-y: auto; padding: 6px 8px; min-height: 0; }
.bank-grid { display: grid; gap: 6px; justify-content: center; align-content: start; }
.bank-card { background: white; border-radius: 10px; border: 4px solid #2E8B3A; overflow: hidden; cursor: grab; user-select: none; touch-action: none; transition: transform 0.15s, opacity 0.2s; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.bank-card.dragging { opacity: 0.3; transform: scale(0.95); }
.bank-card.placed { display: none; }
.bank-card-img { width: 100%; aspect-ratio: 1; background: #f5f5f5; display: flex; align-items: center; justify-content: center; font-size: 3rem; overflow: hidden; }
.bank-card-img img { width: 100%; height: 100%; object-fit: cover; }
.bank-card-lbl { padding: 6px 4px; font-size: 0.85rem; font-weight: 700; color: var(--text-dark); text-align: center; line-height: 1.2; background: white; }
.result-banner { display: none; padding: 14px 16px; text-align: center; font-weight: 800; font-size: 1.4rem; flex-shrink: 0; }
.result-banner.show { display: block; }
.result-banner.all-correct { background: #4CAF50; color: white; }
.result-banner.some-wrong { background: #FFF8E1; color: #E65100; }
.try-again-row { display: none; padding: 6px 10px 0; flex-shrink: 0; text-align: center; }
.try-again-row.show { display: block; }
.btn-try-again { padding: 11px 32px; border-radius: 12px; border: 2px solid var(--purple); background: white; color: var(--purple); font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 0.95rem; cursor: pointer; }
.check-row { padding: 8px 10px; background: white; border-top: 1px solid #eee; flex-shrink: 0; display: flex; gap: 8px; }
.check-btn { flex: 1; padding: 10px; border-radius: 12px; border: none; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 0.95rem; cursor: pointer; }
.btn-check { background: var(--purple); color: white; flex: 2; }
.btn-home { background: #eee; color: #555; }

/* RESULTS MODAL */
.results-overlay { display: none; position: fixed; inset: 0; background: rgba(139,42,184,0.85); z-index: 200; align-items: center; justify-content: center; padding: 24px; }
.results-overlay.open { display: flex; }
.results-modal { background: white; border-radius: 28px; padding: 36px 28px; width: 100%; max-width: 340px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.3); animation: popIn 0.4s cubic-bezier(0.175,0.885,0.32,1.275); }
@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.results-star { font-size: 5rem; line-height: 1; margin-bottom: 4px; }
.results-title { font-size: 2.2rem; font-weight: 900; color: var(--purple); margin: 8px 0 4px; }
.results-sub { font-size: 1.05rem; font-weight: 700; color: #666; margin-bottom: 8px; }
.results-stars { font-size: 2rem; letter-spacing: 6px; margin-bottom: 24px; }
.results-btn { display: block; width: 100%; padding: 14px; margin: 8px 0; border-radius: 16px; border: none; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 1.05rem; cursor: pointer; }
.rbtn-again { background: var(--purple); color: white; }
.rbtn-seqs { background: var(--teal); color: white; }
.rbtn-home { background: #eee; color: #555; }

/* TOGGLES */
.text-toggle { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.toggle-label { color: rgba(255,255,255,0.85); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.5px; text-transform: uppercase; white-space: nowrap; }
.toggle-switch { position: relative; width: 38px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track { position: absolute; inset: 0; background: rgba(255,255,255,0.3); border-radius: 22px; cursor: pointer; transition: background 0.2s; border: 2px solid rgba(255,255,255,0.5); }
.toggle-track::after { content: ''; position: absolute; width: 16px; height: 16px; left: 1px; top: 1px; background: white; border-radius: 50%; transition: transform 0.2s; }
.toggle-switch input:checked + .toggle-track { background: var(--teal); border-color: var(--teal); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(16px); }

/* DRAG GHOST */
#drag-ghost { position: fixed; pointer-events: none; z-index: 9999; width: 90px; height: 90px; border-radius: 10px; border: 4px solid var(--purple); background: white; overflow: hidden; display: none; box-shadow: 0 8px 24px rgba(0,0,0,0.3); transform: rotate(3deg); }
#drag-ghost img { width: 100%; height: 100%; object-fit: cover; }

/* Sort buttons */
.sort-btn { padding: 7px 20px; border-radius: 20px; border: 2px solid #C4A8E0; background: white; color: #8B2AB8; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 0.9rem; cursor: pointer; transition: all 0.15s; }
.sort-btn.active { background: #8B2AB8; color: white; border-color: #8B2AB8; }
