/* 全域樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 15px;
    color: #333;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* 標題區域 */
header {
    text-align: center;
    color: white;
    margin-bottom: 15px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

header h1 {
    font-size: 2em;
    margin-bottom: 5px;
}

.subtitle {
    font-size: 1em;
    opacity: 0.9;
}

/* 主內容區域 */
.main-content {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 15px;
    background: white;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* 控制面板 */
.control-panel {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    overflow-y: auto;
    max-height: 100%;
}

.panel-section {
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 1px solid #dee2e6;
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-section h2 {
    font-size: 1.1em;
    margin-bottom: 10px;
    color: #495057;
    font-weight: 600;
}

.control-group {
    margin-bottom: 15px;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #495057;
    font-size: 0.9em;
}

.control-group input[type="range"] {
    width: 100%;
    cursor: pointer;
}

.control-group input[type="color"] {
    width: 100%;
    height: 40px;
    border: 2px solid #dee2e6;
    border-radius: 5px;
    cursor: pointer;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* 按鈕樣式 */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #5a6268;
    transform: translateY(-2px);
}

.btn-small {
    padding: 8px 12px;
    font-size: 0.9em;
}

.btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 視覺化區域 */
.visualization-area {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow: visible;
}

.grid-container {
    background: #fff;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: visible;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.1);
}

.grid {
    display: grid;
    gap: 2px;
    background: #e9ecef;
    padding: 2px;
    border-radius: 5px;
}

.grid-cell {
    background: white;
    border: 1px solid #dee2e6;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    min-width: 40px;
    min-height: 30px;
}

.grid-cell:hover {
    border-color: #667eea;
    z-index: 10;
}

.grid-cell.obstacle {
    background: #000000;
}

.grid-cell.target {
    background: #ffffff;
}

.grid-cell.filled {
    background: #4CAF50;
    animation: fillAnimation 0.3s ease;
}

.grid-cell.checking {
    background: #ff4444;
    animation: pulse 0.5s ease infinite;
}

.grid-cell.checked {
    background: #e0e0e0;
}

.grid-cell.start {
    border: 3px solid #ff9800;
    box-shadow: 0 0 10px rgba(255, 152, 0, 0.5);
}

@keyframes fillAnimation {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* 資訊面板 */
.info-panel {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 15px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.info-label {
    font-size: 0.85em;
    color: #6c757d;
    font-weight: 500;
}

.info-value {
    font-size: 1.3em;
    font-weight: 700;
    color: #495057;
}

/* 佇列視覺化 */
.queue-visualization {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 15px;
    max-height: 200px;
    overflow-y: auto;
}

.queue-visualization h3 {
    font-size: 1em;
    margin-bottom: 10px;
    color: #495057;
}

.queue-items {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.queue-item {
    background: #667eea;
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 0.85em;
    font-weight: 500;
}

/* 說明按鈕 */
.info-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

/* 說明面板 */
.info-panel-content {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.info-header {
    background: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 2001;
}

.info-header h2 {
    margin: 0;
    color: #495057;
}

.info-body {
    background: white;
    max-width: 900px;
    margin: 0 auto;
    padding: 30px;
    flex: 1;
}

.info-section {
    margin-bottom: 40px;
    padding-bottom: 30px;
    border-bottom: 2px solid #e9ecef;
}

.info-section:last-child {
    border-bottom: none;
}

.info-section h3 {
    color: #667eea;
    font-size: 1.5em;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #667eea;
}

.info-section h4 {
    color: #495057;
    font-size: 1.2em;
    margin-top: 20px;
    margin-bottom: 10px;
}

.info-section p {
    line-height: 1.8;
    color: #495057;
    margin-bottom: 15px;
}

.info-section ol,
.info-section ul {
    margin-left: 20px;
    margin-bottom: 15px;
    line-height: 1.8;
}

.info-section li {
    margin-bottom: 8px;
    color: #495057;
}

.info-section li strong {
    color: #667eea;
}

.range-example {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    border-left: 4px solid #667eea;
}

.range-example h4 {
    color: #667eea;
    margin-top: 0;
}

.code-block {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 15px;
    border-radius: 5px;
    overflow-x: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.5;
    margin: 15px 0;
}

.code-block::before {
    content: '';
}

/* Footer */
.footer {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    text-align: center;
    padding: 12px;
    margin-top: 15px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

.footer-content {
    max-width: 1600px;
    margin: 0 auto;
}

.footer-content p {
    margin: 0;
    font-size: 0.9em;
    opacity: 0.9;
}

.footer-content strong {
    color: white;
    font-weight: 600;
}

/* 響應式設計 */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 300px 1fr;
    }
}

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .control-panel {
        max-height: none;
    }

    header h1 {
        font-size: 1.8em;
    }

    .info-panel {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 捲軸樣式 */
.control-panel::-webkit-scrollbar,
.queue-visualization::-webkit-scrollbar {
    width: 8px;
}

.control-panel::-webkit-scrollbar-track,
.queue-visualization::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.control-panel::-webkit-scrollbar-thumb,
.queue-visualization::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.control-panel::-webkit-scrollbar-thumb:hover,
.queue-visualization::-webkit-scrollbar-thumb:hover {
    background: #555;
}

