.regex-page {
    width: min(1680px, calc(100% - 32px));
}

.regex-hero,
.regex-panel,
.regex-card {
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.regex-hero {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.95fr);
    gap: 18px;
    padding: 22px;
    background:
        linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(49, 94, 251, 0.05)),
        rgba(255, 255, 255, 0.96);
}

.regex-hero__copy h2 {
    margin: 10px 0 10px;
    font-size: clamp(1.9rem, 4vw, 3.4rem);
    line-height: 1.02;
    letter-spacing: -0.04em;
}

.regex-hero__copy p {
    margin: 0;
    max-width: 68ch;
    color: var(--muted);
    line-height: 1.72;
}

.regex-hero__panel {
    display: grid;
    gap: 12px;
    padding: 18px;
    border-radius: 18px;
    border: 1px solid rgba(15, 118, 110, 0.12);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(236, 253, 245, 0.78));
}

.regex-hero__panel h3 {
    margin: 0;
    font-size: 1.02rem;
}

.regex-tip-list {
    margin: 0;
    padding-left: 18px;
    display: grid;
    gap: 9px;
    color: var(--muted);
    line-height: 1.6;
}

.regex-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.regex-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.82);
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 800;
}

.regex-toolbar {
    display: grid;
    gap: 14px;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.regex-toolbar__row {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

.regex-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.regex-button {
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 18px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-soft);
    color: var(--ink);
    font-weight: 800;
    cursor: pointer;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

.regex-button:hover {
    border-color: var(--line-strong);
    box-shadow: 0 10px 26px rgba(23, 32, 42, 0.12);
    transform: translateY(-1px);
}

.regex-button--primary {
    color: #fff;
    background: linear-gradient(135deg, var(--teal), var(--blue));
    border-color: transparent;
}

.regex-button--ghost {
    color: var(--teal-dark);
    background: #ecfdf5;
    border-color: #bce7d4;
}

.regex-flag-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.regex-flag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
    cursor: pointer;
    user-select: none;
}

.regex-flag input {
    accent-color: var(--teal);
}

.regex-flag b {
    color: var(--ink);
}

.regex-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr);
    gap: 16px;
}

.regex-panel {
    display: grid;
    gap: 0;
    overflow: hidden;
}

.regex-panel__header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(248, 250, 252, 0.92);
}

.regex-panel__title {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 900;
}

.regex-panel__subtitle {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.regex-field {
    display: grid;
    gap: 10px;
    padding: 16px;
}

.regex-field label {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.regex-textarea,
.regex-input,
.regex-output {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    color: var(--ink);
    outline: none;
    font-family: var(--mono);
    font-size: 1rem;
    line-height: 1.7;
    padding: 18px 20px;
    box-shadow: 0 10px 24px rgba(23, 32, 42, 0.06);
}

.regex-textarea {
    min-height: 170px;
    resize: vertical;
    white-space: pre-wrap;
    word-break: break-word;
}

.regex-input {
    min-height: 52px;
}

.regex-output {
    min-height: 190px;
    resize: vertical;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.94));
    color: #e2e8f0;
    white-space: pre-wrap;
    word-break: break-word;
}

.regex-textarea::placeholder,
.regex-input::placeholder,
.regex-output::placeholder {
    color: #94a3b8;
}

.regex-card__footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px 16px;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
}

.regex-results {
    display: grid;
    gap: 16px;
    align-content: start;
}

.regex-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.regex-stat {
    padding: 14px 15px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(248, 250, 252, 0.95);
}

