:root {
    --bg: #111311;
    --surface: #191d1a;
    --surface-soft: #202620;
    --surface-line: #2f382f;
    --text: #eef2ea;
    --muted: #9ea89a;
    --accent: #f0c567;
    --accent-strong: #ffb347;
    --mint: #4ec9a2;
    --coral: #ff7a70;
    --ink: #0b0d0b;
    --match-a: rgba(240, 197, 103, 0.34);
    --match-b: rgba(78, 201, 162, 0.28);
    --danger: #ff8278;
    --ok: #65d19e;
    --radius: 8px;
    --shadow: 0 18px 60px rgba(0, 0, 0, 0.26);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        linear-gradient(90deg, rgba(240, 197, 103, 0.055) 1px, transparent 1px),
        linear-gradient(0deg, rgba(78, 201, 162, 0.045) 1px, transparent 1px),
        var(--bg);
    background-size: 32px 32px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

button,
input,
textarea,
select {
    font: inherit;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--surface-line);
    background: rgba(17, 19, 17, 0.93);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 190px;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border: 1px solid rgba(240, 197, 103, 0.5);
    border-radius: var(--radius);
    display: grid;
    place-items: center;
    color: var(--accent);
    background: #171a16;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-weight: 800;
}

.brand-title {
    display: grid;
    gap: 0;
}

.brand-title strong {
    font-size: 15px;
    line-height: 1.15;
}

.brand-title span {
    color: var(--muted);
    font-size: 12px;
}

.topnav {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.topnav a,
.ghost-btn,
.tool-btn {
    border: 1px solid transparent;
    color: var(--muted);
    background: transparent;
    min-height: 34px;
    border-radius: 6px;
    padding: 7px 10px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    cursor: pointer;
    white-space: nowrap;
}

.topnav a.active,
.ghost-btn:hover,
.tool-btn:hover,
.tool-btn.active {
    color: var(--text);
    border-color: var(--surface-line);
    background: var(--surface-soft);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 220px;
    justify-content: flex-end;
}

.primary-btn {
    color: var(--ink);
    background: var(--accent);
    border: 1px solid var(--accent);
    min-height: 34px;
    border-radius: 6px;
    padding: 7px 12px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.primary-btn:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

.workspace {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr) 360px;
    gap: 14px;
    padding: 14px;
    min-height: 0;
}

.side-rail,
.right-rail,
.workbench {
    min-width: 0;
}

.side-rail {
    display: grid;
    gap: 14px;
    align-content: start;
}

.panel {
    background: rgba(25, 29, 26, 0.94);
    border: 1px solid var(--surface-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-header {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--surface-line);
    background: rgba(32, 38, 32, 0.82);
}

.panel-header h2,
.panel-header h3 {
    margin: 0;
    font-size: 13px;
    text-transform: uppercase;
    color: #c9d1c3;
    font-weight: 800;
    letter-spacing: 0;
}

.panel-body {
    padding: 12px;
}

.rail-list {
    display: grid;
    gap: 7px;
}

.rail-item {
    width: 100%;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 9px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    text-align: left;
    cursor: pointer;
}

.rail-item:hover,
.rail-item.active {
    color: var(--text);
    border-color: var(--surface-line);
    background: var(--surface-soft);
}

.rail-item code {
    color: var(--accent);
    font-size: 12px;
}

.status-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.metric {
    min-height: 74px;
    padding: 10px;
    border: 1px solid var(--surface-line);
    border-radius: var(--radius);
    background: #151814;
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 4px;
}

.metric strong {
    display: block;
    font-size: 22px;
    line-height: 1.1;
    color: var(--text);
}

.workbench {
    display: grid;
    grid-template-rows: auto minmax(220px, 0.88fr) minmax(220px, 1fr);
    gap: 14px;
    min-height: calc(100vh - 86px);
}

.editor-bar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(82px, auto);
    align-items: stretch;
    gap: 8px;
}

.regex-string-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin-top: 10px;
}

.regex-string-output {
    min-height: 38px;
    display: flex;
    align-items: center;
    overflow: auto hidden;
    color: var(--accent);
    background: #101310;
    border: 1px solid var(--surface-line);
    border-radius: 6px;
    padding: 9px 10px;
    white-space: nowrap;
}

