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

:root {
    --cyan: #22d3ee;
    --cyan-dark: #0891b2;
    --cyan-glow: rgba(34, 211, 238, 0.3);
    --bg: #0f172a;
    --card-bg: #1e293b;
    --card-border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --gold: #fbbf24;
    color-scheme: dark;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: #0f172a;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
}

html {
    position: fixed;
    width: 100%;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #0f172a;
    color: #f1f5f9;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100dvh;
    padding: 16px;
    padding-bottom: env(safe-area-inset-bottom, 16px);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

/* Header */
.header {
    width: 100%;
    max-width: 400px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    margin-bottom: 24px;
    position: relative;
    z-index: 5;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.puzzle-date {
    font-family: 'DM Sans', sans-serif;
    font-size: 1.125rem;
    font-weight: 700;
    color: #f1f5f9;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.puzzle-date.archive {
    color: #f59e0b;
    font-size: 1rem;
}

/* Legacy puzzle-number kept for JS compat */
.puzzle-number {
    font-family: 'Space Mono', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: #22d3ee;
    cursor: pointer;
    transition: opacity 0.2s;
}

.puzzle-number:hover {
    opacity: 0.8;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.undo-btn {
    font-size: 1.5rem;
    color: #94a3b8;
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
    padding: 4px;
    pointer-events: none;
}

.undo-btn.visible {
    opacity: 0.6;
    pointer-events: auto;
}

.undo-btn.visible:hover {
    opacity: 1;
    color: #22d3ee;
}

.undo-btn.visible:active {
    transform: scale(0.9);
}

/* Tutorial help button (? in header) */
.tutorial-help-btn {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.875rem;
    font-weight: 700;
    color: #64748b;
    background: none;
    border: 1px solid #334155;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    cursor: pointer;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s;
    -webkit-tap-highlight-color: transparent;
}
.tutorial-help-btn.visible {
    opacity: 0.6;
    pointer-events: auto;
}
.tutorial-help-btn:hover {
    opacity: 1;
    color: #94a3b8;
    border-color: #475569;
}

/* Hint button */
.hint-btn {
    font-size: 1.25rem;
    color: #94a3b8;
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.6s ease-in, color 0.2s;
    padding: 4px;
    pointer-events: none;
}

.hint-btn.visible {
    opacity: 0.75;
    pointer-events: auto;
    animation: hint-pulse 2s ease-in-out infinite;
}

.hint-btn.visible:hover {
    opacity: 1;
    color: #f59e0b;
}

@keyframes hint-pulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 0.9; }
}

/* Shake-to-undo setting */
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    margin-top: 12px;
    background: rgba(34, 211, 238, 0.05);
    border: 1px solid #334155;
    border-radius: 8px;
}
.setting-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.setting-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #f1f5f9;
}
.setting-desc {
    font-size: 0.6875rem;
    color: #64748b;
}
.setting-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    -webkit-tap-highlight-color: transparent;
}
.toggle-track {
    display: block;
    width: 40px;
    height: 22px;
    border-radius: 11px;
    background: #334155;
    position: relative;
    transition: background 0.2s;
}
.setting-toggle[aria-checked="true"] .toggle-track {
    background: #22d3ee;
}
.toggle-thumb {
    display: block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #f1f5f9;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: left 0.2s;
}
.setting-toggle[aria-checked="true"] .toggle-thumb {
    left: 20px;
}
.shake-guidance {
    font-size: 0.75rem;
    color: #94a3b8;
    line-height: 1.4;
    padding: 0 4px;
    margin-top: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s, margin-top 0.3s, padding-top 0.3s;
}
.shake-guidance.visible {
    max-height: 200px;
    margin-top: 8px;
    padding-top: 4px;
}
.shake-guidance a {
    color: #22d3ee;
    text-decoration: none;
}
.shake-guidance .guidance-steps {
    margin: 6px 0 0 0;
    padding-left: 1.2em;
}
.shake-guidance .guidance-steps li {
    margin-bottom: 3px;
}

/* Sync section in archive modal */
.sync-section {
    margin-top: 12px;
    padding: 12px;
    background: rgba(34, 211, 238, 0.05);
    border: 1px solid #334155;
    border-radius: 8px;
    text-align: center;
}

.sync-section.signed-in {
    border-color: rgba(34, 211, 238, 0.3);
}

.sync-label {
    font-size: 0.75rem;
    color: #64748b;
    margin-bottom: 8px;
}

.sync-methods {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    background: #fff;
    border: 1px solid #dadce0;
    border-radius: 8px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #3c4043;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
}