.regex-stat span {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.regex-stat strong {
    display: block;
    margin-top: 6px;
    font-size: 1.18rem;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.regex-preview {
    padding: 18px 20px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background:
        linear-gradient(180deg, rgba(249, 250, 251, 0.9), rgba(255, 255, 255, 0.9)),
        rgba(255, 255, 255, 0.94);
    font-family: var(--mono);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.8;
    min-height: 220px;
}

.regex-preview mark {
    padding: 0 3px;
    border-radius: 6px;
    background: rgba(49, 94, 251, 0.16);
    color: inherit;
    box-shadow: inset 0 -2px 0 rgba(49, 94, 251, 0.28);
}

.regex-zero-match {
    display: inline-grid;
    place-items: center;
    min-width: 1.2em;
    padding: 0 4px;
    margin: 0 1px;
    border-radius: 999px;
    background: rgba(217, 119, 6, 0.16);
    color: var(--amber);
    font-weight: 900;
}

.regex-match-list {
    display: grid;
    gap: 12px;
    max-height: 360px;
    overflow: auto;
    padding-right: 4px;
}

.regex-live-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 0 2px;
}

.regex-live-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid rgba(49, 94, 251, 0.18);
    background: rgba(49, 94, 251, 0.08);
    color: var(--ink);
    font-family: var(--mono);
    font-size: 0.88rem;
    font-weight: 800;
    white-space: nowrap;
}

.regex-live-chip span {
    color: var(--muted);
    font-family: var(--sans);
    font-size: 0.74rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.regex-match {
    padding: 14px 15px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.92);
}

.regex-match__head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: baseline;
    margin-bottom: 10px;
}

.regex-match__head strong {
    font-size: 0.98rem;
}

.regex-match__head span {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.regex-match__value {
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--surface-soft);
    font-family: var(--mono);
    white-space: pre-wrap;
    word-break: break-word;
}

.regex-capture-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.regex-capture {
    display: inline-flex;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(248, 250, 252, 0.96);
    font-size: 0.84rem;
    font-weight: 800;
}

.regex-capture b {
    color: var(--teal-dark);
}

.regex-empty-state {
    padding: 16px;
    border: 1px dashed var(--line-strong);
    border-radius: 16px;
    background: rgba(248, 250, 252, 0.84);
    color: var(--muted);
    line-height: 1.7;
}

.regex-note {
    padding: 12px 14px;
    border: 1px solid rgba(15, 118, 110, 0.16);
    border-radius: 16px;
    background: rgba(236, 253, 245, 0.82);
    color: var(--muted);
    line-height: 1.6;
}

.regex-status-bar {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.regex-status-copy {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-weight: 800;
}

.regex-status-light {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--teal);
    box-shadow: 0 0 0 5px rgba(15, 118, 110, 0.12);
}

.regex-progress {
    margin-top: 10px;
    height: 8px;
    border-radius: 999px;
    background: rgba(203, 213, 225, 0.5);
    overflow: hidden;
}

.regex-progress span {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--teal), var(--blue));
    transition: width 0.18s ease;
}

html.theme-dark .regex-hero,
html.theme-dark .regex-toolbar,
html.theme-dark .regex-panel,
html.theme-dark .regex-card,
html.theme-dark .regex-status-bar {
    background: rgba(17, 24, 39, 0.94);
}

html.theme-dark .regex-hero__panel {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.94), rgba(17, 24, 39, 0.92));
    border-color: rgba(148, 163, 184, 0.18);
}

html.theme-dark .regex-chip,
html.theme-dark .regex-flag,
html.theme-dark .regex-stat,
html.theme-dark .regex-match,
html.theme-dark .regex-empty-state {
    background: rgba(15, 23, 42, 0.78);
}

html.theme-dark .regex-preview {
    background: linear-gradient(180deg, rgba(2, 6, 23, 0.98), rgba(15, 23, 42, 0.96));
    color: #e2e8f0;
}

html.theme-dark .regex-capture {
    background: rgba(15, 23, 42, 0.94);
}

html.theme-dark .regex-live-chip {
    background: rgba(96, 165, 250, 0.12);
    border-color: rgba(96, 165, 250, 0.2);
}

@media (max-width: 1240px) {
    .regex-hero,
    .regex-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px) {
    .regex-page {
        width: min(100%, calc(100% - 24px));
    }

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

@media (max-width: 640px) {
    .regex-stats {
        grid-template-columns: 1fr;
    }

    .regex-toolbar__row {
        align-items: stretch;
    }

    .regex-actions {
        width: 100%;
    }

    .regex-actions .regex-button {
        flex: 1 1 140px;
    }
}
