.hidden { display: none !important; }
.signout-btn { margin-top: 1.25rem; width: 100%; }

:root {
    --bg: #f0f2f5;
    --panel-bg: rgba(255, 255, 255, 0.9);
    --text: #1e293b;
    --tile-bg: #ffffff;
    --tile-border: #cbd5e1;
    --correct: #10b981;
    --present: #eab308;
    --absent: #94a3b8;
    --accent: #3b82f6;
    --shadow-deep: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.05);
    --inner-glow: inset 0 1px 1px rgba(255,255,255,0.8);
    --radius: 16px;
}

body.theme-dark {
    --bg: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.8);
    --text: #f8fafc;
    --tile-bg: #1e293b;
    --tile-border: #334155;
    --absent: #64748b;
    --shadow-deep: 0 20px 25px -5px rgba(0,0,0,0.4), 0 10px 10px -5px rgba(0,0,0,0.3);
}


body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    transition: background 0.4s ease;
}

* { -webkit-tap-highlight-color: transparent; }

.container {
    position: relative;
    background: var(--panel-bg);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-deep);
    border: 1px solid rgba(255,255,255,0.1);
    box-sizing: border-box;
    width: 90%;
    max-width: 400px;
    text-align: center;
}

/* Frosted blur is the biggest paint cost on iOS Safari — restrict to
   pointer-capable devices so touch screens stay snappy. */
@media (hover: hover) and (pointer: fine) {
    .container { backdrop-filter: blur(12px); }
    .modal { backdrop-filter: blur(12px); }
}

/* Animations */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

.tile.correct { background: var(--correct); color: white; border-color: var(--correct); }
.tile.present { background: var(--present); color: #1e293b; border-color: var(--present); }

/* Top action buttons */
.top-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-bottom: 0.5rem;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--tile-border);
    background: var(--tile-bg);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover { background: var(--tile-border); }

.help-btn { font-weight: 800; font-size: 1rem; }

/* Theme switcher */
.theme-switcher { display: flex; justify-content: center; gap: 10px; }
.theme-btn {
    background: var(--tile-bg);
    border: 1.5px solid var(--tile-border);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text);
    transition: all 0.2s;
}
.theme-btn:hover { background: var(--tile-border); }
.theme-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--panel-bg);
    border-radius: var(--radius);
    padding: 2rem;
    width: 90%;
    max-width: 320px;
    position: relative;
    box-shadow: var(--shadow-deep);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal h2 {
    margin: 0 0 1.25rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text);
    opacity: 0.5;
    line-height: 1;
}
.modal-close:hover { opacity: 1; }

/* Login form */
.modal-form { display: flex; flex-direction: column; gap: 0; }

.modal-input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--tile-border);
    background: var(--tile-bg);
    color: var(--text);
    font-size: 0.85rem;
    margin-bottom: 10px;
    box-sizing: border-box;
    outline: none;
    font-family: inherit;
}
.modal-input:focus { border-color: var(--accent); }

.modal-error {
    color: #c0392b;
    font-size: 0.8rem;
    margin: 0.5rem 0 0;
    text-align: center;
}
/* Neutral counterpart to .modal-error — used for the password-reset
   confirmation, which must NOT read as a failure. */
.modal-notice {
    font-size: 0.8rem;
    margin: 0.5rem 0 0;
    text-align: center;
    opacity: 0.85;
}
.modal-link-btn {
    display: block;
    margin: 0.5rem auto 0;
    padding: 0;
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    font-size: 0.75rem;
    opacity: 0.7;
    text-decoration: underline;
    cursor: pointer;
}
.modal-link-btn:hover { opacity: 1; }
.modal-footer-text {
    font-size: 0.75rem;
    opacity: 0.7;
    margin: 1rem 0 0;
    text-align: center;
}
.modal-footer-text a { color: var(--accent); text-decoration: none; }

/* Settings */
.settings-section { margin-bottom: 1rem; }
.settings-label {
    font-size: 0.7rem;
    font-weight: 700;
    opacity: 0.5;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
    text-align: left;
}