.google-btn:hover {
    background: #f7f8f8;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.google-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.sync-divider {
    font-size: 0.6875rem;
    color: #475569;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.sync-divider::before,
.sync-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #334155;
}

.email-otp-row {
    display: flex;
    gap: 6px;
    width: 100%;
}

.email-otp-input {
    flex: 1;
    padding: 8px 10px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 6px;
    color: #f1f5f9;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.8125rem;
    outline: none;
    transition: border-color 0.15s;
}

.email-otp-input:focus {
    border-color: #22d3ee;
}

.email-otp-input::placeholder {
    color: #475569;
}

.email-send-btn {
    padding: 8px 12px;
    background: rgba(34, 211, 238, 0.15);
    border: 1px solid #22d3ee;
    border-radius: 6px;
    color: #22d3ee;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

.email-send-btn:hover {
    background: rgba(34, 211, 238, 0.25);
}

.email-send-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* OTP code entry (hidden until email sent) */
.otp-verify-row {
    display: none;
    gap: 6px;
    width: 100%;
}

.otp-verify-row.visible {
    display: flex;
}

.otp-code-input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 6px;
    color: #f1f5f9;
    font-family: 'Space Mono', monospace;
    font-size: 1rem;
    letter-spacing: 0.15em;
    text-align: center;
    outline: none;
    transition: border-color 0.15s;
}

.otp-code-input:focus {
    border-color: #22d3ee;
}

.otp-code-input::placeholder {
    color: #475569;
    letter-spacing: 0.1em;
    font-size: 0.8125rem;
}

.otp-verify-btn {
    padding: 8px 16px;
    background: #22d3ee;
    border: none;
    border-radius: 6px;
    color: #0f172a;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    min-width: 64px;
    flex-shrink: 0;
}

.otp-verify-btn:hover {
    background: #0891b2;
}

.sync-status {
    font-size: 0.6875rem;
    color: #64748b;
    min-height: 1em;
    margin-top: 4px;
}

