* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 90vw;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
    font-size: 2.5em;
}

.controls {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.input-group label {
    font-weight: bold;
    color: #555;
}

.input-group input {
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    width: 80px;
    transition: border-color 0.3s;
}

.input-group input[type="text"] {
    width: 150px;
}

.seed-input-wrapper {
    display: flex;
}

.seed-input-wrapper input {
    border-right: none !important;
    border-radius: 8px 0 0 8px !important;
    width: 150px;
}

#randomSeedBtn {
    padding: 10px 10px;
    border-radius: 0 8px 8px 0;
    font-size: 18px;
    line-height: 1;
    font-weight: normal;
    border: 2px solid transparent;
}

#randomSeedBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

#randomSeedBtn:active {
    transform: rotate(180deg);
}

.input-group select {
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: border-color 0.3s;
    background: white;
}

.input-group select:focus {
    outline: none;
    border-color: #667eea;
}


.seed-display {
    text-align: center;
    margin-bottom: 20px;
    padding: 10px;
    background: #f0f0f0;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #667eea;
    font-size: 14px;
}

button {
    padding: 12px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

button:active {
    transform: translateY(0);
}

.controls-actions {
    display: flex;
    gap: 20px;
}

#maze {
    display: inline-block;
    border: 3px solid #333;
    background: white;
    margin: 0 auto;
    display: flex;
    justify-content: center;
}

.maze-table {
    border-collapse: collapse;
}

.maze-cell {
    width: 20px;
    height: 20px;
    border: none;
    text-align: center;
    vertical-align: middle;
    font-size: 12px;
    font-weight: bold;
    color: white;
}

.maze-cell.wall {
    background-color: #333;
}

.maze-cell.path {
    background-color: #fff;
}

.maze-cell.start {
    background-color: #4CAF50;
    color: white;
}

.maze-cell.end {
    background-color: #f44336;
    color: white;
}

.print-only {
    display: none;
}

/* 手機版：2 欄 grid，label 疊在 input 上方，壓縮為 3 行 */
@media (max-width: 600px) {
    .controls {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 12px;
        align-items: end;
    }

    .input-group {
        display: block;
    }

    .input-group label {
        display: block;
        margin-bottom: 4px;
    }

    .input-group input,
    .input-group select {
        width: 100%;
        box-sizing: border-box;
    }

    .seed-input-wrapper {
        width: 100%;
        display: flex;
    }

    .seed-input-wrapper input {
        width: auto !important;
        min-width: 0;
        flex: 1;
    }

    #randomSeedBtn {
        padding: 10px 8px;
        flex-shrink: 0;
    }

    .controls-actions {
        grid-column: span 2;
        display: flex;
        gap: 12px;
    }

    .controls-actions button {
        flex: 1;
    }
}

/* 列印樣式 - 必須放在最後 */
@media print {
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    @page {
        size: A4;
        margin: 15mm;
    }
    
    body {
        background: white !important;
        padding: 0 !important;
        display: block !important;
        min-height: 0 !important;
    }
    
    .container {
        box-shadow: none !important;
        padding: 0 !important;
        border-radius: 0 !important;
        max-width: 100% !important;
        background: white !important;
    }
    
    .controls {
        display: none !important;
    }
    
    .print-only {
        display: block !important;
    }
    
    .footer {
        margin-top: 10mm !important;
        padding-top: 5mm !important;
        border-top: 1px solid #ddd !important;
        text-align: center !important;
        font-size: 10pt !important;
        color: #666 !important;
    }
    
    .footer p {
        margin: 0 !important;
    }
    
    h1 {
        margin-bottom: 5mm !important;
        font-size: 18pt !important;
        page-break-after: avoid !important;
        display: block !important;
    }
    
    .seed-display {
        margin-bottom: 5mm !important;
        background: white !important;
        border: 1px solid #ddd !important;
        page-break-after: avoid !important;
        font-size: 10pt !important;
        display: block !important;
    }
    
    #maze {
        display: block !important;
        border: 2px solid #333 !important;
        page-break-inside: avoid !important;
        margin: 0 auto 5mm auto !important;
        width: fit-content !important;
        background: white !important;
    }
    
    .maze-table {
        page-break-inside: avoid !important;
        display: table !important;
        border-collapse: collapse !important;
        margin: 0 auto !important;
    }
    
    .maze-table tr {
        display: table-row !important;
    }
    
    .maze-table td {
        display: table-cell !important;
    }
    
    .maze-cell {
        width: 5mm !important;
        height: 5mm !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
        text-align: center !important;
        vertical-align: middle !important;
        font-size: 8pt !important;
        font-weight: bold !important;
        line-height: 5mm !important;
    }
    
    .maze-cell.wall {
        background-color: #333 !important;
    }
    
    .maze-cell.path {
        background-color: #fff !important;
    }
    
    .maze-cell.start {
        background-color: #4CAF50 !important;
        color: white !important;
    }
    
    .maze-cell.end {
        background-color: #f44336 !important;
        color: white !important;
    }
}