/* Help */
.help-content p, .help-content ol {
    font-size: 0.85rem;
    text-align: left;
    line-height: 1.6;
    margin: 0 0 0.75rem;
}
.help-content ol { padding-left: 1.2rem; }

.help-legend {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    font-size: 0.8rem;
}

.help-tile {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.8rem;
    color: white;
    flex-shrink: 0;
    position: relative;
}
.help-tile.correct { background: var(--correct); }
.help-tile.present { background: var(--present); color: #1e293b; }
.help-tile.absent { background: var(--absent); }

.help-note {
    font-size: 0.78rem !important;
    opacity: 0.7;
    margin: 0.75rem 0 1rem !important;
}

.header-meta { font-size: 0.9rem; font-weight: 800; color: var(--text); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.05em; }
h1 { margin: 0 0 8px 0; font-size: 1.5rem; }

.nav-tabs { display: flex; justify-content: center; gap: 20px; margin-bottom: 25px; border-bottom: 1px solid var(--tile-border); padding-bottom: 10px; }
.nav-link { cursor: pointer; font-weight: 700; font-size: 0.8rem; opacity: 0.7; }
.nav-link.active { opacity: 1; color: var(--accent); }

#grid.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 25px;
    touch-action: none;
}

#grid.grid-4 .tile { font-size: 1.4rem; }

.tile {
    aspect-ratio: 1/1;
    background: var(--tile-bg);
    border: 1px solid var(--tile-border);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: var(--inner-glow), 0 4px 6px rgba(0,0,0,0.05);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    transition: transform 0.1s;
    position: relative;
}

/* Keyboard focus ring for roving-tabindex navigation. :focus-visible (not
   :focus) so the ring shows for keyboard nav but not after a mouse click —
   which otherwise leaves a ring lingering on the tile after a swap. */
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.tile.correct { background: var(--correct); color: white; border-color: var(--correct); }
.tile.present { background: var(--present); color: #1e293b; border-color: var(--present); }
.tile.absent { background: var(--absent); color: white; border-color: var(--absent); opacity: 0.85; }

/* Non-color feedback badges — ensures graded states are distinguishable
   without relying on hue alone (WCAG 1.4.1). */
.tile.correct::after,
.tile.present::after,
.tile.absent::after {
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 0.82rem;
    opacity: 0.95;
    font-weight: 900;
    line-height: 1;
}
.tile.correct::after { content: '\2713'; } /* ✓ */
.tile.present::after { content: '\2194'; } /* ↔ */
.tile.absent::after  { content: '\2715'; } /* ✕ */

/* Match badges in help legend tiles */
.help-tile.correct::after,
.help-tile.present::after,
.help-tile.absent::after {
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 0.82rem;
    opacity: 0.95;
    font-weight: 900;
    line-height: 1;
}
.help-tile.correct::after { content: '\2713'; }
.help-tile.present::after { content: '\2194'; }
.help-tile.absent::after  { content: '\2715'; }
.tile.selected { border: 3px solid var(--accent); background: rgba(59, 130, 246, 0.15); color: var(--text); opacity: 1; }
/* Gate hover behind a real hovering pointer so touch devices don't get a
   grey background stuck on the last-tapped tile (mobile emulates :hover on
   tap and leaves it until you tap elsewhere). */
@media (hover: hover) {
    .tile:not(.correct):not(.present):not(.absent):not(.revealed):hover { background: var(--tile-border); transition: background 0.15s; }
}
.tile:not(.correct):not(.present):not(.absent):not(.revealed):active { transform: scale(0.88); }
.tile.drag-over { border: 3px solid var(--accent); background: rgba(59, 130, 246, 0.15); opacity: 1; }
.tile-drag-source { opacity: 0.25; transition: opacity 0.1s; }
.tile-ghost {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    will-change: transform;
    transition: none !important;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.35) !important;
    margin: 0;
}


#main-content-wrapper {
    height: 460px; /* Fixed height for absolute stability */
    padding: 10px;
    box-sizing: border-box;
}

@media (max-height: 680px) {
    #main-content-wrapper { height: 420px; }
}

