*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --bg: #0f1218;
    --panel: #171c26;
    --border: #2a3142;
    --text: #e8ecf4;
    --muted: #8b95a8;
    --accent: #3d8bfd;
    --accent-hover: #5aa3ff;
}

html,
body {
    margin: 0;
    height: 100%;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
    background: var(--bg);
    color: var(--text);
}

body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.app {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Same bar as fireguy.net: white, Dosis, navy top edge, red hover. */
.fg-bar {
    flex-shrink: 0;
    background: #fff;
    color: #2b2d42;
    border-top: 4px solid #2b2d42;
    box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.08);
    font-family: Dosis, sans-serif;
    z-index: 30;
}

.fg-bar-in {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1.5rem;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0.3rem 1.75rem;
    box-sizing: border-box;
}

.fg-logo {
    display: flex;
    align-items: center;
    line-height: 0;
}

.fg-logo img {
    height: 32px;
    width: auto;
}

.fg-toggle {
    display: none;
    padding: 0.4rem 0.75rem;
    border: 1px solid #2b2d42;
    border-radius: 3px;
    background: #fff;
    color: #2b2d42;
    font-family: Dosis, sans-serif;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
}

.fg-nav {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    justify-content: flex-end;
}

.fg-menu {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.2rem 1.15rem;
    width: auto;
    margin: 0;
    padding: 0;
    list-style: none;
}

.fg-menu > li {
    position: relative;
    display: flex;
    align-items: center;
}

.fg-menu a {
    color: #2b2d42;
    font-size: 16px;
    font-weight: 400;
    line-height: 1;
    text-decoration: none;
    text-transform: uppercase;
    padding: 2px 0;
    margin-left: 0;
    border-bottom: 2px solid transparent;
}

.fg-menu a:hover,
.fg-menu a:focus-visible {
    color: #000;
    border-bottom-color: #a30015;
}

.fg-drop-btn {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
    background: transparent;
    color: #2b2d42;
}

.fg-drop > ul {
    display: none;
    position: absolute;
    top: calc(100% - 2px);
    left: 0;
    z-index: 40;
    min-width: 220px;
    margin: 0;
    padding: 0.35rem 0;
    list-style: none;
    background: #fff;
    border: 1px solid #e4e4e8;
    box-shadow: 0 0.45rem 1.4rem rgba(0, 0, 0, 0.12);
}

.fg-drop:hover > ul,
.fg-drop:focus-within > ul,
.fg-drop.is-open > ul {
    display: block;
}

.fg-drop > ul a {
    display: block;
    margin: 0;
    padding: 0.5rem 0.9rem;
    border-bottom: 0;
    font-size: 16px;
    text-transform: none;
}

.fg-drop > ul a:hover,
.fg-drop > ul a:focus-visible {
    background: #f6f6f8;
    border-bottom-color: transparent;
}

.fg-contact > a {
    margin-left: 0;
    padding: 6px 12px;
    border: 0;
    border-radius: 3px;
    background: #2b2d42;
    color: #cacbd0;
    font-size: 16px;
}

.fg-contact > a:hover,
.fg-contact > a:focus-visible {
    background: #202232;
    color: #fff;
    border-bottom-color: transparent;
}

@media (max-width: 900px) {
    .fg-toggle {
        display: inline-flex;
    }

    .fg-drop-btn {
        position: static;
        width: auto;
        height: auto;
        margin: 0 0 0 0.35rem;
        padding: 0.35rem 0.45rem;
        overflow: visible;
        clip: auto;
        border: 1px solid #d5d5dc;
        border-radius: 3px;
        font-size: 0.8rem;
        line-height: 1;
        cursor: pointer;
    }

    .fg-nav {
        display: none;
        flex: 1 0 100%;
    }

    .fg-bar.is-open .fg-nav {
        display: block;
    }

    .fg-menu {
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 0;
        width: 100%;
    }

    .fg-menu > li {
        flex-wrap: wrap;
    }

    .fg-menu a {
        margin-left: 0;
        padding: 0.55rem 0;
    }

    .fg-drop > ul {
        position: static;
        display: none;
        width: 100%;
        min-width: 0;
        box-shadow: none;
        border: 0;
        padding: 0 0 0.35rem 0.75rem;
    }

    .fg-drop.is-open > ul,
    .fg-drop:focus-within > ul {
        display: block;
    }

    .fg-drop:hover > ul {
        display: none;
    }

    .fg-drop.is-open:hover > ul,
    .fg-drop.is-open > ul {
        display: block;
    }

    .fg-contact > a {
        display: inline-block;
        margin: 0.35rem 0 0;
    }
}

.header {
    flex-shrink: 0;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.subtitle {
    margin: 0.35rem 0 0;
    font-size: 0.875rem;
    color: var(--muted);
}

.layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
}

@media (max-width: 960px) {
    .layout {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(200px, 38dvh) minmax(0, 1fr);
    }
}

.viewport-wrap {
    position: relative;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: 0;
    height: 100%;
    align-content: start;
}

.preview-footer {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#viewport {
    min-height: 0;
    overflow: hidden;
    background: #1a1f2e;
    position: relative;
}