.sync-status.error { color: #ef4444; }
.sync-status.success { color: #10b981; }

.sync-signout {
    background: none;
    border: none;
    color: #64748b;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 0.15s;
}

.sync-signout:hover {
    color: #94a3b8;
}

/* Streak milestone nudge toast */
.sync-nudge {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 0.8125rem;
    color: #94a3b8;
    text-align: center;
    z-index: 80;
    max-width: 300px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s, transform 0.4s;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.sync-nudge.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

.sync-nudge-link {
    color: #22d3ee;
    text-decoration: underline;
    cursor: pointer;
    font-weight: 500;
}

.sync-nudge-dismiss {
    color: #475569;
    font-size: 0.75rem;
    cursor: pointer;
    margin-left: 8px;
}

.streak-display {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 1.25rem;
    font-weight: 700;
}

.streak-display .fire {
    font-size: 1.5rem;
}

.freeze-indicator {
    font-size: 1rem;
    margin-left: 4px;
    opacity: 0.8;
}

/* Game Container */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 400px;
    position: relative;
    margin-top: -80px;
}

.result-display {
    font-family: 'Space Mono', monospace;
    font-size: 3.5rem;
    font-weight: 700;
    color: #f1f5f9;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.1s, transform 0.1s, opacity 0.1s;
    margin-bottom: 24px;
    opacity: 0;
}

.result-display.visible { opacity: 1; }
.result-display.success { color: #10b981; transform: scale(1.1); }
.result-display.error { color: #ef4444; }

/* Clean win state: hide cards, show big result */
.result-display.win-clean {
    font-size: 5rem;
    color: #10b981;
    opacity: 1;
    transform: scale(1);
    animation: win-pulse 0.6s ease-out;
}

@keyframes win-pulse {
    0% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

.diamond-grid.win-hidden .slot {
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Hint display */
.hint-display {
    font-family: 'DM Sans', sans-serif;
    font-size: 1.125rem;
    letter-spacing: 0.05em;
    color: #f59e0b;
    opacity: 0;
    transition: opacity 0.5s;
    margin-top: -16px;
    margin-bottom: 8px;
    height: 24px;
}

.hint-display.visible {
    opacity: 0.85;
}

/* Diamond Grid */
.diamond-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 12px;
    width: 320px;
    height: 320px;
    position: relative;
}

.slot { display: flex; align-items: center; justify-content: center; transition: opacity 0.4s ease, transform 0.4s ease; }
.slot.top { grid-column: 2; grid-row: 1; }
.slot.left { grid-column: 1; grid-row: 2; }
.slot.right { grid-column: 3; grid-row: 2; }
.slot.bottom { grid-column: 2; grid-row: 3; }

.card {
    width: 96px;
    height: 96px;
    background: #1e293b;
    border: 2px solid #334155;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Mono', monospace;
    font-size: 2.75rem;
    font-weight: 700;
    color: #f1f5f9;
    cursor: pointer;
    transition: transform 0.1s ease, border-color 0.1s ease, box-shadow 0.1s ease;
    -webkit-user-select: none;
    user-select: none;
}

/* Fraction display inside cards */
.fraction-display {
    display: inline-flex;
    align-items: center;
    gap: 0.05em;
    line-height: 1;
}
.fraction-whole {
    font-size: inherit;
}
.fraction-part {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.45em;
    line-height: 1.1;
    vertical-align: middle;
    position: relative;
}
.frac-num {
    border-bottom: 1.5px solid currentColor;
    padding: 0 0.15em 0.05em;
}
.frac-den {
    padding: 0.05em 0.15em 0;
}
/* Scale down font when showing fractions */
.card .fraction-display {
    font-size: 2rem;
}
.result-display .fraction-display {
    font-size: 2.5rem;
}
.replay-card .fraction-display {
    font-size: 1.5rem;
}

.card:active { transform: scale(0.95); }
.card.selected { border-color: #22d3ee; box-shadow: 0 0 24px rgba(34, 211, 238, 0.3); transform: scale(1.08); }
.card.selected.first { border-color: #22d3ee; }
.card.selected.second { border-color: #f59e0b; box-shadow: 0 0 24px rgba(245, 158, 11, 0.3); }
.card.used { opacity: 0; pointer-events: none; transform: scale(0.8); }

/* Operators Overlay */
.operators-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    display: none; align-items: center; justify-content: center; z-index: 50;
}
.operators-overlay.show { display: flex; }

.operators-grid {
    display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
    gap: 12px; padding: 14px;
    background: rgba(30, 41, 59, 0.85); border-radius: 20px;
    border: 1px solid rgba(51, 65, 85, 0.6);
}

.op-btn {
    width: 54px; height: 54px; border-radius: 50%;
    border: 2px solid #22d3ee; background: rgba(30, 41, 59, 0.95);
    color: #f1f5f9; font-size: 1.5rem; font-weight: 700;
    cursor: pointer; transition: all 0.1s ease;
    display: flex; align-items: center; justify-content: center;
}
.op-btn:hover { background: rgba(34, 211, 238, 0.2); transform: scale(1.1); }
.op-btn:active { transform: scale(0.95); }

/* Move dots */
.move-dots {
    position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 6px; justify-content: center; align-items: center;
    z-index: 310;
}

.move-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #334155; transition: background 0.3s, transform 0.2s;
}
.move-dot.filled { background: #10b981; transform: scale(1.1); }
.move-dot.excess { background: #64748b; }
.move-dot.perfect-hint { background: #334155; opacity: 0.5; }

/* Victory stat card */
.victory-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.victory-backdrop.show { display: flex; }

.victory-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 16px;
    padding: 28px 24px 20px;
    text-align: center;
    max-width: 300px;
    width: 100%;
    position: relative;
    animation: victory-in 0.3s ease-out;
}

@keyframes victory-in {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.victory-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: #64748b;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color 0.15s;
}
.victory-close:hover { color: #f1f5f9; }

.victory-badge {
    font-size: 1rem;
    font-weight: 700;
    color: #10b981;
    margin-bottom: 4px;
    cursor: pointer;
}
.victory-badge.perfect { color: #fbbf24; }

.victory-date {
    font-size: 0.8125rem;
    color: #94a3b8;
    margin-bottom: 20px;
}

.victory-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-bottom: 16px;
}

.victory-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.victory-stat-value {
    font-family: 'Space Mono', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: #f1f5f9;
}

.victory-stat-label {
    font-size: 0.6875rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.victory-percentile {
    font-size: 0.8125rem;
    color: #94a3b8;
    margin-bottom: 16px;
    min-height: 1.2em;
}
.victory-percentile.highlight { color: #22d3ee; font-weight: 600; }

.victory-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.btn {
    padding: 10px 20px; border-radius: 8px; border: none;
    font-family: 'DM Sans', sans-serif; font-size: 0.875rem; font-weight: 600;
    cursor: pointer; transition: all 0.15s ease;
}
.btn-primary { background: #22d3ee; color: #0f172a; }
.btn-primary:hover { background: #0891b2; }

.btn-challenge {
    background: transparent;
    color: #94a3b8;
    border: 1px solid #334155;
}
.btn-challenge:hover {
    border-color: #94a3b8;
    color: #f1f5f9;
}

/* Archive Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none; align-items: center; justify-content: center;
    z-index: 200; padding: 16px;
}
.modal-overlay.show { display: flex; }

.modal {
    background: #1e293b; border-radius: 16px; padding: 24px;
    max-width: 360px; width: 100%; max-height: 80vh; overflow-y: auto;
}
.modal h2 { text-align: center; margin-bottom: 16px; color: #22d3ee; }

.archive-list {
    display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 8px; max-height: 320px; overflow-y: auto; padding-right: 4px;
}

.archive-list::-webkit-scrollbar { width: 6px; }
.archive-list::-webkit-scrollbar-track { background: #1e293b; border-radius: 3px; }
.archive-list::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }

.load-more-btn {
    display: block; width: 100%; margin-top: 12px; padding: 10px;
    background: transparent; border: 1px dashed #475569; border-radius: 8px;
    color: #94a3b8; font-family: 'DM Sans', sans-serif; font-size: 0.875rem;
    cursor: pointer; transition: all 0.15s;
}
.load-more-btn:hover { border-color: #22d3ee; color: #22d3ee; }

.share-history-btn {
    display: block; width: 100%; margin-top: 12px; padding: 10px;
    background: rgba(34, 211, 238, 0.1); border: 1px solid #22d3ee; border-radius: 8px;
    color: #22d3ee; font-family: 'DM Sans', sans-serif; font-size: 0.875rem;
    font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.share-history-btn:hover { background: rgba(34, 211, 238, 0.2); }

.archive-item {
    aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
    background: #0f172a; border: 1px solid #334155; border-radius: 8px;
    font-family: 'Space Mono', monospace; font-size: 0.875rem;
    color: #f1f5f9; cursor: pointer; transition: all 0.15s;
}
.archive-item:hover { border-color: #22d3ee; }

.archive-item.completed { background: rgba(16, 185, 129, 0.2); border-color: #10b981; }

.archive-item.perfect {
    background: rgba(251, 191, 36, 0.15); border-color: #fbbf24; position: relative;
}
.archive-item.perfect::after {
    content: '\2B50'; position: absolute; top: -4px; right: -4px; font-size: 0.6rem;
}

.archive-item.fast-perfect {
    background: rgba(251, 191, 36, 0.3); border-color: #fbbf24; position: relative;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}
.archive-item.fast-perfect::after {
    content: '\2B50\2B50'; position: absolute; top: -6px; right: -8px; font-size: 0.5rem;
}

.archive-item.today { border-color: #22d3ee; box-shadow: 0 0 10px rgba(34, 211, 238, 0.3); }

.archive-item.locked { cursor: default; position: relative; }
.archive-item.locked::before {
    content: '\1F512'; position: absolute; bottom: -4px; left: -4px; font-size: 0.5rem; opacity: 0.7;
}

.modal-close {
    display: block; width: 100%; margin-top: 16px; padding: 12px;
    background: #0f172a; border: 1px solid #334155; border-radius: 8px;
    color: #f1f5f9; font-size: 1rem; cursor: pointer;
}

/* Confetti */
.confetti-container {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 1000; overflow: hidden;
}
.confetti { position: absolute; width: 10px; height: 10px; opacity: 0; }

@keyframes confetti-fall {
    0% { transform: translateY(-100px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Archive mode indicator */
.archive-banner {
    background: rgba(245, 158, 11, 0.15); color: #f59e0b;
    padding: 6px 14px; border-radius: 6px;
    font-size: 0.8125rem; font-weight: 500;
    position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
    display: none; z-index: 10;
    border: 1px solid rgba(245, 158, 11, 0.25);
}
.archive-banner.show { display: block; }

/* Hidden canvas for share image generation */
.share-canvas { display: none; }

/* Sync error toast */
.sync-error-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 0.75rem;
    color: #fca5a5;
    z-index: 90;
    max-width: 300px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
}

.sync-error-toast.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

/* ============================================================
   CALENDAR BUTTON (header)
   ============================================================ */
.calendar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    border-radius: 6px;
    transition: color 0.15s, opacity 0.15s;
    opacity: 0.6;
    padding: 0;
}

.calendar-btn:hover {
    opacity: 1;
    color: #22d3ee;
}

.calendar-btn:active {
    transform: scale(0.9);
}

/* ============================================================
   CALENDAR MODAL
   ============================================================ */
.calendar-modal {
    padding: 20px;
}

.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.calendar-nav {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 12px;
    border-radius: 6px;
    transition: color 0.15s;
    line-height: 1;
}
.calendar-nav:hover { color: #f1f5f9; }
.calendar-nav:disabled { opacity: 0.2; cursor: default; }

.calendar-title {
    font-family: 'DM Sans', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    color: #f1f5f9;
}

.calendar-streak {
    text-align: center;
    font-size: 0.8125rem;
    color: #94a3b8;
    margin-bottom: 16px;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 4px;
}

.calendar-weekdays span {
    text-align: center;
    font-size: 0.6875rem;
    color: #64748b;
    text-transform: uppercase;
    padding: 4px 0;
    letter-spacing: 0.03em;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.cal-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    color: #94a3b8;
    position: relative;
}

.cal-day:hover { background: rgba(255, 255, 255, 0.05); }
.cal-day:active { transform: scale(0.92); }
.cal-day.empty { cursor: default; }
.cal-day.empty:hover { background: none; }
.cal-day.future { color: #334155; cursor: default; }
.cal-day.future:hover { background: none; }

.cal-day.today {
    color: #f1f5f9;
    font-weight: 700;
    background: rgba(34, 211, 238, 0.1);
}

.cal-day.solved {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    font-weight: 600;
}

.cal-day.perfect {
    background: rgba(251, 191, 36, 0.12);
    color: #fbbf24;
    font-weight: 600;
}

.cal-day.missed {
    color: #64748b;
}

.cal-day.missed::after {
    content: '';
    position: absolute;
    bottom: 3px;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: #334155;
}

/* ============================================================
   PUZZLE DETAILS SHEET
   ============================================================ */
.details-sheet {
    background: #1e293b;
    border-radius: 16px 16px 0 0;
    padding: 24px;
    max-width: 400px;
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    max-height: 70vh;
    overflow-y: auto;
    animation: sheet-up 0.25s ease-out;
}

@keyframes sheet-up {
    from { transform: translateX(-50%) translateY(100%); }
    to { transform: translateX(-50%) translateY(0); }
}

.details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.details-date {
    font-size: 1rem;
    font-weight: 700;
    color: #f1f5f9;
}

.details-close {
    background: none;
    border: none;
    color: #64748b;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}
.details-close:hover { color: #f1f5f9; }

.details-tiles {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 12px;
}

.details-tile {
    width: 44px;
    height: 44px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Mono', monospace;
    font-size: 1.125rem;
    font-weight: 700;
    color: #f1f5f9;
}

.details-status {
    text-align: center;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 12px;
}
.details-status.solved { color: #10b981; }
.details-status.perfect { color: #fbbf24; }
.details-status.missed { color: #64748b; }

.details-stats-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 12px;
}

.details-stat {
    text-align: center;
}
.details-stat-value {
    font-family: 'Space Mono', monospace;
    font-size: 1.125rem;
    font-weight: 700;
    color: #f1f5f9;
    display: block;
}
.details-stat-label {
    font-size: 0.625rem;
    color: #64748b;
    text-transform: uppercase;
    display: block;
}

.details-meta {
    text-align: center;
    font-size: 0.6875rem;
    color: #64748b;
    margin-bottom: 16px;
}

.details-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

/* ============================================================
   REPLAY OVERLAY
   ============================================================ */
.replay-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #0f172a;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 300;
}
.replay-overlay.show { display: flex; }

.replay-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 12px;
    width: 280px;
    height: 280px;
    position: relative;
}

.replay-slot {
    display: flex;
    align-items: center;
    justify-content: center;
}
#rslot0 { grid-column: 2; grid-row: 1; }
#rslot1 { grid-column: 1; grid-row: 2; }
#rslot2 { grid-column: 3; grid-row: 2; }
#rslot3 { grid-column: 2; grid-row: 3; }

.replay-card {
    width: 80px;
    height: 80px;
    background: #1e293b;
    border: 2px solid #334155;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Mono', monospace;
    font-size: 2rem;
    font-weight: 700;
    color: #f1f5f9;
    transition: transform 0.3s ease, opacity 0.3s ease, border-color 0.2s;
}

.replay-card.highlight {
    border-color: #22d3ee;
    box-shadow: 0 0 16px rgba(34, 211, 238, 0.3);
    transform: scale(1.05);
}

.replay-card.merging {
    animation: replay-merge 0.35s ease-in forwards;
}

.replay-card.appearing {
    animation: replay-appear 0.25s ease-out;
}

@keyframes replay-merge {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(0.4); opacity: 0; }
}

@keyframes replay-appear {
    0% { transform: scale(0.4); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.replay-card.replay-puff {
    animation: replay-puff 0.45s ease-out forwards;
}

@keyframes replay-puff {
    0% { transform: scale(1); opacity: 1; filter: blur(0); }
    50% { transform: scale(1.15); opacity: 0.6; filter: blur(2px); }
    100% { transform: scale(1.3); opacity: 0; filter: blur(6px); }
}

.replay-op-display {
    grid-column: 2; grid-row: 2;
    font-family: 'Space Mono', monospace;
    font-size: 2.5rem;
    font-weight: 700;
    color: #22d3ee;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}
.replay-op-display.visible { opacity: 1; }
.replay-op-display.undo { color: #f97316; }

.replay-top-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 12px;
    z-index: 310;
}

.replay-close-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid #334155;
    color: #94a3b8;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.replay-close-btn:hover { border-color: #22d3ee; color: #f1f5f9; }
.replay-close-btn:active { transform: scale(0.9); }

/* Undo animation in live play */
.card.undo-appear {
    animation: undo-pop 0.25s ease-out;
}

@keyframes undo-pop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ============================================================
   MORE MENU (replaces calendar + settings buttons)
   ============================================================ */
.more-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    border-radius: 6px;
    transition: color 0.1s, opacity 0.1s;
    opacity: 0.6;
    padding: 0;
}
.more-btn:hover { opacity: 1; color: #22d3ee; }
.more-btn:active { transform: scale(0.9); }

.more-menu {
    position: absolute;
    top: 48px;
    right: 0;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 4px;
    min-width: 160px;
    z-index: 60;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-4px);
    transition: opacity 0.1s, transform 0.1s;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
.more-menu.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.more-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    color: #f1f5f9;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.875rem;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.1s;
}
.more-menu-item:hover { background: rgba(255, 255, 255, 0.05); }
.more-menu-item svg { color: #94a3b8; flex-shrink: 0; }

/* ============================================================
   CLIPBOARD TOAST
   ============================================================ */
.clipboard-toast {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 0.8125rem;
    color: #f1f5f9;
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.clipboard-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================================
   TUTORIAL
   ============================================================ */
.tutorial-tooltip {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    background: #1e293b;
    border: 1px solid rgba(34, 211, 238, 0.3);
    border-radius: 12px;
    padding: 12px 20px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.875rem;
    color: #f1f5f9;
    text-align: center;
    z-index: 500;
    max-width: 320px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}
.tutorial-tooltip.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}
.tutorial-tooltip .tutorial-highlight {
    color: #22d3ee;
    font-weight: 600;
}

/* Tutorial mode: dim non-target elements */
.tutorial-dim {
    opacity: 0.3 !important;
    pointer-events: none !important;
}

/* Tutorial mode: pulse target card */
.tutorial-target {
    animation: tutorial-pulse 1s ease-in-out infinite;
    z-index: 10;
    position: relative;
}
@keyframes tutorial-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.4); }
    50% { box-shadow: 0 0 20px 4px rgba(34, 211, 238, 0.5); }
}

/* Tutorial banner at top */
.tutorial-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    background: rgba(34, 211, 238, 0.08);
    border-bottom: 1px solid rgba(34, 211, 238, 0.15);
    text-align: center;
    padding: 8px 16px;
    font-size: 0.75rem;
    color: #94a3b8;
    z-index: 500;
    display: none;
}
.tutorial-banner.visible { display: block; }
.tutorial-banner .tutorial-skip {
    color: #22d3ee;
    background: none;
    border: none;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    margin-left: 12px;
}

/* ============================================================
   DIFFICULTY CHIP (shown after solve)
   ============================================================ */
.difficulty-chip {
    display: inline-block;
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.difficulty-chip.easy { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.difficulty-chip.medium { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.difficulty-chip.hard { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

/* ============================================================
   FREEZE TOOLTIP
   ============================================================ */
.freeze-tooltip {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 0.75rem;
    color: #94a3b8;
    z-index: 80;
    max-width: 280px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.freeze-tooltip.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .replay-card.merging,
    .replay-card.appearing,
    .replay-card.replay-puff,
    .card.undo-appear {
        animation: none !important;
    }
    .confetti {
        display: none !important;
    }
    /* Disable all transitions globally */
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