.archive-view {
    display: none;
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Calendar archive view (plan 20 Part B) */
.calendar-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.calendar-nav-btn {
    background: var(--tile-bg);
    border: 1px solid var(--tile-border);
    color: var(--text);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}
.calendar-nav-btn:hover:not(:disabled) { background: var(--tile-border); }
.calendar-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.calendar-month-label {
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.7;
}
.calendar-weekday-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 4px;
}
.calendar-weekday {
    text-align: center;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.5;
}
.calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    padding-bottom: 14px;
}
.calendar-cell {
    aspect-ratio: 1 / 1;
    background: var(--tile-bg);
    border: 2px solid var(--tile-border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    user-select: none;
}
.calendar-cell-empty,
.calendar-cell-no-puzzle { visibility: hidden; }
.calendar-cell-future {
    opacity: 0.35;
    cursor: not-allowed;
}
.calendar-cell-locked {
    opacity: 0.5;
    cursor: not-allowed;
}
.calendar-cell-today { border-color: var(--accent); }
.calendar-cell-active { border-color: var(--accent); color: var(--accent); }
.calendar-badge {
    position: absolute;
    top: 2px;
    right: 3px;
    font-size: 0.55rem;
    line-height: 1;
    font-weight: 800;
}
.calendar-badge-gold { color: #f59e0b; font-size: 0.7rem; }
.calendar-badge-win  { color: var(--correct); }
.calendar-badge-fail { color: #ef4444; }
.calendar-badge-lock { top: auto; bottom: 3px; right: 3px; font-size: 0.55rem; }


.controls { display: flex; gap: 10px; }
button.primary-btn { flex: 1; padding: 12px; border-radius: 10px; border: none; background: var(--accent); color: white; font-weight: bold; cursor: pointer; }
button.secondary-btn { background: #64748b; }

/* Check button needs extra width to fit "Check" + 7 inline dots on one
   line. Equal flex makes it the same width as Shuffle, which forces the
   dot row to wrap below the text. 1.6 gives it ~60% more space without
   visually dominating. */
#check-btn { flex: 1.6; }

#status { min-height: 1.5rem; margin-top: 12px; font-size: 0.85rem; font-weight: 600; }

/* Disabled state */
button:disabled { opacity: 0.35; cursor: not-allowed; }

/* Check button — depleting dot budget */
.check-dots {
    display: inline-flex;
    gap: 4px;
    margin-left: 10px;
    vertical-align: middle;
}
.check-dots .dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
}
.check-dots .dot-on  { background: currentColor; }
/* Depleted dots: half-opacity so the full budget of 7 circles is always
   legible, and the remaining count is obvious at a glance. */
.check-dots .dot-off {
    background: currentColor;
    opacity: 0.35;
}

/* Revealed tiles — solution shown after a failed attempt */
.tile.revealed { background: #64748b; color: white; border-color: #64748b; }

/* Banner above the revealed solution */
.solution-banner {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #ef4444;
    margin-bottom: 8px;
}

.new-day-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    background: var(--correct);
    color: #fff;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
}
.new-day-banner span { flex: 1; }
.new-day-banner button {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 0;
    border-radius: 4px;
    padding: 0.35rem 0.75rem;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
}
.new-day-banner button:hover { background: rgba(255, 255, 255, 0.3); }
.new-day-banner .new-day-dismiss {
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
    line-height: 1;
}

/* Avatar icon button variant — background is set inline per-letter. */
.icon-btn-avatar {
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    color: #fff;
    border-color: transparent;
}
.icon-btn-avatar:hover { filter: brightness(1.1); background: inherit; }

/* Account modal */
.account-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 1rem;
}
.account-avatar-chip {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--tile-border);
    color: white;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
}
.account-header-info { text-align: left; min-width: 0; }
.account-email { font-size: 0.8rem; opacity: 0.85; word-break: break-all; margin: 0; }

.account-settings-list { display: flex; flex-direction: column; margin-bottom: 0.75rem; }
.account-row {
    display: block;
    width: 100%;
    padding: 11px 0;
    border: none;
    border-bottom: 1px solid var(--tile-border);
    background: none;
    color: var(--text);
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
}
.account-row:first-child { border-top: 1px solid var(--tile-border); }
.account-row:hover { opacity: 0.7; }
.account-row-danger { color: #c00; }

.account-back-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0;
    margin-bottom: 0.75rem;
    font-family: inherit;
}
.account-pane-title { font-size: 0.9rem; font-weight: 700; margin: 0 0 0.5rem; }
.account-pane-desc { font-size: 0.8rem; opacity: 0.7; margin: 0 0 0.75rem; text-align: left; line-height: 1.5; }
.account-pane-msg { font-size: 0.8rem; margin-top: 0.5rem; text-align: center; }
.account-pane-msg-ok { color: var(--correct); }
.account-pane-msg-err { color: #c0392b; }

/* Avatar picker grid */
.avatar-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    margin-bottom: 0.5rem;
}
.avatar-cell {
    aspect-ratio: 1/1;
    border: 1.5px solid transparent;
    border-radius: 6px;
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}
.avatar-cell:hover { filter: brightness(1.1); }
.avatar-cell-selected {
    box-shadow: 0 0 0 3px var(--text);
}

/* Help modal menu */
.help-menu { display: flex; flex-direction: column; }
.help-feedback-text { cursor: default; }
.help-feedback-email { font-weight: 500; user-select: all; }
.help-back-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0;
    margin-bottom: 0.75rem;
    font-family: inherit;
    text-align: left;
}

