@font-face {
    font-family: 'Comfortaa';
    src: url('Comfortaa-VariableFont_wght.ttf') format('truetype');
    font-weight: 300 700;
    font-display: swap;
}

:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f6f8fb;
    --line: #e2e7ee;
    --text: #1f2a37;
    --muted: #6b7686;
    --primary: #3b5bdb;
    --primary-hover: #2f4ac0;
    --primary-soft: #e8edff;
    --ok: #2f9e44;
    --ok-hover: #278a3b;
    --danger: #e03131;
    --danger-hover: #c92a2a;
    --accent: #1098ad;
    --accent-hover: #0c8599;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
    --radius: 12px;
    --side-w: 340px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #15181e;
        --surface: #1d2129;
        --surface-2: #232833;
        --line: #303746;
        --text: #e6e9ef;
        --muted: #9aa3b2;
        --primary: #6d8bff;
        --primary-hover: #8aa1ff;
        --primary-soft: #26304d;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Comfortaa', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Yu Gothic UI', Meiryo, sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.icon { width: 1.1em; height: 1.1em; flex: none; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- レイアウト ---------- */

#sidebar {
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 28px 24px;
}

#main-content-wrapper { padding: 32px 20px 64px; }

#main-content {
    max-width: 860px;
    margin: 0 auto;
    text-align: center;
}

@media (min-width: 1000px) {
    #sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: var(--side-w);
        overflow-y: auto;
    }
    #main-content-wrapper { margin-left: var(--side-w); padding: 40px 40px 80px; }
}

/* 狭い画面では編集欄を本体の下へ */
@media (max-width: 999px) {
    body { display: flex; flex-direction: column; }
    #main-content-wrapper { order: 1; }
    #sidebar { order: 2; border-right: none; border-top: 1px solid var(--line); }
}

/* ---------- 編集欄 ---------- */

#sidebar h2 { font-size: 1.15rem; margin: 0 0 18px; }

.panel {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 16px;
}

.panel h3 {
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .04em;
    color: var(--muted);
    margin: 0 0 10px;
}

.row { display: flex; gap: 8px; margin-bottom: 8px; }
.row:last-child { margin-bottom: 0; }
.row > select, .row > input { flex: 1; min-width: 0; }

select, input[type="text"] {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 10px;
    height: 42px;
}

select:focus, input[type="text"]:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }

.links { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 10px; font-size: .85rem; }

.linklike {
    font: inherit;
    background: none;
    border: none;
    padding: 0;
    color: var(--muted);
    cursor: pointer;
}
.linklike:hover { color: var(--danger); text-decoration: underline; }

.side-foot {
    display: flex;
    justify-content: space-between;
    font-size: .8rem;
    color: var(--muted);
    padding-top: 6px;
}

/* ---------- ボタン ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font: inherit;
    font-weight: 700;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 9px 14px;
    height: 42px;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .15s, border-color .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ok:hover { background: var(--ok-hover); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-wide { width: 100%; }
.btn-small { height: 30px; padding: 4px 10px; font-size: .8rem; font-weight: 600; background: var(--surface); color: var(--muted); border-color: var(--line); }
.btn-small:hover { color: var(--primary); border-color: var(--primary); }

.btn-big {
    font-size: 1.15rem;
    height: 56px;
    padding: 0 36px;
    border-radius: 999px;
    margin: 18px 0 8px;
    box-shadow: 0 6px 18px rgba(59, 91, 219, .28);
}

/* ---------- 本体 ---------- */

h1 { font-size: 1.8rem; margin: 0 0 6px; letter-spacing: .02em; }

#file-name { font-size: .85rem; color: var(--muted); min-height: 1.4em; margin-bottom: 14px; }

.toolbar { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

#result {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin: 18px 0 8px;
    text-align: left;
}
#result.pop .result-card { animation: pop .28s ease-out both; }
#result.pop .result-card:nth-child(2) { animation-delay: .03s; }
#result.pop .result-card:nth-child(3) { animation-delay: .06s; }
#result.pop .result-card:nth-child(4) { animation-delay: .09s; }
#result.pop .result-card:nth-child(n+5) { animation-delay: .12s; }

@keyframes pop {
    from { transform: translateY(6px) scale(.97); }
    to { transform: none; }
}

.result-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px 40px 14px 16px;
}
.result-cat { font-size: .75rem; font-weight: 700; color: var(--muted); }
.result-val { font-size: 1.35rem; font-weight: 700; word-break: break-word; }

.icon-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary); }

.btn-copy { grid-column: 1 / -1; justify-self: center; height: 36px; font-size: .85rem; }

#history-box {
    max-width: 640px;
    margin: 6px auto 0;
    text-align: left;
    font-size: .85rem;
    color: var(--muted);
}
#history-box summary { cursor: pointer; text-align: center; }
#history { margin: 8px 0 0; padding-left: 1.6em; }
#history li { padding: 2px 0; }

#category-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin: 28px 0 14px;
    padding-top: 22px;
    border-top: 1px solid var(--line);
}
#category-list a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--text);
    font-size: .85rem;
}
#category-list a:hover { border-color: var(--primary); text-decoration: none; }
#category-list .count { font-size: .75rem; color: var(--muted); }

.checkbox-group {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px 18px;
    margin-bottom: 16px;
    scroll-margin-top: 16px;
    text-align: left;
}

.group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.group-head h2 { font-size: 1.1rem; margin: 0; }
.button-container { display: flex; gap: 6px; }

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

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px 6px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    cursor: pointer;
    user-select: none;
    font-size: .92rem;
    transition: background-color .12s, border-color .12s;
}
.chip:hover { border-color: var(--primary); }
.chip input { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; }
.chip:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); }

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

#toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 20px);
    background: #1f2a37;
    color: #fff;
    padding: 10px 18px;
    border-radius: 999px;
    font-size: .9rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
