/* ==========================================================================
   SUIRODOKU MOBILE - Main Stylesheet
   Version: 1.0.0
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Variables
   -------------------------------------------------------------------------- */
:root {
    color-scheme: light only;
    
    --mobile-header-height: 44px;
    --mobile-action-bar-height: 48px;
    --mobile-controls-height: auto;
    --mobile-pad-gap: 8px;
    --mobile-btn-size: min(calc((100vw - 60px) / 6 - 8px), 48px);
    --mobile-toggle-height: 32px;
    
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
    
    --primary: #007aff;
    --primary-hover: #0056b3;
    --text-primary: #1c1c1e;
    --text-secondary: #374151;
    --text-muted: #6b7280;
    --bg-primary: #fff;
    --bg-secondary: #f2f2f7;
    --border-color: #e5e7eb;
    --border-dark: #484848;
    
    --error: #ff3b30;
    --error-dark: #d70015;
    --success: #28a745;
    --warning: #ff9500;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);
}

/* --------------------------------------------------------------------------
   Base Reset
   -------------------------------------------------------------------------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    caret-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

html {
    height: 100%;
    overflow: hidden;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    background: linear-gradient(135deg, #fef7f0 0%, #fffbf7 50%, #f9f4ef 100%);
    color: var(--text-primary);
    height: 100%;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

body::before {
    content: "";
    position: fixed;
    inset: -20%;
    z-index: -1;
    pointer-events: none;
    background: 
        radial-gradient(650px 650px at 18% 25%, rgba(255,159,28,0.12), transparent 58%),
        radial-gradient(850px 850px at 82% 15%, rgba(14,165,233,0.16), transparent 62%),
        radial-gradient(720px 720px at 35% 85%, rgba(168,85,247,0.13), transparent 60%);
}

/* --------------------------------------------------------------------------
   Mobile Header
   -------------------------------------------------------------------------- */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 44px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
}

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

.header-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 100px;
}

.header-logo {
    display: flex;
    align-items: center;
}

.header-logo img {
    height: 26px;
    width: auto;
}