.font-load-error {
    position: absolute;
    left: 0.75rem;
    right: 0.75rem;
    bottom: 0.75rem;
    z-index: 2;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    background: rgba(40, 20, 20, 0.92);
    border: 1px solid #c44;
    color: #fcc;
    font-size: 0.8rem;
    line-height: 1.45;
    max-height: 40%;
    overflow: auto;
    white-space: pre-wrap;
}

.model-dimensions {
    margin: 0;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--muted);
    border-top: 1px solid var(--border);
    background: #141824;
}

.viewport-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    background: #141824;
}

.build-status {
    margin: 0;
    padding: 0.35rem 1rem 0;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--muted);
    background: #141824;
}

.build-status[data-kind='ok'] {
    color: #9ddeb8;
}

.build-status[data-kind='warn'] {
    color: #f0d48a;
}

.build-status[data-kind='error'] {
    color: #f0a8a8;
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

#font-filter {
    margin-bottom: 0.4rem;
}

.panel-gap {
    margin: 0.75rem 0;
}

.panel {
    border-left: 1px solid var(--border);
    background: var(--panel);
    padding: 1rem;
    overflow: auto;
    min-height: 0;
}

.panel-section {
    margin-bottom: 1.25rem;
}

.panel-section label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: var(--muted);
}

.section-title {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

input[type='text'],
input[type='search'],
input[type='number'],
input[type='file'],
textarea,
select {
    width: 100%;
    padding: 0.45rem 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #0f1218;
    color: var(--text);
    font-size: 0.9rem;
}

textarea {
    resize: vertical;
    min-height: 4rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.75rem;
}

/* Let grid cells shrink so flex children (numeric wraps) don’t overflow the panel */
#controls .grid-2 > div {
    min-width: 0;
}

.preset-buttons-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

#preset-buttons-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--muted);
}

.preset-buttons {
    display: flex;
    gap: 0.5rem;
}

.preset-buttons .preset-btn {
    flex: 1;
    min-width: 0;
}

.preset-buttons .preset-btn[aria-pressed='true'] {
    background: var(--accent);
    border-color: transparent;
    color: #fff;
}

.preset-buttons .preset-btn[aria-pressed='true']:hover {
    background: var(--accent-hover);
}

.hint {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

.inline-file {
    margin-top: 0.5rem;
    display: block;
}

.inline-file input {
    margin-top: 0.35rem;
}

.inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.inline input {
    width: auto;
}

button {
    padding: 0.5rem 0.85rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #222836;
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
}

button.primary {
    background: var(--accent);
    border-color: transparent;
    color: #fff;
}

button.primary:hover {
    background: var(--accent-hover);
}

button:hover:not(.primary) {
    background: #2a3142;
}

/* Panel numeric row: compact width (few digits); spin column stays fixed */
#controls .grid-2 > div > .char-field {
    width: fit-content;
    max-width: 100%;
    min-width: 0;
}

#controls .grid-2 > div > .char-field input[type='number'] {
    flex: 0 1 auto;
    width: 4.25rem;
    min-width: 2.75rem;
    max-width: 100%;
}

.char-rows-section {
    display: flex;
    flex-direction: column;
    min-width: 0;
    --char-rows-cols: minmax(2rem, auto) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
}

.char-rows-header-row {
    display: grid;
    grid-template-columns: var(--char-rows-cols);
    gap: 0.35rem;
    align-items: end;
    padding-bottom: 0.35rem;
    margin-bottom: 0.15rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.char-header-col {
    min-width: 0;
    line-height: 1.25;
}

.char-header-col:first-child {
    text-align: center;
}

.char-rows {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 220px;
    overflow: auto;
    padding: 0.25rem 0;
}

.char-row {
    display: grid;
    grid-template-columns: var(--char-rows-cols);
    gap: 0.35rem;
    align-items: stretch;
    font-size: 0.8rem;
}

.char-row .char-glyph {
    color: var(--text);
    text-align: center;
    align-self: center;
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.2;
    min-width: 1.5rem;
}

.char-row .char-glyph.is-space {
    color: var(--muted);
    font-weight: 500;
}

/* Per-char number + ▲▼ (single control outline) */
.char-field {
    display: flex;
    align-items: stretch;
    min-width: 0;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #0f1218;
    overflow: hidden;
}

.char-field:focus-within {
    outline: 2px solid var(--accent);
    outline-offset: 0;
}

.char-field input[type='number'] {
    width: auto;
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: 0.3rem 0.35rem;
    font-size: 0.8rem;
    border: none;
    border-radius: 0;
    background: transparent;
}

.char-field input[type='number'].char-dragging {
    cursor: ns-resize;
    touch-action: none;
    user-select: none;
}

.char-spin {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: 1.35rem;
    border-left: 1px solid var(--border);
}

.char-spin-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    min-height: 1rem;
    border: none;
    border-radius: 0;
    background: #1a2230;
    color: var(--muted);
    font-size: 0.45rem;
    line-height: 1;
    cursor: pointer;
}

.char-spin-btn:hover {
    background: #2a3142;
    color: var(--text);
}

.char-spin-btn:active {
    background: #354058;
}

.char-spin-btn + .char-spin-btn {
    border-top: 1px solid var(--border);
}