/* Stats modal — signed-out CTA */
.stats-cta-text {
    font-size: 0.85rem;
    line-height: 1.5;
    margin: 0 0 1rem;
    text-align: center;
}

/* Stats modal — give it more room than the other modals */
#stats-modal .modal { max-width: 360px; }

.stats-summary { display: flex; justify-content: space-around; margin-bottom: 1.25rem; }
.stats-block { text-align: center; }
.stats-number { font-size: 2rem; font-weight: 800; line-height: 1; }
.stats-label { font-size: 0.85rem; font-weight: 700; text-transform: uppercase; opacity: 0.6; letter-spacing: 0.03em; margin-top: 2px; line-height: 1.2; }
.stats-dist-label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; opacity: 0.5; letter-spacing: 0.05em; margin-bottom: 8px; text-align: left; }
.dist-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.dist-label { font-size: 0.75rem; font-weight: 700; width: 56px; text-align: right; flex-shrink: 0; }
.dist-bar { background: var(--accent); border-radius: 4px; height: 20px; display: flex; align-items: center; min-width: 22px; transition: width 0.4s ease; }
.dist-bar.dist-bar-fail { background: #ef4444; }
.dist-bar.dist-bar-empty { background: var(--tile-border); }
.dist-count { font-size: 0.65rem; font-weight: 700; color: white; padding: 0 8px; white-space: nowrap; }
.dist-bar.dist-bar-empty .dist-count { color: var(--text); opacity: 0.6; }

/* Account modal — section groupings */
.account-section-header {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted, var(--absent));
    opacity: 0.7;
    padding: 0.75rem 0 0.25rem;
}
.account-section-divider {
    border: none;
    border-top: 1px solid var(--tile-border);
    margin: 0.25rem 0 0;
}

/* === Legal pages === */
.legal-page { display: block; max-width: 720px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.legal-page h1 { margin: 1rem 0 1.5rem; }
.legal-page h2 { margin: 2rem 0 0.75rem; font-size: 1.1rem; }
.legal-page p, .legal-page li { line-height: 1.6; font-size: 0.95rem; }
.legal-page a.back-link { display: inline-block; margin-bottom: 1rem; font-size: 0.85rem; }
.legal-page .last-updated { margin-top: 3rem; font-size: 0.8rem; opacity: 0.7; }

/* === App footer === */
.app-footer { margin-top: 2rem; padding-top: 1rem; text-align: center; font-size: 0.75rem; opacity: 0.6; }
.app-footer a { color: inherit; text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }