/* style.css — cactnut-design-system のトークン (tokens.css) を参照。
   HEX 直書きはせず semantic 名 (var(--fg) 等) を使う。 */

body {
    font-family: var(--font-sans);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    position: relative;
    background-color: var(--bg);
    color: var(--fg);
}

h1 {
    font-size: var(--text-xl);
    font-weight: 700;
    line-height: var(--leading-heading);
    letter-spacing: -0.01em;
    margin: 0 0 var(--space-6);
}

#dotCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;            /* 背景レイヤ (コンテンツは z-index: 1 以上) */
    pointer-events: none;
    /* パーティクル色のソース (JS が getComputedStyle で読む)。
       ここがライト(既定)の色。ダークは下の @media で --fg に上書きする。 */
    color: var(--brand-500);
}

@media (prefers-color-scheme: dark) {
    #dotCanvas { color: var(--fg); }
}

.container {
    text-align: center;
    width: 90%;
    max-width: 720px;
    position: relative;
    z-index: 1;
    padding: var(--space-6) 0;
}

.flex-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-6); /* トグルとグリッド/スライダーの間 */
    flex-wrap: wrap;
}

#inputText, #outputText {
    width: 90%;
    box-sizing: border-box;
    padding: var(--space-3);
    margin: 0 auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: var(--text-xs);
    line-height: 1.7;
    background-color: var(--bg-elevated);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: var(--radius-tight);   /* 入力は箱なので tight (4px)。squircle 不要 */
    transition: border-color var(--motion-quick), box-shadow var(--motion-quick);
}

#inputText {
    height: 100px;
    resize: vertical;
}

#inputText:focus,
#inputText:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

.spacer {
    height: var(--space-6);
}

#outputText {
    white-space: pre-wrap;
    word-wrap: break-word;
    text-align: left;
    min-height: 2.5em;
    cursor: pointer;
    transition: background-color var(--motion-quick), border-color var(--motion-quick);
}

@media (hover: hover) {
    #outputText:hover { background-color: var(--fill); }
}

/* ===== Toast ===== */
.toast {
    visibility: hidden;
    position: fixed;
    left: 50%;
    bottom: var(--space-4);
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 360px;
    padding: var(--space-3) var(--space-4);
    color: var(--fg);
    text-align: left;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--bg-elevated);
    box-shadow: var(--shadow-sm);
    font-size: var(--text-xs);
    z-index: 10;
}

@media (min-width: 768px) {
    .toast { left: auto; right: var(--space-4); transform: none; }
}

#toastContent { word-break: break-all; }

.toast.show {
    visibility: visible;
    /* out の終了 (2.5s + 0.5s = 3.0s) を JS の削除タイミング (3000ms) に合わせる */
    -webkit-animation: toast-in 250ms var(--ease-spring), toast-out 500ms var(--ease-spring) 2.5s;
    animation: toast-in 250ms var(--ease-spring), toast-out 500ms var(--ease-spring) 2.5s;
}

@keyframes toast-in {
    from { opacity: 0; bottom: 0; }
    to   { opacity: 1; bottom: var(--space-4); }
}

@keyframes toast-out {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* ===== Toggle (Table / Size) — 2 等分セグメント。
   インジケータが半セルを覆い、translateX(100%) で隣セルへ移る。
   ラベル幅 (= 言語) に依存しないよう寸法は % とグリッドで決める ===== */
.wideToggle-container {
    position: relative;
    display: inline-block;          /* ラベルにフィット (固定幅にしない) */
    background-color: var(--fill-strong);
    border-radius: 999px;
    padding: 4px;
    cursor: pointer;
}

.labels-container {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr; /* 2 セル等幅 (広い方にそろう) */
    pointer-events: none;           /* クリックはコンテナの onclick へ */
    z-index: 2;                     /* ラベルを前面に */
}

.label {
    padding: 6px 18px;
    text-align: center;
    white-space: nowrap;
    color: var(--muted);            /* 非選択ラベル */
    transition: color var(--motion-base);
}

.label.active {
    color: var(--on-accent);        /* accent 上に乗るラベル */
    font-weight: 500;
}

/* 既定は左セルを覆う ([4px, 中央])。active で自分の幅 (= 半セル) ぶん右へ */
.toggle-btn {
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 4px;
    right: 50%;
    background-color: var(--accent);
    border-radius: 999px;
    transition: transform var(--motion-base);
    z-index: 1;                     /* ラベルの背面 */
}

.toggle-btn.active {
    transform: translateX(100%);
}

/* ===== グリッド選択 UI ===== */
.grid-selector-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    min-width: 200px; /* スライダーと同じ幅を確保 */
    position: relative;
}

.grid-label {
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--fg);
    min-width: 90px;
    text-align: center;
    cursor: pointer;
    user-select: none;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-tight);
    background-color: var(--bg-elevated);
    transition: background-color var(--motion-quick);
}

@media (hover: hover) {
    .grid-label:hover { background-color: var(--fill); }
}

.grid-label:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.grid-selector {
    position: relative;
}

/* popover: 影で階層を作る (白グローは使わない) */
.grid-container {
    display: grid;
    grid-template-columns: repeat(6, 20px);
    grid-template-rows: repeat(6, 20px);
    gap: 2px;
    padding: var(--space-2);
    background-color: var(--bg-elevated);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: var(--space-1);
    z-index: 1000;
    box-shadow: var(--shadow-md);
}

.grid-cell {
    width: 20px;
    height: 20px;
    background-color: var(--fill);
    border: 1px solid var(--border);
    border-radius: var(--radius-tight);
    cursor: pointer;
    transition: background-color var(--motion-quick), border-color var(--motion-quick);
}

.grid-cell:hover,
.grid-cell.active {
    /* 背景だけを accent に。border は据え置きにして塗り面を非選択セルと同じ大きさに保つ */
    background-color: var(--accent);
}

/* ===== Size slider ===== */
.size-slider-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 200px;
}

input[type="range"] {
    accent-color: var(--accent);
}

#sliderValue {
    font-size: var(--text-xs);
    color: var(--muted);
    min-width: 56px;
    text-align: left;
}

/* 改行記号 */
.newline-symbol {
    color: var(--muted);
    font-size: 0.9em;
    user-select: none;
}
