body {
    font-family: system-ui, -apple-system, sans-serif;
}

svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Crosshair only on the drawing canvas. A bare `svg` selector also hit every
   icon inside the toolbar and zoom buttons, so hovering an icon showed a
   crosshair instead of the button's pointer. */
#automaton-canvas {
    cursor: crosshair;
}

.node {
    cursor: move;
}

.node-circle {
    fill: white;
    stroke: #333;
    stroke-width: 2;
    transition: fill 0.2s;
}

.node:hover .node-circle {
    fill: #f0fdf4;
    stroke: #16a34a;
}

.node.selected .node-circle {
    stroke: #2563eb;
    stroke-width: 3;
    fill: #eff6ff;
}

@keyframes nodePulse {
    from { stroke-width: 2; fill: #ffffff; }
    to { stroke-width: 4; fill: #fef3c7; }
}

.node.drawing-edge .node-circle {
    stroke: #f59e0b;
    animation: nodePulse 0.5s infinite alternate;
}

.accept-circle {
    fill: none;
    stroke: #333;
    stroke-width: 1.5;
    pointer-events: none;
}

.node:hover .accept-circle {
    stroke: #16a34a;
}

.node.selected .accept-circle {
    stroke: #2563eb;
}

.katex-container {
    color: #333;
    transition: color 0.2s;
}

.node:hover .katex-container {
    color: #16a34a;
    font-weight: bold;
}

.node.selected .katex-container {
    color: #2563eb;
    font-weight: bold;
}

.start-arrow {
    fill: none;
    stroke: #333;
    stroke-width: 2;
    marker-end: url(#arrowhead);
    pointer-events: none;
    transition: stroke 0.2s;
}

.node.selected .start-arrow {
    stroke: #2563eb;
}

.edge-path {
    fill: none;
    stroke: #666;
    stroke-width: 2;
    marker-end: url(#arrowhead);
    cursor: pointer;
    transition: stroke-width 0.2s, stroke 0.2s;
}

.edge-path:hover {
    stroke-width: 4;
    stroke: #16a34a;
}

.edge.selected .edge-path {
    stroke: #2563eb;
    stroke-width: 3;
}

.temp-edge {
    fill: none;
    stroke: #94a3b8;
    stroke-width: 2;
    stroke-dasharray: 5, 5;
    marker-end: url(#arrowhead-temp);
    pointer-events: none;
}

#selection-box {
    fill: rgba(37, 99, 235, 0.1);
    stroke: #2563eb;
    stroke-width: 1;
    stroke-dasharray: 4;
    pointer-events: none;
}

#automaton-canvas:focus-visible {
    outline: 3px solid #2563eb;
    outline-offset: -3px;
}

/* ---------- Keyboard key hints ---------- */

kbd {
    display: inline-block;
    min-width: 1.4em;
    padding: 0 0.35em;
    border: 1px solid #cbd5e1;
    border-bottom-width: 2px;
    border-radius: 4px;
    background: #f8fafc;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.8em;
    line-height: 1.5;
    text-align: center;
    color: #334155;
}

/* ---------- Simulation ---------- */

.sim-type-badge:empty {
    display: none;
}

.sim-type-badge {
    padding: 0 0.4em;
    border-radius: 9999px;
    background: #e0e7ff;
    color: #3730a3;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    cursor: help;
}

.sim-icon-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: transparent;
}

.sim-output {
    margin-top: 0.375rem;
}

.sim-output:not(:has(> :not(:empty))) {
    display: none;
}

.sim-tape:empty,
.sim-status:empty {
    display: none;
}

.sim-tape {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    max-width: 100%;
}

.sim-symbol {
    min-width: 1.5rem;
    padding: 0 0.3rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85rem;
    line-height: 1.5rem;
    text-align: center;
    color: #0f172a;
}

.sim-symbol-read {
    color: #94a3b8;
    background: #f1f5f9;
}

.sim-symbol-current {
    border-color: #f59e0b;
    background: #fef3c7;
    font-weight: 700;
    box-shadow: 0 0 0 1px #f59e0b;
}

.sim-symbol-stuck {
    border-color: #dc2626;
    background: #fee2e2;
    box-shadow: 0 0 0 1px #dc2626;
}

.sim-symbol-empty {
    font-style: italic;
    color: #64748b;
}

.sim-status {
    font-size: 0.85rem;
    color: #334155;
}

.sim-status-accepted {
    color: #15803d;
}

.sim-status-rejected,
.sim-status-error {
    color: #b91c1c;
}

.sim-state-name .katex {
    font-size: 1em;
}

/* ---------- Language L(M) ---------- */

.lang-row {
    margin-top: 0.375rem;
    padding-top: 0.375rem;
    border-top: 1px solid #f1f5f9;
}

.lang-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
    border-radius: 4px;
}

.lang-toggle:hover {
    color: #1e293b;
}

.lang-toggle:focus-visible,
.lang-copy:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.lang-chevron {
    width: 0.9rem;
    height: 0.9rem;
    transition: transform 0.15s ease;
}

.lang-toggle[aria-expanded="true"] .lang-chevron {
    transform: rotate(90deg);
}

.lang-output {
    margin-top: 0.25rem;
    padding: 0.375rem 0.5rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
}

.lang-output.hidden {
    display: none;
}

.lang-expression {
    overflow-x: auto;
    overflow-y: hidden;
    max-height: 5.5rem;
    padding: 0.125rem 0;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #0f172a;
}

.lang-output-error .lang-expression {
    font-size: 0.85rem;
    color: #b91c1c;
}

.lang-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem 0.75rem;
}

