
/* asymptote-wiki base styles */

:root {
    --color-bg: #fafafa;
    --color-text: #222;
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-danger: #dc2626;
    --color-border: #e5e7eb;
    --color-card-bg: #fff;
    --color-code-bg: #f3f4f6;
    /* Fluid side gutters: grow with the viewport (16px -> 80px). There is no
       fixed content ceiling, so galleries and figures fill the window wide. */
    --gutter: clamp(1rem, 4vw, 5rem);
    /* Reading column and prose line-length, in *characters* (not pixels):
       they scale with the font size, and a block's auto width means they fill
       (never overflow) narrow screens. */
    --content-max: 100ch; /* reading / editing column width */
    --measure: 72ch;      /* comfortable prose line length */
    --radius: 6px;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    margin: 0;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
header {
    background: #fff;
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem var(--gutter);
}

nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
}

/* Main */
main {
    margin: 1rem auto;
    padding: 0 var(--gutter);
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 1rem;
    color: #6b7280;
    font-size: 0.875rem;
}

/* Index layout with sidebar */
.index-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 2rem;
    align-items: start;
}
.sidebar {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    overflow-x: auto;
}
.sidebar h2 { font-size: 1rem; margin-bottom: 0.5rem; }
.cat-tree { list-style: none; padding: 0; width: max-content; }
.cat-tree li { margin: 0.15rem 0; }
.cat-tree ul { list-style: none; padding-left: 1rem; }
.cat-tree a {
    display: block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
    white-space: nowrap;
}
.cat-tree a:hover { background: var(--color-code-bg); text-decoration: none; }
.cat-tree a.active { background: var(--color-primary); color: #fff; }
/* Up/breadcrumb nav row for gallery (category) pages: always on its own line,
   shown at the top and the bottom (mirrors the example-page pager). */
.gallery-nav {
    display: flex;
    gap: 0.5rem;
    margin: 0.5rem 0 1rem;
}
/* The bottom copy sits right after the cards (which end tighter than the h1
   does), so give it a bit more breathing room above it. */
.gallery-nav-bottom {
    margin-top: 1.5rem;
}
.gallery-main { min-width: 0; }
.gallery-main h1 { text-align: center; }
.subtitle-block { margin-bottom: 0.5rem; text-align: center; }
.subtitle-block p { margin: 0; }

@media (max-width: 700px) {
    .index-layout { grid-template-columns: 1fr; }
    .sidebar {
        position: static;
        max-height: none;
        overflow: visible;
        margin-bottom: 1rem;
    }
}

/* Gallery grid */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.card {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: box-shadow 0.15s;
}
.card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }

.card-thumb {
    display: block;
    height: 200px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-bottom: 1px solid var(--color-border);
}
.thumb-frame {
    width: 100%;
    height: 100%;
    border: none;
}
/* 2D previews are static: let pointer events fall through to the surrounding
   <a class="card-thumb"> so clicking the thumbnail opens the page. (Losing
   pointer events is harmless -- there is nothing inside to interact with.) */
.thumb-frame-2d {
    pointer-events: none;
}
/* 3D previews are live WebGL viewports: keep them interactive and signal
   "drag me" rather than "click me". */
