/* ライト: ポップなパステル / ダーク: 同じ色相を落ち着かせた対比 */
:root, [data-theme="light"] {
  --bg: #fff6fa;
  --card: #ffffff;
  --ink: #3d3550;
  --sub: #8c82a3;
  --line: #f1dcea;
  --head: #f1ecff;
  --cond: #fff5cf;
  --cond-ink: #8a6a00;
  --section: #ffe4f0;
  --accent: #ff7eb3;
  --accent-ink: #ffffff;
  --mint: #6fd6c2;
  --best: #d6f6ec;
  --best-ink: #157a64;
  --badge: #e2efff;
  --badge-ink: #3a64a8;
  --ng: #ffdfe4;
  --ng-ink: #b23a52;
  --drop: #ffd1e5;
  --shadow: 0 2px 10px rgba(255, 126, 179, 0.15);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #1c1a28;
  --card: #262236;
  --ink: #ece7f7;
  --sub: #a197bd;
  --line: #3a3450;
  --head: #2e2845;
  --cond: #39321f;
  --cond-ink: #f1d57a;
  --section: #3a2638;
  --accent: #f58cba;
  --accent-ink: #2a1422;
  --mint: #6cc9b7;
  --best: #1f453d;
  --best-ink: #94ecd6;
  --badge: #25395a;
  --badge-ink: #a9c8f5;
  --ng: #5a2a35;
  --ng-ink: #f3b3c0;
  --drop: #54304a;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}
a { color: var(--accent); }
select, input, button { font: inherit; color: inherit; }
select {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 2px 6px;
}
select:disabled { opacity: 0.5; }

header {
  position: sticky; top: 0; z-index: 10; /* 装備の候補一覧を表の固定見出しより手前に */
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 3px solid var(--accent);
  box-shadow: var(--shadow);
}
h1 { font-size: 18px; margin: 0 4px 0 0; color: var(--accent); letter-spacing: 0.05em; }
.field { color: var(--sub); }
.spacer { flex: 1; }
#baseLv {
  width: 4em; background: var(--card); border: 1.5px solid var(--line); border-radius: 8px; padding: 2px 6px;
}
/* 純粋ステータスの入力（クリックで開くパネル） */
.pure { position: relative; }
.pure summary {
  cursor: pointer; list-style: none; user-select: none;
  border: 1.5px solid var(--line); border-radius: 8px; padding: 2px 8px; background: var(--card); color: var(--sub);
}
.pure summary::-webkit-details-marker { display: none; }
.pure summary::after { content: " ▾"; font-size: 10px; }
.pure[open] summary { border-color: var(--accent); }
.pure-summary { color: var(--ink); font-size: 12px; font-variant-numeric: tabular-nums; }
.pure-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 5; width: max-content;
  padding: 10px 12px; background: var(--card); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.pure-grid { display: grid; grid-template-columns: repeat(6, auto); gap: 6px 10px; }
.pure-grid label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--sub); }
.pure-grid input {
  width: 5em; box-sizing: border-box; background: var(--card); color: var(--ink); border: 1.5px solid var(--line); border-radius: 8px; padding: 2px 6px;
  font-variant-numeric: tabular-nums;
}
.pure-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; font-size: 12px; color: var(--sub); }
.pure-btns { display: inline-flex; gap: 10px; }
.pure-btns button {
  border: none; background: none; padding: 0; cursor: pointer;
  font-size: 12px; color: var(--sub); text-decoration: underline dotted;
}
.pure-btns button:hover { color: var(--accent); }

/* 一括設定のボタン群（つながったピル型） */
.preset { display: inline-flex; align-items: center; border-radius: 999px; background: var(--head); padding: 2px; gap: 2px; }
.preset-label { color: var(--sub); font-size: 12px; padding: 0 6px 0 10px; }
.preset button {
  border: none; cursor: pointer; border-radius: 999px; padding: 3px 8px; min-width: 2.8em;
  background: var(--card); color: var(--ink); font-weight: bold; font-variant-numeric: tabular-nums;
}
.preset button:hover { background: var(--drop); }
.preset button.max { background: var(--accent); color: var(--accent-ink); }
.preset button.max:hover { filter: brightness(1.05); }
.btn {
  border: none; border-radius: 999px; padding: 4px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: bold;
}
.btn:hover { filter: brightness(1.05); }
.btn.icon { width: 30px; padding: 4px 0; text-align: center; background: var(--head); color: var(--ink); }

/* 画面 = 操作バー（固定）＋ 表の領域（縦横スクロール）＋ フッター。表の見出し行と左 3 列は領域内で張り付く */
html, body { height: 100%; }
body { display: flex; flex-direction: column; }
header { flex: none; }
main { flex: 1; min-height: 0; overflow: auto; padding: 0; }
/* 余白は表の外側に付ける（main の padding だと張り付いた行・列の外に中身がのぞく） */
main > table { margin: 16px; }
.empty-state { min-height: 100%; display: grid; place-items: center; padding: 24px; box-sizing: border-box; }
.empty-card {
  text-align: center; padding: 28px 36px; border-radius: 18px;
  background: var(--card); border: 2px dashed var(--line); box-shadow: var(--shadow);
}
.empty-title { margin: 0 0 8px; font-size: 18px; font-weight: bold; color: var(--accent); }
.empty-sub { margin: 0 0 16px; color: var(--sub); }
.empty-reset { margin: 14px 0 0; font-size: 12px; color: var(--sub); }
/* 左上の角に置くリセットボタン（文字だけの控えめなボタン） */
.reset-tools { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin-bottom: 10px; }
.reset-tools button, .empty-reset button {
  border: none; background: none; padding: 0; cursor: pointer;
  font-size: 12px; font-weight: normal; color: var(--sub); text-decoration: underline dotted;
}
.reset-tools button:hover, .empty-reset button:hover { color: var(--accent); }
/* 装備の検索欄は空いた幅を使って伸びる（狭い画面では 9.5em まで縮む） */
.combo { flex: 1 1 7.5em; min-width: 7.5em; max-width: 22em; }
.combo .count:not(:empty) { margin-left: 4px; padding: 0 6px; border-radius: 999px; font-size: 11px; font-weight: bold; background: var(--best); color: var(--best-ink); }
#add { flex: 1; min-width: 0; width: auto; background: var(--card); border: 1.5px solid var(--line); border-radius: 8px; padding: 2px 6px; }
.combo { position: relative; display: inline-flex; align-items: center; gap: 4px; }
#add-list {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 5;
  min-width: max(20em, 100%); box-sizing: border-box; max-height: min(60vh, 420px); overflow: auto;
  margin: 0; padding: 4px; list-style: none;
  background: var(--card); color: var(--ink); border: 1.5px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
#add-list li { display: flex; gap: 4px; padding: 3px 8px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
#add-list li .check { width: 1.2em; flex: none; color: var(--best-ink); font-weight: bold; }
#add-list li.chosen { background: var(--best); color: var(--best-ink); font-weight: bold; }
#add-list li.active, #add-list li:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
#add-list li.empty { color: var(--sub); cursor: default; }
#add-list li { align-items: center; }
#add-list li .nm { flex: 1; }
#add-list li.is-hidden .nm { opacity: 0.5; text-decoration: line-through; }
/* 「隠す」「戻す」は行にマウスを乗せたとき（またはキー操作で選んでいるとき）だけ出す */
#add-list .hide-btn {
  visibility: hidden; flex: none; margin-left: 8px; padding: 0 8px; border-radius: 999px; font-size: 11px;
  border: 1px solid var(--line); background: var(--card); color: var(--sub); cursor: pointer;
}
#add-list li:hover .hide-btn, #add-list li.active .hide-btn, #add-list li.is-hidden .hide-btn { visibility: visible; }
#add-list .hide-btn:hover { color: var(--accent); border-color: var(--accent); }
#add-list li.hidden-toggle { justify-content: center; margin-top: 4px; border-top: 1px dashed var(--line); border-radius: 0; color: var(--sub); font-size: 12px; }
#add-list li.hidden-toggle:hover { outline: none; color: var(--accent); }
th.item .ng.hid { background: var(--head); color: var(--sub); }
#add-list mark { background: none; color: var(--accent); text-decoration: underline; }
#job { max-width: 6.5em; }
th.item.cannot .item-name, th.item.cannot .meta { opacity: 0.55; }
th.item .ng { display: inline-block; margin-bottom: 2px; padding: 0 6px; border-radius: 999px; font-size: 11px; font-weight: bold; background: var(--ng); color: var(--ng-ink); }
#theme { margin-left: auto; }
.empty { color: var(--sub); padding: 24px; }

table {
  border-collapse: separate; border-spacing: 0;
  background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; overflow: clip; /* hidden だと張り付き表示が効かない */
  box-shadow: var(--shadow);
}
th, td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 5px 8px; vertical-align: middle; }
tr > :last-child { border-right: none; }
tbody tr:last-child > * { border-bottom: none; }

/* 左の条件列・効果列 */
.c-ref, .c-tr { text-align: center; white-space: nowrap; background: var(--cond); color: var(--cond-ink); font-size: 12px; }
.c-ref.none, .c-tr.none { color: var(--sub); } /* 固定列なので半透明にしない */
.c-label { text-align: left; font-weight: normal; background: var(--head); }
thead .c-ref, thead .c-tr, thead .c-label { font-weight: bold; vertical-align: bottom; font-size: 13px; color: var(--ink); }

/* 装備列（アーリースカイ・ロイヤルフェイバー[1] が 1 行に収まる幅） */
th.item { width: 14.5em; min-width: 14.5em; max-width: 14.5em; background: var(--head); text-align: left; vertical-align: top; cursor: grab; }
th.item.dragging { opacity: 0.4; }
th.item.drop-target { background: var(--drop); }
.item-tools { display: flex; gap: 2px; justify-content: flex-end; margin: -2px -4px 2px 0; }
.item-tools button {
  border: none; background: none; cursor: pointer; color: var(--sub);
  width: 22px; height: 22px; border-radius: 6px; line-height: 1;
}
.item-tools button:hover:not(:disabled) { background: var(--card); color: var(--accent); }
.item-tools button:disabled { opacity: 0.25; cursor: default; }
.item-tools .grip { margin-right: auto; color: var(--sub); cursor: grab; user-select: none; }
.item-name { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-name a { text-decoration: none; }
.meta { color: var(--sub); font-weight: normal; font-size: 11.5px; margin-top: 2px; }
.ctrl { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; font-weight: normal; font-size: 12.5px; }
.ctrl label { display: inline-flex; gap: 4px; align-items: center; }
.ctrl .set { color: var(--badge-ink); }

/* 値セル */
td.v { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.v.off { opacity: 0.35; }
td.v.blank { background: transparent; }
td.v .calc { font-size: 11.5px; color: var(--sub); margin-left: 4px; }
td.v .setname { display: block; font-size: 11px; color: var(--badge-ink); }
td.v.best { background: var(--best); color: var(--best-ink); font-weight: bold; }
td.v.zero { color: var(--sub); }
td.txt { white-space: normal; font-size: 12.5px; text-align: left; }
.badge {
  display: inline-block; font-size: 11px; padding: 0 6px; margin-left: 4px; border-radius: 999px;
  background: var(--badge); color: var(--badge-ink); vertical-align: 1px;
}

tbody.collapsed > tr:not(.section) { display: none; }
/* 見出しの直後に切り替えボタン（横スクロールしても見える位置）。行の空き部分のクリックでも開閉する */
.sec-head { display: flex; align-items: center; gap: 16px; }
tr.section th { cursor: pointer; }
.sec-toggle { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
/* 合計の表示切り替え（小さなセグメント） */
.seg { display: inline-flex; background: var(--card); border-radius: 999px; padding: 2px; gap: 2px; font-weight: normal; }
.seg button {
  border: none; cursor: pointer; border-radius: 999px; padding: 1px 10px; font-size: 12px;
  background: transparent; color: var(--sub);
}
.seg button:hover { color: var(--accent); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: bold; }
td.empty-row { color: var(--sub); text-align: left; padding: 10px 16px; }
.sec-toggle:hover { color: var(--accent); }
.sec-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.caret { font-size: 10px; width: 1em; color: var(--accent); }
tr.section th {
  background: var(--section); color: var(--ink); text-align: left; font-size: 13px; letter-spacing: 0.05em;
}

tr.group > * { padding-top: 3px; padding-bottom: 3px; background: var(--card); }
tr.group th.c-label { font-weight: bold; font-size: 12px; color: var(--accent); background: var(--card); }
.badge.lv { background: var(--cond); color: var(--cond-ink); }

footer { flex: none; color: var(--sub); font-size: 12px; padding: 6px 16px 8px; border-top: 1px solid var(--line); }
footer p { margin: 0; }
footer .copy { font-size: 10.5px; opacity: 0.8; margin-top: 2px; }

/* 合計欄では条件列を無地にする */
td.c-ref.sum, td.c-tr.sum { background: var(--card); }

/* 列が多いときは横スクロール。左の 3 列（精錬・超越・効果）は固定（セルごとに文字サイズが違うので px で揃える） */
.c-ref, .c-tr { width: 64px; min-width: 64px; max-width: 64px; }
.c-label { width: 230px; min-width: 230px; max-width: 230px; }
.c-ref, .c-tr, .c-label { position: sticky; z-index: 1; }
.c-ref { left: 0; }
.c-tr { left: 64px; }
.c-label { left: 128px; }
tbody.collapsed > tr:not(.section) { display: none; }
/* 見出しの直後に切り替えボタン（横スクロールしても見える位置）。行の空き部分のクリックでも開閉する */
.sec-head { display: flex; align-items: center; gap: 16px; }
tr.section th { cursor: pointer; }
.sec-toggle { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
/* 合計の表示切り替え（小さなセグメント） */
.seg { display: inline-flex; background: var(--card); border-radius: 999px; padding: 2px; gap: 2px; font-weight: normal; }
.seg button {
  border: none; cursor: pointer; border-radius: 999px; padding: 1px 10px; font-size: 12px;
  background: transparent; color: var(--sub);
}
.seg button:hover { color: var(--accent); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: bold; }
td.empty-row { color: var(--sub); text-align: left; padding: 10px 16px; }
.sec-toggle:hover { color: var(--accent); }
.sec-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.caret { font-size: 10px; width: 1em; color: var(--accent); }
tr.section th { position: sticky; left: 0; }
thead th { position: sticky; top: 0; z-index: 2; }
thead .c-ref, thead .c-tr, thead .c-label { z-index: 3; } /* 左上の角は縦横どちらにも張り付く */
/* 長い装備名は省略せず折り返す */
.item-name { white-space: normal; overflow: visible; }

/* スマホなど狭い画面: 左の固定 3 列を細くして、装備の列が見えるようにする */
@media (max-width: 640px) {
  h1 { font-size: 16px; }
  main > table { margin: 8px; }
  .c-ref, .c-tr { width: 38px; min-width: 38px; max-width: 38px; padding-left: 2px; padding-right: 2px; font-size: 11px; white-space: normal; }
  .c-tr { left: 38px; }
  .c-label { left: 76px; width: 124px; min-width: 124px; max-width: 124px; font-size: 12px; padding-left: 6px; padding-right: 6px; }
  thead .c-ref, thead .c-tr, thead .c-label { font-size: 12px; }
  th.item { width: 12em; min-width: 12em; max-width: 12em; }
  footer { font-size: 10.5px; padding: 4px 10px 6px; }
  footer .copy { font-size: 9.5px; }
}
.badge.pure { background: var(--best); color: var(--best-ink); }
