:root {
    --bg: #0f172a;
    --panel: #111827;
    --panel2: #1e293b;
    --border: #334155;
    --text: #e2e8f0;
    --sub: #94a3b8;
    --accent: #38bdf8;
    --success: #22c55e;
    --warn: #f59e0b;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at top, #1e293b, #0f172a 50%);
    color: var(--text);
    font-family: sans-serif;
}

header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 23, 42, .9);
    position: sticky;
    top: 0;
    z-index: 10;
}

header h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.25;
}

header p {
    color: var(--sub);
    margin: 4px 0 0;
    font-size: 13px;
    line-height: 1.35;
}

.page-layout {
    max-width: 1800px;
    padding: 20px;
}

.three-pane {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.sidebar,
.main-content,
.ad-sidebar {
    min-width: 0;
}

.ad-sidebar {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(260px, .9fr) minmax(220px, .7fr);
    gap: 20px;
    align-items: start;
    margin-top: 20px;
}

.ad-sidebar .panel {
    margin-top: 0 !important;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.control-panel {
    padding: 10px;
}

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

.button-group button {
    width: 100%;
    margin: 0;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.2;
}

.sidebar .panel,
.ad-sidebar .panel {
    font-size: 12px;
}

.sidebar .panel h2,
.ad-sidebar .panel h2 {
    font-size: 16px;
    line-height: 1.2;
    margin-bottom: 10px;
}

.sidebar .stat-label {
    font-size: 12px;
}

.status-panel .stat {
    padding: 9px 10px;
    margin-bottom: 8px;
    border: 1px solid rgba(51, 65, 85, .8);
    border-radius: 10px;
    background: rgba(15, 23, 42, .62);
}

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

.status-panel h2,
.status-panel .diagnostic-tasks {
    grid-column: 1 / -1;
}

.status-panel .stat {
    margin-bottom: 0;
}

.status-panel .stat:last-of-type {
    margin-bottom: 0;
}

.status-panel .stat-value {
    font-size: 18px;
    line-height: 1.2;
}

.status-panel .progress-wrap {
    display: none;
}

.diagnostic-tasks {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(51, 65, 85, .75);
}

.task-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.task-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 4px 7px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(15, 23, 42, .72);
    color: var(--sub);
    font-size: 11px;
    line-height: 1;
}

.task-pill.complete {
    color: #bbf7d0;
    border-color: var(--success);
    background: rgba(20, 83, 45, .78);
}

.scan-state {
    margin-top: 10px;
    padding: 8px;
    border-radius: 10px;
    border: 1px solid var(--warn);
    background: rgba(120, 53, 15, .42);
    color: #fde68a;
    font-size: 12px;
    font-weight: bold;
    text-align: center;
    letter-spacing: .04em;
}

.scan-state.complete {
    color: #bbf7d0;
    border-color: var(--success);
    background: rgba(20, 83, 45, .75);
}

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

.analysis-panel h2 {
    margin-bottom: 0;
}

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

.analysis-card {
    padding: 8px;
    border: 1px solid rgba(51, 65, 85, .8);
    border-radius: 10px;
    background: rgba(15, 23, 42, .62);
}

.analysis-value {
    margin-top: 4px;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
}

.analysis-value.ok {
    color: #bbf7d0;
}

.combo-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.combo-pill {
    padding: 5px 7px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(15, 23, 42, .72);
    color: var(--sub);
    font-size: 11px;
    line-height: 1;
}

.combo-pill.active {
    color: #bae6fd;
    border-color: var(--accent);
    background: rgba(14, 116, 144, .45);
    box-shadow: 0 0 0 2px rgba(56, 189, 248, .12);
}

.panel {
    background: rgba(17, 24, 39, .88);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
}

.main-content .panel + .panel {
    margin-top: 20px;
}

.panel h2 {
    margin-top: 0;
}

.stat {
    margin-bottom: 14px;
}

.stat:last-child {
    margin-bottom: 0;
}

.stat-label {
    color: var(--sub);
    font-size: 13px;
}

.stat-value {
    font-size: 22px;
    font-weight: bold;
    word-break: break-all;
}

.progress-wrap {
    height: 14px;
    border-radius: 999px;
    background: #020617;
    overflow: hidden;
    border: 1px solid var(--border);
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #38bdf8, #22c55e);
}

.key-info-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.main-content > .panel:first-child,
.key-info-panel {
    padding: 10px 12px;
}

.main-content > .panel:first-child h2,
.key-info-panel h2 {
    margin-bottom: 8px;
    font-size: 18px;
    line-height: 1.2;
}

.key-info-grid .stat {
    margin-bottom: 0;
    background: rgba(15, 23, 42, .65);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
}

.key-info-grid .stat-label {
    font-size: 12px;
    line-height: 1.2;
}

.key-info-grid .stat-value {
    font-size: 18px;
    line-height: 1.2;
}

.layout-switch {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.main-content .layout-switch {
    display: none;
}

.layout-btn.active {
    background: var(--accent);
    color: #001018;
}

.copy-panel {
    margin-top: 14px;
    background: rgba(15, 23, 42, .48);
    color: #cbd5e1;
    font-size: 13px;
    line-height: 1.65;
}

.copy-panel p {
    margin: 0 0 6px;
}

.copy-panel p:last-child {
    margin-bottom: 0;
}

.copy-note {
    color: var(--sub);
    font-size: 12px;
}

/* keyboard */

.keyboard-root {
    overflow: hidden;
    padding-bottom: 10px;
}

.keyboard-scale {
    width: max-content;
    transform-origin: top left;
    margin-inline: auto;
}

.keyboard-top {
    margin-bottom: 14px;
}

.keyboard-bottom {
    display: grid;
    grid-template-columns: max-content max-content;
    justify-content: start;
    align-items: start;
    gap: 9px;
}

.keyboard-main {
    min-width: 0;
}

.keyboard-side {
    display: grid;
    grid-template-columns: 158px 212px;
    gap: 9px;
    align-items: start;
    justify-content: start;
    justify-self: end;
    width: 379px;
    max-width: 379px;
    margin-top: 4px;
}

.keyboard-side-left {
    width: 158px;
    height: 266px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0;
}

#functionKeys,
#editKeys,
#arrowKeys {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.key-row {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
}

/* function keys */

#functionKeys .key-row {
    display: grid;
    grid-template-columns: repeat(30, 27px);
    column-gap: 0;
    row-gap: 4px;
    width: max-content;
}

