@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500;600&display=swap');

:root {
    --primary:       #6366f1;
    --primary-dark:  #4f46e5;
    --primary-light: #e0e7ff;
    --accent:        #ec4899;
    --accent-light:  #fce7f3;
    --success:       #10b981;
    --error:         #ef4444;
    --warning:       #f59e0b;
    --bg-primary:    #ffffff;
    --bg-secondary:  #f8fafc;
    --bg-tertiary:   #f1f5f9;
    --text-primary:  #1e293b;
    --text-secondary:#64748b;
    --border:        #e2e8f0;
    --border-dark:   #cbd5e1;
    --shadow-sm:     0 1px 2px rgba(0,0,0,0.05);
    --shadow-md:     0 4px 6px rgba(0,0,0,0.07);
    --shadow-lg:     0 10px 15px rgba(0,0,0,0.1);
    --shadow-xl:     0 20px 25px rgba(0,0,0,0.1);

    --g0-bg:   #e0e7ff; --g0-fg: #6366f1;
    --g1-bg:   #fce7f3; --g1-fg: #ec4899;
    --g2-bg:   #d1fae5; --g2-fg: #10b981;
    --g3-bg:   #fef3c7; --g3-fg: #f59e0b;
    --g4-bg:   #dbeafe; --g4-fg: #3b82f6;
    --g5-bg:   #f3e8ff; --g5-fg: #8b5cf6;
}

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

html, body { height: 100%; scroll-behavior: smooth; }

.main-body {
    font-family: 'Geist', sans-serif;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, #f0f4f8 100%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1500px;
    margin: 0 auto;
    padding: 1rem 1rem 2rem;
}

.header {
    text-align: center;
    margin-bottom: 0.75rem;
    animation: slideDown 0.5s ease-out;
}

.title {
    font-size: clamp(1.6rem, 5vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
}

.title .accent {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
    align-items: start;
}

.panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.left-panel {
    height: calc(100vh - 120px);
    min-height: 600px;
}

.left-panel .config-card {
    flex: 0 0 auto;
    max-height: 55%;
    overflow-y: auto;
}

.left-panel .process-card {
    flex: 1 1 0;
    min-height: 200px; 
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.left-panel .process-card .algorithm-view {
    flex: 1 1 0;
    overflow: auto;
}

.right-panel {
    height: calc(100vh - 120px);
    min-height: 600px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.graph-card {
    flex: 1 1 0;
    min-height: 220px;
    display: flex;
    flex-direction: column;
}

.graph-card .graph-container {
    flex: 1 1 0;
    min-height: 0;
}

.bottom-row {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    min-height: 220px;
    max-height: 380px;
    height: clamp(220px, 30vh, 380px);
}

.steps-card, .trans-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 0.85rem 1rem;
    box-shadow: var(--shadow-md);
    transition: box-shadow 0.25s ease, border-color 0.25s ease;
    animation: slideUp 0.5s ease-out 0.1s backwards;
}

.card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-light);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.card-header .card-title { margin-bottom: 0; }

.badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.3rem 0.65rem;
    border-radius: 0.5rem;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.form-group { margin-bottom: 0.9rem; }
.form-group:last-child { margin-bottom: 0; }

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: var(--text-primary);
}

.input, .select, .textarea {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    font-family: 'Geist', sans-serif;
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.textarea {
    resize: vertical;
    min-height: 85px;
    font-family: 'Geist Mono', monospace;
    font-size: 0.82rem;
}

.help-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.35rem;
}

.hidden { display: none; }

.button-group {
    display: flex;
    gap: 0.6rem;
    margin-top: 1rem;
}

.nav-buttons { margin-top: auto; padding-top: 0.5rem; }

.btn {
    flex: 1;
    padding: 0.65rem 1rem;
    border: none;
    border-radius: 0.65rem;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.25s ease;
    font-family: 'Geist', sans-serif;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--border); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-light); }

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

.step-content {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 0.65rem 0.85rem;
    background: var(--bg-secondary);
    border-radius: 0.65rem;
    border-left: 3px solid var(--primary);
    line-height: 1.6;
    overflow-y: auto;
    flex: 1 1 0;
    min-height: 0;
}

.step-counter {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 0.4rem;
    text-align: center;
    flex-shrink: 0;
}
.step-counter.hidden { display: none; }

.graph-container {
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background: white;
    border-radius: 0.65rem;
    border: 1px solid var(--border);
    height: 100%;
}