.lang-meta {
    font-size: 0.75rem;
    color: #64748b;
}

.lang-meta:empty {
    display: none;
}

.lang-copy {
    flex-shrink: 0;
    padding: 0 0.4rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    font-size: 0.75rem;
    color: #334155;
}

.lang-copy:hover {
    background: #f1f5f9;
}

.lang-copy.hidden {
    display: none;
}

.node.sim-active .node-circle {
    fill: #fef3c7;
    stroke: #f59e0b;
    stroke-width: 4;
}

.node.sim-active.sim-accepted .node-circle {
    fill: #dcfce7;
    stroke: #16a34a;
}

.node.sim-active.sim-rejected .node-circle {
    fill: #fee2e2;
    stroke: #dc2626;
}

.edge.sim-taken .edge-path {
    stroke: #f59e0b;
    stroke-width: 3.5;
}

/* ---------- On-canvas hint and edge-drawing banner ---------- */

.onboarding-hint,
.edge-draft-banner {
    position: absolute;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 25;
    width: max-content;
    max-width: calc(100% - 1rem);
    padding: 0.4rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    line-height: 1.35;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
}

.onboarding-hint {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: #1e293b;
    color: #f8fafc;
}

.onboarding-hint.hidden,
.edge-draft-banner.hidden {
    display: none;
}

/* On small screens the hint leaves the canvas overlay and becomes a slim
   full-width bar above the canvas (see OnboardingHint.updatePlacement), so
   the diagram stays fully visible and tappable. Desktop is unchanged. */
@media (max-width: 639px) {
    .onboarding-hint.onboarding-hint--inline {
        position: static;
        transform: none;
        width: 100%;
        max-width: 100%;
        margin-bottom: 0.5rem;
    }
}

.onboarding-link {
    flex-shrink: 0;
    color: #93c5fd;
    text-decoration: underline;
    white-space: nowrap;
}

.onboarding-close {
    flex-shrink: 0;
    font-size: 1.2rem;
    line-height: 1;
    color: #cbd5e1;
}

.onboarding-close:hover,
.onboarding-link:hover {
    color: #fff;
}

.edge-draft-banner {
    background: #fffbeb;
    border: 1px solid #f59e0b;
    color: #78350f;
    pointer-events: none;
}

.edge-draft-banner .katex {
    font-size: 1em;
}

/* ---------- Toasts ---------- */

.toast-container {
    position: fixed;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: max-content;
    max-width: calc(100vw - 1.5rem);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.5rem;
    background: #1e293b;
    color: #f8fafc;
    font-size: 0.875rem;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
    pointer-events: auto;
    animation: toastIn 0.18s ease-out;
    transition: opacity 0.2s, transform 0.2s;
}

.toast-leaving {
    opacity: 0;
    transform: translateY(6px);
}

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

.toast-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    border-radius: 9999px;
    background: #475569;
    font-size: 0.75rem;
    font-weight: 700;
}

.toast-success .toast-icon {
    background: #16a34a;
}

.toast-error {
    background: #7f1d1d;
}

.toast-error .toast-icon {
    background: #dc2626;
}

.toast-action {
    flex-shrink: 0;
    padding: 0.1rem 0.5rem;
    border-radius: 0.25rem;
    background: rgba(255, 255, 255, 0.15);
    font-weight: 600;
    color: #fff;
}

.toast-action:hover {
    background: rgba(255, 255, 255, 0.28);
}

.toast-close {
    flex-shrink: 0;
    font-size: 1.1rem;
    line-height: 1;
    color: #cbd5e1;
}

/* ---------- Help dialog ---------- */

.help-dialog::backdrop {
    background: rgba(15, 23, 42, 0.45);
}

@media (prefers-reduced-motion: reduce) {
    .toast,
    .node.drawing-edge .node-circle {
        animation: none;
    }
}

/* When main's content overflows (on small screens: canvas plus an open
   properties panel), plain `justify-content: center` clips the overflow at
   the top, hiding the top of the diagram behind the onboarding hint bar with
   no way to scroll to it. Safe centering keeps normal centering when content
   fits, but aligns to the start on overflow, so the diagram always stays
   below the hint bar and the panel scrolls into view instead. Browsers
   without safe-alignment support keep the previous centering. */
@supports (justify-content: safe center) {
    main.justify-center {
        justify-content: safe center;
    }
}
