* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #EDE8E3;
    color: #2d2d2d;
    line-height: 1.6;
    min-height: 100vh;
    overflow-y: scroll;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 28px 20px 40px;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #4A5E4F;
    margin-bottom: 20px;
    letter-spacing: -0.3px;
}


.footer {
    max-width: 960px;
    margin: 0 auto;
    padding: 16px 20px;
    text-align: center;
    font-size: 0.8rem;
    color: #888;
    border-top: 1px solid #D5CEC3;
}

.input-section {
    background: #fff;
    border: 1px solid #D5CEC3;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.input-row {
    display: flex;
    gap: 20px;
    margin-bottom: 16px;
}

.input-group {
    display: flex;
    flex-direction: column;
}

.grammar-input { flex: 2; }
.string-input  { flex: 1; }

label {
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: #3a3a3a;
    display: flex;
    align-items: center;
    gap: 5px;
}

.symbol-buttons {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.symbol-label {
    font-size: 0.75rem;
    color: #888;
    font-weight: 500;
}

.btn-symbol {
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    font-size: 0.85rem;
    font-weight: 700;
    width: 32px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid #D5CEC3;
    background: #f4f1ed;
    color: #4A5E4F;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-symbol:hover {
    background: #7A6680;
    border-color: #7A6680;
    color: #fff;
}

.label-icon {
    font-size: 0.9rem;
    opacity: 0.5;
}

textarea,
input[type="text"] {
    font-family: 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
    font-size: 0.88rem;
    padding: 10px 12px;
    border: 1.5px solid #D5CEC3;
    background: #F7F5F2;
    color: #2d2d2d;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

textarea:focus,
input[type="text"]:focus {
    border-color: #7A6680;
    box-shadow: 0 0 0 2px rgba(122,102,128,0.15);
    background: #fff;
}

textarea {
    resize: vertical;
    min-height: 110px;
}

textarea::placeholder,
input::placeholder {
    color: #b0b5bf;
}

small {
    font-size: 0.73rem;
    color: #888;
    margin-top: 6px;
}

small code {
    background: #EDE8E3;
    padding: 1px 5px;
    font-size: 0.72rem;
    color: #444;
}

.examples {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.examples-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
}

.btn-example {
    font-size: 0.8rem;
    padding: 6px 14px;
    border: 2px solid #7A6680;
    background: #fff;
    color: #7A6680;
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.btn-example:hover {
    background: #7A6680;
    color: #fff;
}

.btn-example:active {
    background: #634F6A;
    border-color: #634F6A;
    color: #fff;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    background: #4A5E4F;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.2px;
}

.btn-primary:hover {
    background: #3D4F42;
}

.btn-primary:active {
    background: #324138;
}

.btn-icon {
    font-size: 1.05rem;
}

.error {
    background: #fff5f5;
    border: 1px solid #e0b0b0;
    border-left: 4px solid #c0392b;
    color: #8b1a1a;
    padding: 12px 16px;
    font-size: 0.86rem;
    margin-bottom: 20px;
    white-space: pre-wrap;
    font-family: 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
}

.hidden {
    display: none !important;
}

.output-section {
    margin-top: 8px;
}

.derivations {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.derivations .panel { flex: 1; }

.panel {
    background: #fff;
    border: 1px solid #D5CEC3;
    padding: 18px 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.panel-left  { border-top: 3px solid #7A6680; }
.panel-right { border-top: 3px solid #A8B8A0; }

.tree-panel {
    border-top: 3px solid #D4AD96;
    margin-bottom: 16px;
}

.panel h2 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: #4A5E4F;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #E0DBD5;
}

.panel-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    font-size: 0.72rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.badge-left  { background: #7A6680; }
.badge-right { background: #A8B8A0; }
.badge-tree  { background: #D4AD96; color: #4A5E4F; }

.derivation-compact {
    font-family: 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
    font-size: 0.88rem;
    line-height: 1.9;
    padding: 10px 12px;
    background: #F5F2EE;
    border: 1px solid #E0DBD5;
    word-wrap: break-word;
    overflow-x: auto;
}

.derivation-compact .arrow {
    color: #888;
    margin: 0 3px;
    font-size: 0.82rem;
}

.derivation-steps {
    margin-top: 12px;
    padding-top: 0;
}

.derivation-step {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 5px 8px;
    font-family: 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
    font-size: 0.82rem;
    transition: background 0.15s;
}

.derivation-step:hover {
    background: #EDE8E3;
}

.step-num {
    color: #999;
    font-size: 0.72rem;
    min-width: 48px;
    text-align: right;
    font-weight: 500;
}

.step-form { flex: 1; }

.step-prod {
    color: #888;
    font-size: 0.72rem;
    white-space: nowrap;
}

.nt { color: #7A6680; font-weight: 700; }
.t  { color: #2d2d2d; }
.eps { color: #aaa; font-style: italic; }

.canvas-wrapper {
    overflow: auto;
    max-height: 520px;
    background: #F7F5F2;
    border: 1px solid #E0DBD5;
    text-align: center;
    padding: 16px;
}

.canvas-wrapper canvas {
    display: inline-block;
}

@media (max-width: 640px) {
    .input-row { flex-direction: column; }
    .derivations { flex-direction: column; }
    h1 { font-size: 1.3rem; }
    .input-section { padding: 16px; }
}
