<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <!-- Game Container with Glow -->
    <FrameLayout
        android:id="@+id/gameContainer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_margin="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.mintris.game.GameView
            android:id="@+id/gameView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <!-- Glowing Border -->
        <View
            android:id="@+id/glowBorder"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/glow_border" />
    </FrameLayout>
    
    <!-- Title Screen -->
    <com.mintris.game.TitleScreen
        android:id="@+id/titleScreen"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <!-- HUD Container - Score, Level, Lines -->
    <LinearLayout
        android:id="@+id/gameControlsContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        
        <LinearLayout
            android:id="@+id/hudContainer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:layout_gravity="end"
            android:orientation="vertical">

            <TextView
                android:id="@+id/scoreText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="32sp"
                android:textStyle="bold"
                android:fontFamily="sans-serif"
                tools:text="score: 0" />

            <TextView
                android:id="@+id/currentLevelText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="32sp"
                android:textStyle="bold"
                android:fontFamily="sans-serif"
                tools:text="level: 1" />

            <TextView
                android:id="@+id/linesText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="32sp"
                android:textStyle="bold"
                android:fontFamily="sans-serif"
                tools:text="lines: 0" />

            <TextView
                android:id="@+id/comboText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="32sp"
                android:textStyle="bold"
                android:fontFamily="sans-serif"
                tools:text="combo: 0" />
        </LinearLayout>

        <!-- Next Piece Preview -->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:layout_gravity="end"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="NEXT"
                android:textColor="@color/white"
                android:textSize="16sp"
                android:textStyle="bold"
                android:fontFamily="sans-serif"
                android:layout_marginBottom="4dp" />

            <com.mintris.game.NextPieceView
                android:id="@+id/nextPieceView"
                android:layout_width="80dp"
                android:layout_height="80dp" />
        </LinearLayout>
            
        <!-- Settings button -->
        <ImageButton
            android:id="@+id/pauseButton"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_gravity="start"
            android:layout_margin="16dp"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:contentDescription="@string/settings"
            android:padding="12dp"
            android:src="@drawable/ic_pause" />
    </LinearLayout>

    <!-- Hold Piece Preview -->
    <com.mintris.game.HoldPieceView
        android:id="@+id/holdPieceView"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <!-- Game Over overlay -->
    <LinearLayout
        android:id="@+id/gameOverContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone">

        <TextView
            android:id="@+id/gameOverText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/game_over"
            android:textColor="@color/white"
            android:textSize="36sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/session_stats"
            android:textColor="@color/white"
            android:textSize="28sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif"
            android:layout_marginTop="24dp" />

        <TextView
            android:id="@+id/sessionScoreText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:textColor="@color/white"
            android:textSize="24sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif" />

        <TextView
            android:id="@+id/sessionLinesText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:textColor="@color/white"
            android:textSize="24sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif" />

        <TextView
            android:id="@+id/sessionPiecesText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:textColor="@color/white"
            android:textSize="24sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif" />

        <TextView
            android:id="@+id/sessionTimeText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:textColor="@color/white"
            android:textSize="24sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif" />

        <TextView
            android:id="@+id/sessionLevelText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:textColor="@color/white"
            android:textSize="24sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/line_clears"
            android:textColor="@color/white"
            android:textSize="28sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif"
            android:layout_marginTop="16dp" />

        <TextView
            android:id="@+id/sessionSinglesText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:textColor="@color/white"
            android:textSize="24sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif" />

        <TextView
            android:id="@+id/sessionDoublesText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:textColor="@color/white"
            android:textSize="24sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif" />

        <TextView
            android:id="@+id/sessionTriplesText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:textColor="@color/white"
            android:textSize="24sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif" />

        <TextView
            android:id="@+id/sessionTetrisesText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:textColor="@color/white"
            android:textSize="24sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif" />

        <Button
            android:id="@+id/playAgainButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="32dp"
            android:background="@color/transparent"
            android:text="@string/play"
            android:textColor="@color/white"
            android:textSize="24sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif" />
    </LinearLayout>
    
    <!-- Player Progression Screen -->
    <com.mintris.ui.ProgressionScreen
        android:id="@+id/progressionScreen"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    
    <!-- Settings Menu overlay -->
    <LinearLayout
        android:id="@+id/pauseContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black"
        android:orientation="vertical"
        android:visibility="gone">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            android:layout_marginTop="32dp"
            android:layout_marginBottom="32dp">

            <TextView
                android:id="@+id/settingsTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/settings"
                android:textColor="@color/white"
                android:textSize="24sp"
                android:textStyle="bold"
                android:fontFamily="sans-serif"
                android:layout_marginEnd="16dp"
                android:textAllCaps="false" />

            <com.mintris.ui.LevelBadge
                android:id="@+id/pauseLevelBadge"
                android:layout_width="48dp"
                android:layout_height="48dp" />

        </LinearLayout>

        <ScrollView
            android:id="@+id/pauseMenuScrollView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:scrollbars="none"
            android:overScrollMode="never"
            android:fillViewport="false">
            
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center"
                android:paddingTop="16dp"
                android:paddingBottom="32dp">
                
                <Button
                    android:id="@+id/pauseStartButton"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:background="@color/transparent"
                    android:text="@string/start"
                    android:textColor="@color/white"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:fontFamily="sans-serif"
                    android:textAllCaps="false" />
        
                <Button
                    android:id="@+id/resumeButton"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:background="@color/transparent"
                    android:text="@string/resume"
                    android:textColor="@color/white"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:fontFamily="sans-serif"
                    android:textAllCaps="false" />
        
                <Button
                    android:id="@+id/pauseRestartButton"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:background="@color/transparent"
                    android:text="@string/restart"
                    android:textColor="@color/white"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:fontFamily="sans-serif"
                    android:textAllCaps="false" />
        
                <Button
                    android:id="@+id/highScoresButton"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:background="@color/transparent"
                    android:text="@string/high_scores"
                    android:textColor="@color/white"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:fontFamily="sans-serif"
                    android:textAllCaps="false" />
        
                <Button
                    android:id="@+id/statsButton"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:background="@color/transparent"
                    android:text="@string/stats"
                    android:textColor="@color/white"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:fontFamily="sans-serif"
                    android:textAllCaps="false" />
                    
                <!-- Level Selection -->
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:gravity="center"
                    android:layout_marginTop="16dp">
                    
                    <TextView
                        android:id="@+id/selectLevelText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/select_level"
                        android:textColor="@color/white"
                        android:textSize="24sp"
                        android:textStyle="bold"
                        android:fontFamily="sans-serif"
                        android:textAllCaps="false" />
                        
                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:layout_marginTop="8dp">
                        
                        <Button
                            android:id="@+id/pauseLevelDownButton"
                            android:layout_width="48dp"
                            android:layout_height="48dp"
                            android:background="@color/transparent"
                            android:text="−"
                            android:textColor="@color/white"
                            android:textSize="24sp"
                            android:textStyle="bold"
                            android:fontFamily="sans-serif" />
                            
                        <TextView
                            android:id="@+id/pauseLevelText"
                            android:layout_width="48dp"
                            android:layout_height="48dp"
                            android:gravity="center"
                            android:text="1"
                            android:textColor="@color/white"
                            android:textSize="24sp"
                            android:textStyle="bold"
                            android:fontFamily="sans-serif" />
                            
                        <Button
                            android:id="@+id/pauseLevelUpButton"
                            android:layout_width="48dp"
                            android:layout_height="48dp"
                            android:background="@color/transparent"
                            android:text="+"
                            android:textColor="@color/white"
                            android:textSize="24sp"
                            android:textStyle="bold"
                            android:fontFamily="sans-serif" />
                    </LinearLayout>
                </LinearLayout>
                
                <!-- Sound Toggle -->
                <Button
                    android:id="@+id/settingsButton"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:background="@color/transparent"
                    android:text="@string/sound_on"
                    android:textColor="@color/white"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:fontFamily="sans-serif"
                    android:textAllCaps="false" />
        
                <!-- Music Toggle -->
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:gravity="center"
                    android:layout_marginTop="16dp">
                    
                    <TextView
                        android:id="@+id/musicText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/music"
                        android:textColor="@color/white"
                        android:textSize="24sp"
                        android:textStyle="bold"
                        android:fontFamily="sans-serif"
                        android:layout_marginEnd="16dp"
                        android:textAllCaps="false" />
                        
                    <ImageButton
                        android:id="@+id/musicToggle"
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:background="@color/transparent"
                        android:src="@drawable/ic_volume_up"
                        android:contentDescription="@string/music" />
                </LinearLayout>

                <!-- Customization Button -->
                <Button
                    android:id="@+id/customizationButton"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:background="@color/transparent"
                    android:text="@string/customization"
                    android:textColor="@color/white"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:fontFamily="sans-serif"
                    android:textAllCaps="false"
                    android:singleLine="true" />
            </LinearLayout>
        </ScrollView>
    </LinearLayout>

    <!-- Customization Menu overlay -->
    <LinearLayout
        android:id="@+id/customizationContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black"
        android:orientation="vertical"
        android:visibility="gone">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            android:layout_marginTop="32dp"
            android:layout_marginBottom="32dp">

            <TextView
                android:id="@+id/customizationTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/customization"
                android:textColor="@color/white"
                android:textSize="20sp"
                android:textStyle="bold"
                android:fontFamily="sans-serif"
                android:layout_marginEnd="16dp"
                android:textAllCaps="false"
                android:singleLine="true" />

            <com.mintris.ui.LevelBadge
                android:id="@+id/customizationLevelBadge"
                android:layout_width="48dp"
                android:layout_height="48dp" />

        </LinearLayout>

        <ScrollView
            android:id="@+id/customizationMenuScrollView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:scrollbars="none"
            android:overScrollMode="never"
            android:fillViewport="false">
            
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center"
                android:paddingTop="16dp"
                android:paddingBottom="32dp">

                <!-- Theme Selector -->
                <com.mintris.ui.ThemeSelector
                    android:id="@+id/customizationThemeSelector"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp" />
                    
                <!-- Block Skin Selector -->
                <com.mintris.ui.BlockSkinSelector
                    android:id="@+id/customizationBlockSkinSelector"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:background="@drawable/menu_item_background"
                    android:padding="16dp" />

                <!-- Random Mode Toggle -->
                <LinearLayout
                    android:id="@+id/randomModeContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:background="@drawable/menu_item_background"
                    android:gravity="center_vertical"
                    android:orientation="horizontal"
                    android:padding="16dp">

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="@string/random_mode"
                        android:textSize="18sp"
                        android:textColor="@android:color/white" />

                    <Switch
                        android:id="@+id/randomModeSwitch"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:scaleX="1.5"
                        android:scaleY="1.5"
                        android:thumbTint="@color/switch_thumb_color"
                        android:trackTint="@color/switch_track_color" />
                </LinearLayout>

                <!-- Back Button -->
                <Button
                    android:id="@+id/customizationBackButton"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="32dp"
                    android:background="@color/transparent"
                    android:text="@string/back"
                    android:textColor="@color/white"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:fontFamily="sans-serif"
                    android:textAllCaps="false" />
            </LinearLayout>
        </ScrollView>
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout> 