#functionKeys .key {
    margin: 0 2px;
    width: auto;
    min-width: 0;
}

/* main keys */

#mainKeys {
    display: grid;
    grid-template-columns: repeat(30, 27px);
    grid-template-rows: repeat(5, 50px);
    column-gap: 0;
    row-gap: 4px;
    width: max-content;
}

#mainKeys .key {
    margin: 0 2px;
    width: auto;
    min-width: 0;
}

#mainKeys .key.wide,
#mainKeys .key.xwide,
#mainKeys .key.space {
    width: auto;
    min-width: 0;
}

#mainKeys .key[data-code="Enter"] {
    height: auto;
}

/* edit keys */

#editKeys {
    width: 158px;
}

#editKeys .key-row {
    display: grid;
    grid-template-columns: repeat(3, 50px);
    gap: 4px;
}

/* arrow keys */

#arrowKeys {
    width: 158px;
    display: grid;
    grid-template-rows: auto auto;
    gap: 4px;
}

#arrowKeys .key-row {
    display: grid;
    gap: 4px;
}

#arrowKeys .key-row:first-child {
    grid-template-columns: 50px;
    justify-content: center;
}

#arrowKeys .key-row:last-child {
    grid-template-columns: repeat(3, 50px);
}

/* numpad */

#numpadKeys {
    width: 212px;
    display: grid;
    grid-template-columns: repeat(4, 50px);
    grid-template-rows: repeat(5, 50px);
    gap: 4px;
}

#numpadKeys .key {
    width: 50px;
    min-width: 50px;
    height: 50px;
}

#numpadKeys .key.zero {
    width: auto;
    min-width: 0;
    grid-column: 1 / span 2;
    grid-row: 5;
}

#numpadKeys .key.tall {
    height: auto;
    min-height: 0;
}

#numpadKeys .key[data-code="NumpadAdd"] {
    grid-column: 4;
    grid-row: 2 / span 2;
}

#numpadKeys .key[data-code="NumpadEnter"] {
    grid-column: 4;
    grid-row: 4 / span 2;
}

#numpadKeys .key[data-code="NumpadDecimal"] {
    grid-column: 3;
    grid-row: 5;
}

/* keys */

.key {
    position: relative;
    flex-shrink: 0;
    min-width: 50px;
    height: 50px;
    padding: 3px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--panel2);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 12px;
    user-select: none;
    overflow: hidden;
    transition: background-color .16s ease, border-color .16s ease, box-shadow .16s ease, transform .08s ease;
}

.key::after {
    content: "";
    position: absolute;
    inset: 50%;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .42);
    opacity: 0;
    transform: translate(-50%, -50%) scale(.2);
    pointer-events: none;
}

.key.wide {
    min-width: 88px;
}

.key.xwide {
    min-width: 140px;
}

.key.space {
    min-width: 240px;
}

.key.active {
    background: var(--accent);
    color: #001018;
    transform: scale(.95);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, .18);
}

