:root {
    --bg: var(--color-bg-base);
    --fg: var(--color-fg-primary);
    --muted: var(--color-fg-muted);
    --card-bg: var(--color-bg-surface);
    --border: var(--color-border-base);
    --accent: var(--color-accent);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 760px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.navigation-links { margin-bottom: 1rem; }
.navigation-links a { color: var(--muted); text-decoration: none; font-size: .9rem; }
.navigation-links a:hover { color: var(--accent); }

h1 {
    font-size: clamp(1.5rem, 5vw, 2rem);
    margin: 0 0 .5rem;
    letter-spacing: -0.02em;
}

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

details.help { margin: 0 0 1.2rem; }
details.help summary { cursor: pointer; color: var(--accent); font-size: .9rem; }
details.help ol { margin: .6rem 0 0; padding-left: 1.3em; font-size: .9rem; color: var(--muted); }
details.help li { margin: .3rem 0; }

/* --- レイアウト（スマホ=縦積み / PC=2カラム） --- */
.layout { display: block; }
.side-label { display: block; padding-left: .2rem; margin: .2rem 0 .5rem; }

/* --- 盤面 --- */
.board-wrap {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: .5rem;
    margin-bottom: .6rem;
}

#board {
    display: block;
    width: 100%;
    height: auto;
    touch-action: none;      /* ドラッグ中のスクロール抑止 */
    -webkit-user-select: none;
    user-select: none;
}

.status {
    min-height: 1.3em;
    font-size: .85rem;
    color: var(--accent);
    margin-bottom: .6rem;
}

/* --- パネル共通 --- */
.panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: .8rem .9rem;
    margin-bottom: .9rem;
}
.panel-label {
    display: block;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: .5rem;
}

/* --- 選択中バー --- */
.selbar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.selbar .sel-name { font-weight: 600; flex: 1; min-width: 6em; }
.size-ctl {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .82rem;
    color: var(--muted);
    flex: 1 1 100%;
}
.size-ctl input[type="range"] { flex: 1; min-width: 8em; accent-color: var(--accent); }

button {
    font: inherit;
    cursor: pointer;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--fg);
    padding: .5rem .9rem;
    transition: background .15s ease, border-color .15s ease;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.danger { color: #d33; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.ghost { color: var(--muted); }

/* --- ギャラリー --- */
.gallery { margin-bottom: 1rem; }
details.cat {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: .5rem;
    background: var(--card-bg);
    overflow: hidden;
}
details.cat > summary {
    cursor: pointer;
    padding: .7rem .9rem;
    font-weight: 600;
    list-style: none;
    display: flex;
    align-items: center;
    gap: .5rem;
}
details.cat > summary::-webkit-details-marker { display: none; }
details.cat > summary::before {
    content: "▸";
    color: var(--accent);
    transition: transform .15s ease;
}
details.cat[open] > summary::before { transform: rotate(90deg); }
.cat-count {
    margin-left: auto;
    font-size: .75rem;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0 .55em;
}
.unit-h {
    margin: .6rem .9rem .2rem;
    font-size: .82rem;
    color: var(--muted);
    font-weight: 600;
}
.thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: .5rem;
    padding: .5rem .9rem .9rem;
}
.thumb {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .25rem;
    padding: .3rem .2rem;
    border: 1px solid transparent;
    background: transparent;
    text-align: center;
}
.thumb img {
    width: 100%;
    max-width: 64px;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 50%;
    background: var(--bg);
    border: 2px solid var(--border);
    pointer-events: none;
}
.thumb .thumb-name {
    font-size: .68rem;
    line-height: 1.2;
    color: var(--muted);
    word-break: break-word;
    pointer-events: none;
}
.thumb.selected { border-color: var(--accent); background: var(--bg); }
.thumb.selected img { border-color: var(--accent); }
.gallery .err { color: #d33; font-size: .9rem; }

/* --- アクション --- */
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: .9rem; }
.actions button { flex: 1; min-width: 8em; }

details.tweet summary { cursor: pointer; color: var(--accent); font-size: .9rem; margin-bottom: .5rem; }
#tweetText {
    width: 100%;
    font: inherit; font-size: .9rem;
    padding: .5rem .6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--fg);
    resize: vertical;
}

.tool-note { font-size: .85rem; color: var(--muted); margin-top: 1.5rem; }
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* --- PC（ワイド）: 盤面とパネルを横並び、盤面は追従（sticky） --- */
@media (min-width: 860px) {
    .container { max-width: 1140px; }
    .layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(340px, 400px);
        gap: 1.6rem;
        align-items: start;
    }
    .col-board {
        position: sticky;
        top: 1rem;
    }
    .side-label { margin-top: 0; }
    /* 右カラムのギャラリーは高くなり過ぎないようスクロール領域に */
    .gallery {
        max-height: 60vh;
        overflow-y: auto;
        padding-right: .2rem;
    }
    /* PC はサムネを気持ち大きく */
    .thumbs { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
}

/* --- ポインタ（マウス）環境だけ hover を効かせる --- */
@media (hover: hover) {
    .thumb { cursor: pointer; transition: background .12s ease, border-color .12s ease; }
    .thumb:hover { border-color: var(--border); background: var(--card-bg); }
    .thumb:hover img { border-color: var(--accent); }
    details.cat > summary { transition: background .12s ease; }
    details.cat > summary:hover { background: var(--card-bg); }
    #board .q-point { cursor: grab; }
}