.thumb-frame-3d {
    cursor: grab;
}
.thumb-frame-3d:active {
    cursor: grabbing;
}
/* Subtle press cue on the (clickable) 2D thumbnails. */
.card-thumb:hover .thumb-frame-2d {
    filter: brightness(0.97);
}
.no-thumb { color: #9ca3af; font-style: italic; }

.card-body { padding: 1rem; }
.card-body h3 { margin: 0 0 0.25rem; font-size: 1rem; }
.card-meta { color: #6b7280; font-size: 0.8rem; margin: 0; }

/* Tags */
.tags { margin-top: 0.5rem; }
.tag {
    display: inline-block;
    background: var(--color-code-bg);
    border-radius: 3px;
    padding: 0.1rem 0.4rem;
    font-size: 0.75rem;
    margin-right: 0.25rem;
    color: #4b5563;
}

/* Example page */
.example-page { max-width: var(--content-max); }
.page-header {
    margin-bottom: 1.5rem;
    max-width: var(--content-max);
}
.page-header h1 { margin: 0.25rem 0; }
.example-nav {
    display: flex;
    gap: 0.5rem;
    margin: 0.25rem 0 1rem;
}
.page-meta { color: #6b7280; font-size: 0.9rem; }

.page-content {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
}
/* Reading measure: keep prose at a comfortable width, but let figures and
   collapsible source blocks (.asy-output / .asy-source) span the full column. */
.page-content > :not(.asy-output):not(.asy-source) {
    max-width: var(--measure);
}

/* Asymptote output blocks */
.asy-output {
    margin: 1rem 0;
    text-align: center;
    background: #fff;
}
/* Separate stacked figures: a divider before every figure except the first. */
.page-content > .asy-output:not(:first-child) {
    border-top: 1px solid var(--color-border);
    padding-top: 1rem;
}
/* The figure title sits right at the top of its card. */
.asy-output h3 { margin-top: 0; }
/* ...and the first card has no extra margin above it either. */
.page-content > .asy-output:first-child { margin-top: 0; }
.asy-svg svg { max-width: 100%; height: auto; }
.asy-html iframe {
    border: none;
    display: block;
}
.asy-pdf iframe {
    border: none;
    display: block;
}
.asy-output-bar {
    margin-top: 0.5rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-code-bg);
}

.asy-source {
    margin: 0.25rem 0 1rem;
    text-align: left;
}
.asy-source summary {
    cursor: pointer;
    color: var(--color-primary);
    font-size: 0.875rem;
    padding: 0.25rem 0;
}
.asy-source pre {
    background: var(--color-code-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.5;
}

.compile-error {
    color: var(--color-danger);
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 1rem;
    font-family: monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
}

/* Source files section */
.source-files {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}
.file-list { list-style: none; padding: 0; }
.file-list li { margin: 0.25rem 0; display: flex; align-items: center; gap: 0.5rem; }
.inline-form { display: inline; margin: 0; }
.btn-sm {
    padding: 0.15rem 0.5rem;
    font-size: 0.8rem;
}
/* Uniform navigation arrows. The text glyphs (&larr; &uarr; &rarr;) fall back
   to different fonts per code point and render at inconsistent sizes; these
   inline SVGs inherit the button's color and a single size, so up/prev/next
   look identical everywhere. */
.nav-arrow {
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
}
.add-file-form {
    margin-top: 1rem;
    display: flex;
    gap: 0.25rem;
    align-items: center;
}
.add-file-form input[type="file"] {
    font-size: 0.85rem;
    /* Hug the control: the UA default width (~258px) left a wide empty gap
       before the Add/Replace button. 200px fits "No file chosen" + "Choose
       file" with no clipping. */
    width: 200px;
}

/* Page actions */
.page-actions {
    margin: 1rem 0;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--color-text);
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none !important;
}
.btn:hover { background: var(--color-code-bg); }
.btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-danger {
    background: #fff;
    border-color: var(--color-danger);
    color: var(--color-danger);
}
.btn-danger:hover { background: #fef2f2; }

/* Forms */
form { max-width: var(--content-max); }
.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="file"],
.form-group textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.95rem;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.code-input {
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    font-size: 0.85rem;
}
.hint {
    color: #6b7280;
    font-size: 0.85rem;
    margin: 0.25rem 0;
}
.hint-block {
    background: var(--color-code-bg);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    overflow-x: auto;
}
.form-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 0.75rem;
}

/* Flash messages */
.flashes { margin-bottom: 1rem; }
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}
.flash-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--color-danger);
}
.flash-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

/* Markdown toolbar + preview */
.md-toolbar {
    display: flex;
    gap: 0.3rem;
    margin-bottom: 0.4rem;
}
.md-btn { font-size: 0.8rem; padding: 0.2rem 0.5rem; }
.md-preview {
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius, 6px);
    padding: 0.75rem 1rem;
    background: #fafafa;
    min-height: 3rem;
    width: 100%;
    font-size: 0.95rem;
}
.md-preview .asy-placeholder {
    background: #f0f9ff;
    border: 1px dashed #93c5fd;
    padding: 0.5rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.85rem;
    color: #2563eb;
}

/* Search */
.search-form {
    display: flex;
    gap: 0.3rem;
    margin-bottom: 1.5rem;
    align-items: center;
}
.search-form input[type="text"] {
    flex: 1;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius, 6px);
    font-size: 0.9rem;
    min-width: 0;
}
.search-clear {
    border: none;
    background: none;
    font-size: 1.1rem;
    color: #9ca3af;
    cursor: pointer;
    padding: 0 0.3rem;
    line-height: 1;
}
.search-clear:hover { color: #374151; }
.match-info {
    font-size: 0.8rem;
    color: #6b7280;
    margin-top: 0.25rem;
}
.no-results {
    color: #6b7280;
    font-style: italic;
    padding: 1rem 0;
}

/* Utility */
.subtitle { color: #6b7280; }
.empty { color: #6b7280; font-style: italic; }

/* Responsive */
@media (max-width: 600px) {
    .gallery { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
}