.graph-container svg {
    display: block;
    width: 100%;
    height: 100%;
}

.placeholder {
    font-size: 3rem;
    color: #cbd5e1;
    animation: float 3s ease-in-out infinite;
}

.placeholder-text {
    color: #a0aec0;
    font-size: 0.85rem;
    text-align: center;
}

.algorithm-view {
    overflow: auto;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: 0.65rem;
}

.table-cell {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    font-size: 0.72rem;
    font-weight: 500;
    background: white;
    transition: all 0.25s ease;
}

.table-cell.marked  { background: var(--error); color: white; font-weight: 700; }
.table-cell.header  { background: var(--bg-tertiary); font-weight: 600; color: var(--text-primary); }
.table-cell.current {
    border: 2px solid var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light) inset;
    transform: scale(1.08);
    z-index: 1;
    position: relative;
}

.partitions-container { display: flex; flex-wrap: wrap; gap: 0.65rem; align-content: flex-start; }

.partition-group {
    padding: 0.65rem 0.85rem;
    border: 2px solid var(--primary-light);
    border-radius: 0.65rem;
    background: var(--primary-light);
    animation: slideUp 0.3s ease-out;
    transition: box-shadow 0.2s;
}

.partition-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--primary);
    margin-bottom: 0.3rem;
    letter-spacing: 0.05em;
}

.partition-states {
    font-family: 'Geist Mono', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.transition-table-view {
    overflow-y: auto;
    overflow-x: auto;
    flex: 1 1 0;
    min-height: 0;
}

.trans-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.76rem;
    font-family: 'Geist', sans-serif;
}

.trans-table th,
.trans-table td {
    padding: 0.22rem 0.45rem;
    border: 1px solid var(--border);
    text-align: center;
    transition: background 0.2s;
}

.trans-header-cell {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary);
    position: sticky;
    top: 0;
    z-index: 2;
}

.sym-highlight {
    background: var(--accent-light) !important;
    color: var(--accent);
}

.row-highlight td { background: #f0f4ff; }

.trans-state-cell {
    font-weight: 600;
    text-align: left;
    font-family: 'Geist Mono', monospace;
    font-size: 0.78rem;
    white-space: nowrap;
    color: var(--text-secondary);
}

.state-active {
    background: var(--primary) !important;
    color: white !important;
    font-weight: 700;
    border-radius: 0;
}

.accept-state { font-style: italic; }

.trans-data-cell { color: var(--text-primary); }

.cell-active {
    background: linear-gradient(135deg, var(--primary-light), var(--accent-light)) !important;
    font-weight: 700;
    border: 1.5px solid var(--primary) !important;
    color: var(--primary-dark);
}

.tutorial-section {
    background: white;
    border-top: 2px solid var(--border);
    padding: 2.5rem 1.5rem;
    border-radius: 1.25rem;
    margin-top: 2rem;
}

.tutorial-title {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.tutorial-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.tutorial-item { display: flex; gap: 1.25rem; }

.tutorial-number {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    color: white;
    font-weight: 700;
    font-size: 1.2rem;
    border-radius: 50%;
}

.tutorial-item h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.4rem; color: var(--text-primary); }
.tutorial-item p  { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 0.4rem; line-height: 1.6; }
.tutorial-item strong { color: var(--text-primary); font-weight: 600; }

.example-box {
    background: var(--bg-secondary);
    border-left: 4px solid var(--primary);
    padding: 1.25rem;
    border-radius: 0.65rem;
    margin-top: 1.5rem;
}

.example-box h3 { margin-bottom: 0.75rem; font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }

.example-code {
    background: white;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.85rem;
    font-family: 'Geist Mono', monospace;
    font-size: 0.82rem;
    color: var(--text-primary);
    overflow-x: auto;
    line-height: 1.6;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-8px); }
}

@media (max-width: 1100px) {
    .layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .left-panel, .right-panel {
        height: auto;
        min-height: unset;
    }

    .left-panel .process-card { min-height: 200px; }

    .graph-card { min-height: 320px; }

    .bottom-row { height: auto; }

    .steps-card, .trans-card { min-height: 220px; }
}

@media (max-width: 680px) {
    .container { padding: 0.75rem 0.5rem 1.5rem; }
    .bottom-row { grid-template-columns: 1fr; }
    .table-cell { width: 34px; height: 34px; font-size: 0.7rem; }
    .tutorial-content { grid-template-columns: 1fr; }
}