.key.checked {
    background:
        linear-gradient(rgba(245, 158, 11, calc(var(--heat, 0) * .42)), rgba(245, 158, 11, calc(var(--heat, 0) * .30))),
        linear-gradient(rgba(56, 189, 248, .30), rgba(14, 165, 233, .22)),
        var(--panel2);
    border-color: rgba(56, 189, 248, calc(.58 + var(--heat, 0) * .24));
    box-shadow:
        inset 0 -3px 0 rgba(245, 158, 11, calc(var(--heat, 0) * .22)),
        0 0 calc(var(--heat, 0) * 12px) rgba(245, 158, 11, calc(var(--heat, 0) * .34));
}

.key.warning {
    background:
        linear-gradient(rgba(239, 68, 68, .52), rgba(239, 68, 68, .52)),
        var(--panel2);
    border-color: var(--danger);
    box-shadow:
        inset 0 -3px 0 rgba(239, 68, 68, .24),
        0 0 14px rgba(239, 68, 68, .34);
    animation: chatterPulse .75s ease-in-out infinite;
}

.key.hit {
    animation: keyPop .18s ease-out;
}

.key.hit::after {
    animation: keyRipple .34s ease-out;
}

.key-count {
    position: absolute;
    right: 5px;
    bottom: 4px;
    font-size: 10px;
    color: #94a3b8;
}

.key.checked .key-count {
    color: #fde68a;
}

.key.warning .key-count {
    color: #fecaca;
}

@keyframes keyPop {
    0% {
        transform: scale(1);
    }

    55% {
        transform: scale(.92);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes keyRipple {
    0% {
        opacity: .5;
        transform: translate(-50%, -50%) scale(.2);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(8);
    }
}

@keyframes chatterPulse {
    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, .30);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(239, 68, 68, .20);
    }
}

/* log / result / ad */

.log {
    height: 240px;
    overflow-y: auto;
    background: #020617;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    font-size: 11px;
    line-height: 1.35;
}

.log-item {
    padding: 4px 0;
    border-bottom: 1px solid #111827;
}

.result-card {
    display: none;
    margin-top: 20px;
    padding: 20px;
    border-radius: 18px;
    border: 1px solid var(--success);
    background: linear-gradient(135deg, rgba(34, 197, 94, .18), rgba(56, 189, 248, .14));
}

.result-card.show {
    display: block;
}

.result-title {
    font-size: 32px;
    font-weight: bold;
}

.ad-panel {
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sub);
}

footer {
    padding: 24px;
    border-top: 1px solid var(--border);
    background: rgba(15, 23, 42, .72);
    color: var(--sub);
}

.footer-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    max-width: 1120px;
    margin: 0 auto;
    text-align: left;
}

.footer-grid h2 {
    margin: 0 0 10px;
    color: var(--text);
    font-size: 16px;
}

.footer-grid ul {
    margin: 0;
    padding-left: 1.1em;
}

.footer-grid li {
    margin-bottom: 6px;
}

.footer-grid a {
    color: #bae6fd;
    text-decoration: none;
}

.footer-grid a:hover {
    text-decoration: underline;
}

.footer-grid p {
    margin: 0 0 8px;
    line-height: 1.6;
}

.footer-note {
    max-width: 1120px;
    margin: 18px auto 0;
    padding-top: 14px;
    border-top: 1px solid rgba(51, 65, 85, .72);
    text-align: center;
    font-size: 12px;
}

.seo-copy-section {
    max-width: 1120px;
    margin: 0 auto;
    padding: 24px 20px 8px;
    color: #cbd5e1;
    line-height: 1.75;
}

.seo-copy-section h2,
.seo-copy-section h3 {
    color: var(--text);
}

.seo-copy-section h2 {
    font-size: 24px;
    margin: 0 0 12px;
}

.seo-copy-section h3 {
    font-size: 18px;
    margin: 20px 0 8px;
}

.seo-copy-section p {
    margin: 0 0 10px;
}

.seo-copy-section ul {
    margin: 0 0 14px 1.2em;
    padding: 0;
}

.seo-copy-note {
    color: var(--sub);
    font-size: 13px;
}

@media(max-width: 1200px) {
    .three-pane {
        grid-template-columns: 240px minmax(0, 1fr);
    }
}

@media(max-width: 980px) {
    .three-pane {
        grid-template-columns: 1fr;
    }

    .ad-sidebar {
        grid-template-columns: 1fr;
    }

    .sidebar,
    .main-content,
    .ad-sidebar {
        margin-bottom: 20px;
    }

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

@media(max-width: 700px) {
    .key-info-grid {
        grid-template-columns: 1fr;
    }

    .button-group,
    .status-panel {
        grid-template-columns: 1fr;
    }

    header h1 {
        font-size: 24px;
    }

    .page-layout {
        padding: 12px;
    }
}
