:root {
            --primary-color: #0891b2; 
            --secondary-color: #f8fafc;
            --text-color: #1f2937;
            --border-color: #e5e7eb;
            --error-color: #ef4444;
        }

        body {
            font-family: 'Inter', system-ui, -apple-system, sans-serif;
            margin: 0;
            padding: 12px 8px; 
            background-color: #f3f4f6;
            color: var(--text-color);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: flex-start;
            min-height: 100vh;
            touch-action: manipulation;
        }

        .page-wrapper {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 100%;
            max-width: 480px; 
            margin: 0 auto;
            box-sizing: border-box;
        }

        .container {
            display: flex;
            flex-direction: column;
            width: 100%;
            gap: 12px; 
            justify-content: center;
            box-sizing: border-box;
        }
        
        .controls, .display {
            background-color: white;
            padding: 14px; 
            border-radius: 12px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.1);
            border: 1px solid var(--border-color);
            box-sizing: border-box;
            width: 100%;
        }

        .display {
            display: flex;
            justify-content: center;
            align-items: center;
            order: 1; 
            height: auto !important;
            min-height: 0 !important;
        }

        .controls {
            order: 2;
            display: flex !important;
            flex-direction: column !important;
            justify-content: flex-start !important;
            gap: 14px !important;
            height: auto !important;
            min-height: 0 !important;
            max-height: none !important;
        }

        h1 {
            color: #111827;
            text-align: center;
            width: 100%;
            margin: 0; 
            font-size: 1.15rem; 
            font-weight: 800;
            line-height: 1.4;
        }

        h1 a {
            display: inline-block;
            margin: 2px 4px;
            text-decoration: none;
        }

        .board-container {
            position: relative;
            width: 100%;
            max-width: 100%;
            display: flex;
            justify-content: center;
            box-sizing: border-box;
        }

        #puzzleCanvas {
            border: 1px solid var(--border-color);
            background-color: var(--secondary-color);
            display: block;
            position: relative;
            z-index: 0;
            border-radius: 6px;
            width: 100% !important; 
            max-width: 100% !important;
            height: auto !important;
            image-rendering: -webkit-optimize-contrast;
            image-rendering: crisp-edges;
            image-rendering: pixelated;
        }

        .selection-row {
            display: flex !important;
            gap: 6px !important;
            justify-content: space-between !important;
            width: 100% !important;
            margin-bottom: 0 !important;
            height: auto !important;
        }

        .form-group {
            flex: 1;
            min-width: 0; 
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        label {
            display: block;
            font-weight: 700;
            color: #4b5563;
            font-size: 0.75rem; 
            text-transform: uppercase;
            letter-spacing: 0.05em;
            text-align: center;
        }

        select {
            width: 100%;
            padding: 8px; 
            border: 1px solid #cbd5e1;
            border-radius: 8px;
            box-sizing: border-box;
            background-color: #f8fafc;
            font-size: 0.85rem; 
            color: #111827;
            text-align-last: center;
        }

        .button-group {
            display: flex !important;
            gap: 8px !important; 
            width: 100% !important;
            margin-top: 0 !important;
        }

        button {
            flex: 1;
            padding: 10px 16px; 
            font-size: 0.85rem; 
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s ease;
            font-weight: 700;
        }

        button:active:not(:disabled) {
            transform: scale(0.98);
        }

        #hintBtn { 
            background-color: var(--primary-color); 
            color: white; 
            box-shadow: 0 4px 10px rgba(8, 145, 178, 0.2);
        }
        #hintBtn:hover:not(:disabled) { background-color: #0e7490; }
        
        #resetBtn { 
            background-color: var(--error-color); 
            color: white; 
            box-shadow: 0 4px 10px rgba(239, 68, 68, 0.2);
        }
        #resetBtn:hover:not(:disabled) { background-color: #dc2626; }

        button:disabled {
            background-color: #d1d5db !important;
            color: #9ca3af !important;
            cursor: not-allowed;
            box-shadow: none !important;
        }

        #status {
            font-weight: 600;
            color: #d97706;
            font-size: 0.8rem;
            margin: 0;
            text-align: center;
            min-height: 24px;
        }

        .badge-link {
            font-size: 0.75rem;
            padding: 2px 6px;
            border-radius: 4px;
            font-weight: 600;
            border: 1px solid transparent;
        }
        .qr-badge { background-color: #fef2f2; color: #ef4444; border-color: #fee2e2; }
        .game-badge { background-color: #e0e7ff; color: #4f46e5; border-color: #e0e7ff; }
        .cn-badge { background-color: #f0fdf4; color: #16a34a; border-color: #dcfce7; }

        .page-footer {
            margin-top: 24px;
            text-align: center;
            font-size: 0.8rem;
            color: #6b7280;
            width: 100%;
            box-sizing: border-box;
        }
        .page-footer a { color: var(--primary-color); text-decoration: underline; font-weight: 500; }