:root {
    --bg: #f4f7fb;
    --panel: #fff;
    --panel-soft: #eef4fb;
    --text: #172033;
    --muted: #647084;
    --line: #d8e1ed;
    --primary: #1765e8;
    --primary-dark: #0e4fb8;
    --green: #0f9f67;
    --amber: #d98a10;
    --danger: #d43b3b;
    --shadow: 0 16px 40px rgba(15, 23, 42, .12);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 12% 4%, rgba(23, 101, 232, .16), transparent 30%),
        radial-gradient(circle at 88% 10%, rgba(15, 159, 103, .12), transparent 28%),
        linear-gradient(180deg, #f8fbff, var(--bg));
    font-family: Arial, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

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

a {
    color: inherit;
}

.app-nav {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px clamp(14px, 4vw, 42px);
    border-bottom: 1px solid rgba(15, 23, 42, .08);
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(16px);
}

.brand,
.tool-home,
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.brand {
    gap: 10px;
    color: var(--text);
    text-decoration: none;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: var(--radius);
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--green));
    box-shadow: 0 10px 22px rgba(23, 101, 232, .22);
}

.brand strong,
.brand small {
    display: block;
}

.brand strong {
    font-size: 17px;
    font-weight: 900;
}

.brand small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.tool-home {
    gap: 8px;
    min-height: 40px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--text);
    font-weight: 900;
    text-decoration: none;
}

.tool-home:hover,
.tool-home:focus {
    border-color: var(--primary);
    color: var(--primary);
}

.app-shell {
    width: min(1400px, calc(100% - 28px));
    margin: 0 auto;
    padding: 28px 0 58px;
}

.counter-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.32fr) minmax(340px, .68fr);
    gap: 18px;
    align-items: start;
}

.editor-panel,
.stats-panel,
.analysis-card {
    border: 1px solid rgba(15, 23, 42, .08);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, .94);
    box-shadow: var(--shadow);
}

.editor-panel,
.stats-panel {
    padding: 18px;
}

.stats-panel {
    position: sticky;
    top: 82px;
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 950;
    letter-spacing: .14em;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    color: var(--text);
    line-height: 1.2;
    font-weight: 950;
    letter-spacing: 0;
}

h1 {
    font-size: clamp(26px, 4vw, 42px);
}

h2 {
    font-size: 22px;
}

.editor-actions {
    display: inline-flex;
    gap: 8px;
}

.icon-btn {
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--primary);
    cursor: pointer;
    transition: transform .16s ease, border-color .16s ease, color .16s ease;
}

.icon-btn:hover,
.icon-btn:focus {
    border-color: var(--primary);
    transform: translateY(-1px);
}

.icon-btn.danger {
    color: var(--danger);
}

textarea {
    width: 100%;
    min-height: 520px;
    resize: vertical;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fbfdff;
    color: var(--text);
    font-size: 17px;
    line-height: 1.8;
    outline: 0;
}

textarea:focus {
    border-color: rgba(23, 101, 232, .58);
    box-shadow: 0 0 0 4px rgba(23, 101, 232, .1);
}

.settings-bar {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(130px, 170px) minmax(190px, auto);
    gap: 12px;
    align-items: end;
    margin-top: 14px;
}

.select-field,
.number-field {
    display: grid;
    gap: 6px;
}

.select-field span,
.number-field span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

select,
input[type="number"] {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    padding: 8px 10px;
}

.toggle-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    font-weight: 900;
}

.toggle-field input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.status-pill {
    flex: 0 0 auto;
    padding: 6px 10px;
    border-radius: 999px;
    background: #eef5ff;
    color: var(--primary-dark);
    font-size: 13px;
    font-weight: 950;
}

.primary-stat {
    margin-bottom: 14px;
    padding: 18px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, #102033, #123f75);
    color: #fff;
}

.primary-stat span,
.primary-stat small {
    display: block;
    color: rgba(255, 255, 255, .78);
    font-weight: 850;
}

.primary-stat strong {
    display: block;
    margin: 5px 0;
    font-size: clamp(44px, 7vw, 72px);
    line-height: 1;
    font-weight: 950;
}

.progress-card {
    margin-bottom: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.progress-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-weight: 950;
}

.progress-track {
    height: 10px;
    margin: 10px 0 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #e7eef7;
}

.progress-track span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary), var(--green));
    transition: width .18s ease;
}

.progress-card small {
    color: var(--muted);
    font-weight: 850;
}

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

.metric-grid article {
    display: grid;
    grid-template-columns: 34px 1fr;
    gap: 4px 8px;
    align-items: center;
    min-height: 76px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fbfdff;
}

.metric-grid i {
    grid-row: 1 / span 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    background: #eef5ff;
    color: var(--primary);
}

.metric-grid span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.metric-grid strong {
    color: var(--text);
    font-size: 22px;
    font-weight: 950;
}

.analysis-grid {
    display: grid;
    grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr);
    gap: 18px;
    margin-top: 18px;
}

.analysis-card {
    padding: 18px;
}

.analysis-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.analysis-head i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius);
    background: #fff7e6;
    color: var(--amber);
}

dl {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 0;
}

dl div {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fbfdff;
}

dt {
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

dd {
    margin: 6px 0 0;
    font-size: 26px;
    font-weight: 950;
}

.keyword-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.keyword-list span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid rgba(23, 101, 232, .2);
    border-radius: 999px;
    background: #eef5ff;
    color: var(--primary-dark);
    font-size: 14px;
    font-weight: 900;
}

.keyword-list small {
    color: var(--muted);
    font-weight: 950;
}

.keyword-list.empty {
    color: var(--muted);
    font-weight: 850;
}

.app-footer {
    padding: 0 14px 28px;
    color: var(--muted);
    text-align: center;
    font-size: 13px;
    font-weight: 850;
}

@media (max-width: 980px) {
    .counter-grid,
    .analysis-grid {
        grid-template-columns: 1fr;
    }

    .stats-panel {
        position: static;
    }

    textarea {
        min-height: 420px;
    }
}

@media (max-width: 680px) {
    .app-nav {
        align-items: stretch;
        flex-direction: column;
    }

    .tool-home {
        width: 100%;
    }

    .panel-head,
    .settings-bar {
        grid-template-columns: 1fr;
    }

    .settings-bar {
        display: grid;
    }

    .editor-actions {
        width: 100%;
    }

    .icon-btn {
        flex: 1 1 0;
    }

    .metric-grid,
    dl {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 26px;
    }
}