/* Menu Burger Button */
.menu-burger {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.menu-burger:active {
    background: rgba(0, 0, 0, 0.05);
}

.menu-burger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Trophy Indicator */
.trophy-indicator {
    display: none;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.trophy-indicator.visible {
    display: flex;
}

.trophy-indicator img {
    width: 24px;
    height: 24px;
}

/* Header Stats */
.header-stat {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.header-stat .stat-value {
    font-variant-numeric: tabular-nums;
}

.header-stat.time .stat-value {
    min-width: 36px;
}

.header-stat.errors .stat-value {
    color: var(--text-primary);
    min-width: 24px;
}

.header-stat.errors.critical .stat-value {
    color: var(--error);
    font-weight: 700;
}

.header-stat.score {
    color: var(--primary);
}

.header-stat.score .stat-value {
    min-width: 32px;
    text-align: left;
}

.header-stat.score .stat-value.negative {
    color: #dc2626;
}

/* --------------------------------------------------------------------------
   Main Content Area
   -------------------------------------------------------------------------- */
.mobile-content {
    position: absolute;
    top: var(--mobile-header-height);
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 2vw 0 0 0;
    overflow: hidden;
    gap: 4px;
}

/* --------------------------------------------------------------------------
   Grid Container Override for Mobile
   -------------------------------------------------------------------------- */
.grid-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0;
    flex: 0 0 auto;
}

#sudoku-container {
    width: min(94vw, 380px) !important;
    height: min(94vw, 380px) !important;
}

/* --------------------------------------------------------------------------
   Action Bar (Toggle Notes + Hint + Correct + Toggle Colors)
   -------------------------------------------------------------------------- */
.mobile-action-bar {
    width: 100%;
    max-width: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 4px 12px;
    flex: 0 0 auto;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
    flex: 1;
    max-width: 110px;
}

.action-btn img {
    width: 20px;
    height: 20px;
}

/* Toggle Notes Button (in action bar) */
.toggle-notes-btn {
    background: linear-gradient(135deg, #fff, #f8fafc);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 10px 12px;
    border-radius: 10px;
    flex: 0 0 auto;
    max-width: 46px;
    min-width: 46px;
}

.toggle-notes-btn img {
    width: 22px;
    height: 22px;
    opacity: 0.6;
    transition: opacity 0.2s ease, filter 0.2s ease;
}

.toggle-notes-btn:active {
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
    transform: scale(0.95);
}

.toggle-notes-btn.active {
    background: linear-gradient(135deg, #007aff, #0056cc);
    border-color: #007aff;
    color: #fff;
}

.toggle-notes-btn.active img {
    opacity: 1;
    filter: brightness(2);
}

.toggle-notes-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Hint Button */
.hint-btn {
    background: linear-gradient(135deg, #fff, #f8fafc);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.hint-btn:active {
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
    transform: scale(0.98);
}

/* Correct Button */
.correct-btn {
    background: linear-gradient(135deg, #fff, #f8fafc);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    opacity: 0.5;
    pointer-events: none;
}

.correct-btn.active {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border-color: transparent;
    color: #fff;
    opacity: 1;
    pointer-events: auto;
    animation: correctPulse 2s infinite;
}

.correct-btn.active:active {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: scale(0.98);
}

@keyframes correctPulse {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
    }
    50% {
        box-shadow: 0 4px 16px rgba(239, 68, 68, 0.5);
    }
}

/* --------------------------------------------------------------------------
   Controls Container (2x PAD 3x3)
   -------------------------------------------------------------------------- */
.mobile-controls {
    width: 100%;
    max-width: 420px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 8px;
    padding: 2px 12px 12px;
    flex: 0 0 auto;
}

.control-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

/* PAD Grid 3x3 */
.pad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.pad-btn {
    width: var(--mobile-btn-size);
    height: var(--mobile-btn-size);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
    border: 2px solid transparent;
}

.pad-btn:active:not(:disabled) {
    transform: scale(0.92);
}

.pad-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Number Buttons */
.number-btn {
    background: #d6dae8;
    color: var(--text-primary);
}

.number-btn:active:not(:disabled) {
    background: #c0c5d6;
}

.number-btn.notes-mode {
    background: var(--primary) !important;
    color: #fff !important;
    border-color: var(--primary) !important;
}

/* Color Buttons */
.color-btn {
    border: 2px solid rgba(0, 0, 0, 0.15);
}

.color-btn:active:not(:disabled) {
    border-color: rgba(0, 0, 0, 0.3);
}

.color-btn.notes-mode {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

/* Color definitions */
.color-yellow { background-color: #FFEB6A; }
.color-orange { background-color: #FFBB45; }
.color-red { background-color: #FF8A7A; }
.color-green { background-color: #5BD87A; }
.color-brown { background-color: #C9A387; }
.color-pink { background-color: #FFA8CB; }
.color-cyan { background-color: #64EAE6; }
.color-blue { background-color: #5DB2FF; }
.color-purple { background-color: #BEA1E5; }

/* --------------------------------------------------------------------------
   Mobile Menu (Slide Panel)
   -------------------------------------------------------------------------- */
.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.menu-overlay.open {
    opacity: 1;
    visibility: visible;
}

.menu-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 320px;
    max-width: 85vw;
    background: #fff;
    z-index: 2001;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.menu-overlay.open .menu-panel {
    transform: translateX(0);
}

.menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-color);
}

.menu-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.menu-close {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 28px;
    color: var(--text-muted);
    transition: background 0.2s ease;
}

.menu-close:active {
    background: rgba(0, 0, 0, 0.05);
}

.menu-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.menu-section {
    padding: 8px 0;
}

.menu-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 8px 16px 4px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    font-size: 18px;
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s ease;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
}

.menu-item:active {
    background: rgba(0, 0, 0, 0.05);
}

.menu-item img {
    width: 28px;
    height: 28px;
}

.menu-item svg {
    width: 28px;
    height: 28px;
}

.menu-item.danger {
    color: var(--error);
}

.menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 16px;
}

/* --------------------------------------------------------------------------
   Logout button style
   -------------------------------------------------------------------------- */
.logout-btn {
    color: #ff3b30 !important;
}

.logout-btn svg {
    stroke: #ff3b30;
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* --------------------------------------------------------------------------
   Difficulty Background Classes
   -------------------------------------------------------------------------- */
body.difficulty-medium::before {
    background: 
        radial-gradient(650px 650px at 20% 30%, rgba(34, 197, 94, 0.15), transparent 55%),
        radial-gradient(800px 800px at 80% 20%, rgba(16, 185, 129, 0.12), transparent 60%),
        radial-gradient(700px 700px at 40% 80%, rgba(52, 211, 153, 0.14), transparent 58%);
}

body.difficulty-hard::before {
    background: 
        radial-gradient(650px 650px at 15% 25%, rgba(251, 191, 36, 0.18), transparent 55%),
        radial-gradient(800px 800px at 85% 15%, rgba(245, 158, 11, 0.15), transparent 60%),
        radial-gradient(700px 700px at 35% 85%, rgba(217, 119, 6, 0.12), transparent 58%);
}

body.difficulty-expert::before {
    background: 
        radial-gradient(650px 650px at 18% 28%, rgba(239, 68, 68, 0.16), transparent 55%),
        radial-gradient(800px 800px at 82% 18%, rgba(220, 38, 38, 0.14), transparent 60%),
        radial-gradient(700px 700px at 38% 82%, rgba(185, 28, 28, 0.12), transparent 58%);
}

body.difficulty-master::before {
    background: 
        radial-gradient(650px 650px at 20% 25%, rgba(139, 92, 246, 0.18), transparent 55%),
        radial-gradient(800px 800px at 80% 20%, rgba(124, 58, 237, 0.16), transparent 60%),
        radial-gradient(700px 700px at 35% 80%, rgba(109, 40, 217, 0.14), transparent 58%);
}

/* --------------------------------------------------------------------------
   Accessibility
   -------------------------------------------------------------------------- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --------------------------------------------------------------------------
   Safe Area (Notch Support)
   -------------------------------------------------------------------------- */
@supports (padding-top: env(safe-area-inset-top)) {
    .mobile-header {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--mobile-header-height) + env(safe-area-inset-top));
    }
    
    .mobile-content {
        top: calc(var(--mobile-header-height) + env(safe-area-inset-top));
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .mobile-controls {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    
    .menu-panel {
        padding-top: env(safe-area-inset-top);
    }
}

/* --------------------------------------------------------------------------
   Loading State
   -------------------------------------------------------------------------- */
.mobile-loading {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-loading.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------------------
   RTL Support
   -------------------------------------------------------------------------- */
body.rtl-language {
    direction: rtl;
}

body.rtl-language .mobile-header {
    flex-direction: row-reverse;
}

body.rtl-language .header-left,
body.rtl-language .header-right {
    flex-direction: row-reverse;
}

body.rtl-language .menu-panel {
    left: auto;
    right: 0;
    transform: translateX(100%);
}

body.rtl-language .menu-overlay.open .menu-panel {
    transform: translateX(0);
}

body.rtl-language .menu-item {
    flex-direction: row-reverse;
    text-align: right;
}

/* --------------------------------------------------------------------------
   Cell Notes Styles - Mobile optimized
   -------------------------------------------------------------------------- */
.cell-notes {
    position: absolute !important;
    top: 1px !important;
    left: 1px !important;
    right: 1px !important;
    bottom: 1px !important;
    display: grid !important;
    grid-template-rows: repeat(4, 1fr) !important;
    gap: 0 !important;
    pointer-events: none !important;
    z-index: 25 !important;
}

.notes-row {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 0 !important;
    height: 100% !important;
}

.note-item {
    width: 7px;
    height: 7px;
    min-width: 7px;
    min-height: 7px;
    max-width: 7px;
    max-height: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    flex-grow: 0;
    box-sizing: border-box;
}

.note-number {
    font-size: 8px;
    font-weight: 700;
    color: #333;
    text-shadow: 0 0 1px #fff, 0 0 1px #fff;
    line-height: 1;
}

.note-color {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    border: 0.5px solid rgba(0,0,0,0.3);
}

.note-color.color-yellow { background-color: #FFEB6A; }
.note-color.color-orange { background-color: #FFBB45; }
.note-color.color-red { background-color: #FF8A7A; }
.note-color.color-green { background-color: #5BD87A; }
.note-color.color-brown { background-color: #C9A387; }
.note-color.color-pink { background-color: #FFA8CB; }
.note-color.color-cyan { background-color: #64EAE6; }
.note-color.color-blue { background-color: #5DB2FF; }
.note-color.color-purple { background-color: #BEA1E5; }

/* Ensure cells have correct positioning for notes overlay */
.sudoku-cell {
    position: relative !important;
    overflow: hidden;
}

/* Number inside cell - below notes */
.sudoku-cell > span {
    position: relative;
    z-index: 20;
}
/* Force logo footer visibility on mobile */
.suiro-popup-logo-footer {
    display: flex !important;
    visibility: visible !important;
}

/* ==========================================================================
   Popup buttons side by side on mobile
   ========================================================================== */
.suiro-mode-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
}

.suiro-mode-grid.suiro-compact-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
}

#suiro-defeat-popup .suiro-difficulty-grid,
#suiro-victory-popup .suiro-difficulty-grid {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    justify-content: center !important;
}

#suiro-defeat-popup .suiro-difficulty-grid > *,
#suiro-victory-popup .suiro-difficulty-grid > * {
    flex: 1 1 0 !important;
    max-width: none !important;
    min-width: 0 !important;
}

/* Difficulty selection - 2 or 3 per row */
#suiro-difficulty-selection-popup .suiro-difficulty-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
}

/* Smaller logo in popup footer on mobile */
.suiro-popup-logo-footer {
    padding: 6px 12px !important;
}

.suiro-popup-logo-footer .suiro-logo-svg {
    height: 22px !important;
    max-width: 120px !important;
}