.slash {
    width: 38px;
    display: grid;
    place-items: center;
    color: var(--accent);
    border: 1px solid var(--surface-line);
    background: #111411;
    border-radius: 6px;
    font-size: 21px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.field {
    width: 100%;
    color: var(--text);
    background: #101310;
    border: 1px solid var(--surface-line);
    border-radius: 6px;
    min-height: 42px;
    padding: 10px 11px;
    outline: none;
}

.field:focus,
textarea:focus,
select:focus {
    border-color: rgba(240, 197, 103, 0.8);
    box-shadow: 0 0 0 3px rgba(240, 197, 103, 0.12);
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.flag-grid {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.flag-toggle {
    min-width: 34px;
    min-height: 34px;
    border-radius: 6px;
    border: 1px solid var(--surface-line);
    color: var(--muted);
    background: #121512;
    cursor: pointer;
    font-weight: 800;
    line-height: 1;
}

.flag-toggle.active {
    color: var(--ink);
    border-color: var(--accent);
    background: var(--accent);
}

.mode-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mode-button {
    min-height: 36px;
    border-radius: 6px;
    border: 1px solid var(--surface-line);
    background: #121512;
    color: var(--muted);
    padding: 8px 11px;
    cursor: pointer;
}

.mode-button.active {
    color: var(--ink);
    border-color: var(--accent);
    background: var(--accent);
    font-weight: 800;
}

.code-generator-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
}

.code-language-select {
    min-height: 34px;
    max-width: 210px;
    color: var(--text);
    background: #121512;
    border: 1px solid var(--surface-line);
    border-radius: 6px;
    padding: 6px 30px 6px 10px;
    outline: none;
}

.subgrid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.textarea-wrap {
    height: 100%;
    min-height: 190px;
}

textarea {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 190px;
    resize: none;
    color: var(--text);
    background: #101310;
    border: 1px solid var(--surface-line);
    border-radius: 6px;
    padding: 12px;
    outline: none;
    line-height: 1.55;
}

.output-pre {
    margin: 0;
    width: 100%;
    min-height: 190px;
    max-height: 42vh;
    overflow: auto;
    color: #dfe6d9;
    background: #101310;
    border: 1px solid var(--surface-line);
    border-radius: 6px;
    padding: 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.55;
}

mark.match {
    color: var(--text);
    background: var(--match-a);
    border-bottom: 2px solid var(--accent);
    border-radius: 3px;
    padding: 1px 0;
}

mark.match:nth-of-type(even) {
    background: var(--match-b);
    border-bottom-color: var(--mint);
}

.zero-width {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    transform: translateY(0.2em);
    background: var(--coral);
    border-radius: 2px;
}

.right-rail {
    display: grid;
    gap: 14px;
    align-content: start;
}

.explain-list,
.match-list,
.reference-list {
    display: grid;
    gap: 8px;
    max-height: 265px;
    overflow: auto;
    padding-right: 3px;
}

.token-row,
.match-row,
.reference-row {
    display: grid;
    grid-template-columns: minmax(70px, auto) 1fr;
    gap: 10px;
    padding: 9px;
    border: 1px solid var(--surface-line);
    background: #141814;
    border-radius: 6px;
    min-height: 42px;
    align-items: start;
}

.reference-row {
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.token-row code,
.match-row code,
.reference-row code {
    color: var(--accent);
    overflow-wrap: anywhere;
}

.token-row span,
.match-row span,
.reference-row span {
    color: #cfd8ca;
    font-size: 13px;
    line-height: 1.35;
}

.muted {
    color: var(--muted);
}

.error-box {
    border: 1px solid rgba(255, 122, 112, 0.54);
    background: rgba(255, 122, 112, 0.12);
    color: #ffd1cd;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
}

.ok-pill,
.warn-pill {
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.ok-pill {
    color: #092015;
    background: var(--ok);
}

.warn-pill {
    color: #260f0d;
    background: var(--danger);
}

.mode-panel {
    display: none;
}

.mode-panel.active {
    display: grid;
    gap: 10px;
}

.code-block {
    margin: 0;
    padding: 12px;
    border: 1px solid var(--surface-line);
    border-radius: 6px;
    background: #101310;
    color: #dfe6d9;
    overflow: auto;
    white-space: pre;
}

.mini-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.test-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 8px;
}

.test-table td,
.test-table th {
    color: #cfd8ca;
    padding: 0 6px;
    vertical-align: middle;
    font-size: 13px;
}

.test-table input[type="text"] {
    width: 100%;
    min-height: 36px;
    color: var(--text);
    background: #101310;
    border: 1px solid var(--surface-line);
    border-radius: 6px;
    padding: 7px 9px;
}

.test-table input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.tiny-btn {
    min-width: 32px;
    min-height: 32px;
    border-radius: 6px;
    border: 1px solid var(--surface-line);
    background: #121512;
    color: var(--muted);
    cursor: pointer;
}

.tiny-btn:hover {
    color: var(--text);
    background: var(--surface-soft);
}

.search-field {
    width: 100%;
    min-height: 36px;
    color: var(--text);
    background: #101310;
    border: 1px solid var(--surface-line);
    border-radius: 6px;
    padding: 8px 10px;
    outline: none;
    margin-bottom: 10px;
}

.copy-state {
    min-height: 18px;
    color: var(--muted);
    font-size: 12px;
    text-align: right;
}

@media (max-width: 1180px) {
    .workspace {
        grid-template-columns: 170px minmax(0, 1fr);
    }

    .right-rail {
        grid-column: 1 / -1;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 860px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .top-actions,
    .brand,
    .topnav {
        width: 100%;
        justify-content: flex-start;
    }

    .workspace {
        grid-template-columns: 1fr;
    }

    .side-rail {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .right-rail {
        grid-template-columns: 1fr;
    }

    .workbench {
        min-height: auto;
        grid-template-rows: auto auto auto;
    }

    .subgrid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .workspace {
        padding: 10px;
    }

    .side-rail {
        grid-template-columns: 1fr;
    }

    .editor-bar {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .editor-bar .flag-grid {
        grid-column: 1 / -1;
    }

    .panel-body {
        padding: 10px;
    }

    .token-row,
    .match-row,
    .reference-row {
        grid-template-columns: 1fr;
    }

    .code-generator-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}
