:root {
  --bg: #f6f4ef; --panel: #ffffff; --ink: #1f2328; --sub: #5d636b; --line: #dedad2;
  --accent: #2f5fb3; --accentInk: #ffffff; --ok: #1d7446; --okbg: #e2f2e8; --mid: #7f5900; --midbg: #fbefcf;
  --ng: #a3392b; --ngbg: #f8e3df; --none: #6f757c; --nonebg: #ecebe7; --crown: #a87a00;
  --navH: 58px; --safeB: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181b; --panel: #202328; --ink: #e8e6e1; --sub: #a5aab0; --line: #363a40;
    --accent: #7ea6ef; --accentInk: #10151f; --ok: #73d29b; --okbg: #1c3a2a; --mid: #e9c46a; --midbg: #3c3117;
    --ng: #f28d7d; --ngbg: #44231e; --none: #9aa0a6; --nonebg: #2a2d32; --crown: #e9c46a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181b; --panel: #202328; --ink: #e8e6e1; --sub: #a5aab0; --line: #363a40;
  --accent: #7ea6ef; --accentInk: #10151f; --ok: #73d29b; --okbg: #1c3a2a; --mid: #e9c46a; --midbg: #3c3117;
  --ng: #f28d7d; --ngbg: #44231e; --none: #9aa0a6; --nonebg: #2a2d32; --crown: #e9c46a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "BIZ UDPGothic", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
  font-size: 15px; line-height: 1.55; -webkit-tap-highlight-color: transparent;
}
button, select, input, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ヘッダーとタブ */
.stick { position: sticky; top: 0; z-index: 5; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); background: var(--panel); border-bottom: 1px solid var(--line); }
.title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title small { font-weight: 400; color: var(--sub); font-size: 12px; margin-left: 4px; }
.sync { font-size: 12px; color: var(--sub); white-space: nowrap; padding: 3px 9px; border-radius: 999px; background: var(--nonebg); }
.sync.ok { color: var(--ok); background: var(--okbg); }
.sync.ng { color: var(--ng); background: var(--ngbg); }
.sync.busy { color: var(--mid); background: var(--midbg); }
.topTabs { display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.topTabs button { flex: 0 0 auto; border: 1px solid var(--line); background: transparent; padding: 7px 14px; border-radius: 999px; font-size: 14px; cursor: pointer; }
.topTabs button.on { background: var(--accent); border-color: var(--accent); color: var(--accentInk); }
.bottomTabs, .fab { display: none; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h2 { font-size: 16px; margin: 20px 0 8px; }
h3 { font-size: 15px; margin: 0; }
.note { color: var(--sub); font-size: 13px; margin: 4px 0 12px; }
.note.top0, .top0 { margin-top: 0; }
.small { font-size: 12.5px; }
.meta { color: var(--sub); font-size: 13px; }
.empty { text-align: center; color: var(--sub); padding: 32px 0; }
.tag { font-size: 11px; color: var(--sub); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-weight: 400; }

/* カード */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 0 0 10px; scroll-margin-top: 110px; }
.cardHead { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.cardHead .meta { flex: 1 1 auto; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.b-perfect { background: var(--okbg); color: var(--ok); }
.b-full { background: var(--midbg); color: var(--mid); }
.b-partial { background: var(--ngbg); color: var(--ng); }
.b-none { background: var(--nonebg); color: var(--none); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 4px; }
.chip { font-size: 12.5px; padding: 2px 8px; border-radius: 6px; border: 1px dashed var(--line); background: transparent; color: var(--none); }
.chip.max { background: var(--okbg); color: var(--ok); border: 1px solid transparent; }
.chip.low { background: var(--midbg); color: var(--mid); border: 1px solid transparent; }
.legend { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; }
.cands { font-size: 13px; color: var(--sub); margin-top: 4px; }
.cands b { color: var(--ink); font-weight: 600; }
details.sub { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; }
details summary { cursor: pointer; font-size: 13px; color: var(--sub); padding: 6px 0; min-height: 32px; list-style-position: outside; }
details summary b { color: var(--ink); }
.sub .line { display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; font-size: 13px; padding: 3px 0; }

/* 集計 */
.sum { display: flex; gap: 6px; margin: 0 0 12px; }
.stat { flex: 1 1 0; min-width: 0; border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; }
.stat b { font-size: 22px; line-height: 1.2; }
.stat b small { font-size: 13px; font-weight: 400; }
.stat span { font-size: 12px; }
.overview { display: flex; flex-wrap: wrap; gap: 5px; margin: 0 0 10px; }
.dot { text-decoration: none; font-size: 12.5px; font-weight: 700; padding: 5px 9px; border-radius: 8px; min-width: 44px; text-align: center; }

/* 操作部品 */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 10px; }
.toolbar input[type=search], .toolbar select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); min-height: 40px; }
.toolbar input[type=search] { flex: 1 1 200px; min-width: 0; }
.toolbar select { flex: 0 1 auto; max-width: 100%; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; min-height: 40px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
button.primary, button.ghost, button.danger, button.small, .btnLike {
  border-radius: 10px; padding: 8px 16px; min-height: 40px; cursor: pointer; border: 1px solid var(--line); background: var(--panel); display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accentInk); font-weight: 600; }
button.danger, summary.danger { color: var(--ng); }
button.small { padding: 4px 12px; min-height: 36px; font-size: 14px; }
button:disabled { opacity: .45; cursor: default; }

/* ベルト */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.grid .card { margin: 0; }
.card.belt { cursor: pointer; transition: border-color .15s; }
.card.belt:hover { border-color: var(--accent); }
.card.belt:active { transform: scale(.995); }
.editHint { margin-left: auto; font-size: 12px; color: var(--accent); }
.effects { margin: 6px 0 0; padding: 0; list-style: none; font-size: 13.5px; }
.effects li { padding: 1px 0; display: flex; align-items: baseline; gap: 4px; }
.effects .v { color: var(--sub); }
.crown { color: var(--crown); font-weight: 700; display: inline-block; width: 1em; }
.crown.off { visibility: hidden; }
.unk { color: var(--ng); }
.uses { font-size: 12.5px; margin-top: 6px; line-height: 1.6; }
.uses .lbl { color: var(--sub); }

/* アクセ */
.card.list { padding: 4px 14px; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .nm { font-weight: 600; font-size: 14.5px; }
.item .sp { color: var(--sub); font-size: 12.5px; grid-column: 1 / -1; }
.item input.memo { grid-column: 1 / -1; font-size: 14px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); min-height: 36px; }
select.st { font-size: 14px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); min-height: 38px; }
select.st.s2 { background: var(--okbg); color: var(--ok); border-color: transparent; }
select.st.s1 { background: var(--midbg); color: var(--mid); border-color: transparent; }

/* 耐性防具 */
.tblWrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; -webkit-overflow-scrolling: touch; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
th, td { border-bottom: 1px solid var(--line); padding: 6px 6px; text-align: center; vertical-align: middle; white-space: nowrap; }
thead th { background: var(--nonebg); font-weight: 600; font-size: 12px; line-height: 1.3; }
.stickCol { position: sticky; left: 0; z-index: 1; background: var(--panel); text-align: left; border-right: 1px solid var(--line); min-width: 116px; max-width: 140px; white-space: normal; }
thead .stickCol { background: var(--nonebg); z-index: 2; }
.stickCol .spec { display: block; font-weight: 400; font-size: 11.5px; color: var(--sub); line-height: 1.35; }
td.cell button { font-size: 13px; min-width: 56px; min-height: 38px; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line); background: transparent; cursor: pointer; }
td.cell button.done { background: var(--okbg); color: var(--ok); border-color: transparent; font-weight: 700; }
td.cell button.todo { background: var(--ngbg); color: var(--ng); border-color: transparent; }
td.cell button.opt { background: var(--midbg); color: var(--mid); border-color: transparent; }
td.cell .na { color: var(--none); }

/* 保存・履歴 */
.log { font-size: 13px; max-height: 50vh; overflow-y: auto; }
.log div { padding: 4px 0; border-bottom: 1px solid var(--line); }
.log div:last-child { border-bottom: 0; }
.log time { color: var(--sub); margin-right: 8px; font-variant-numeric: tabular-nums; }
.login { display: flex; gap: 8px; flex-wrap: wrap; }
.login input { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); flex: 1 1 220px; min-height: 42px; }
.btnLike { cursor: pointer; }

/* トースト */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 30;
  background: #2b2f35; color: #fff; padding: 10px 14px; border-radius: 12px; font-size: 14px; display: flex; gap: 12px; align-items: center; max-width: calc(100vw - 32px); transition: opacity .2s, transform .2s; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { background: transparent; border: 0; color: #9cc0ff; font-weight: 700; padding: 6px 4px; min-height: 36px; cursor: pointer; white-space: nowrap; }

/* ダイアログ */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); background: var(--panel); color: var(--ink); overflow: hidden; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { display: flex; flex-direction: column; max-height: inherit; }
.dlgHead { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.dlgHead h2 { margin: 0; font-size: 15px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlgBody { overflow-y: auto; padding: 12px 16px 20px; overscroll-behavior: contain; }
dialog label, .dlgBody .lbl { display: block; font-size: 13px; color: var(--sub); margin: 8px 0; }
dialog input, dialog select, dialog textarea { display: block; width: 100%; margin-top: 3px; font-size: 16px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 42px; }
dialog .row { display: grid; grid-template-columns: 1fr 96px 72px; gap: 8px; }
.builder { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.builder select, .builder input { width: auto; display: inline-block; margin: 0; font-size: 16px; padding: 6px 8px; min-height: 40px; background: var(--panel); }
.builder #bdSub { display: contents; }
.builder input { width: 76px; }
.preview { margin: 8px 0; font-size: 14px; }
.pv { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0 4px 4px; border-bottom: 1px solid var(--line); }
.pv:last-of-type { border-bottom: 0; }
.pv .x { border: 0; background: var(--nonebg); color: var(--sub); width: 36px; height: 36px; border-radius: 50%; font-size: 18px; cursor: pointer; flex: 0 0 auto; }
details.raw { margin: 4px 0; }
#beltDel { margin-top: 16px; width: 100%; }
#beltDel[hidden] { display: none; }

/* スマホ */
@media (max-width: 720px) {
  html { scroll-padding-top: 0; }
  .stick { position: static; }
  .top { position: sticky; top: 0; z-index: 5; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
  .title { font-size: 16px; }
  .title small, .topTabs { display: none; }
  main { padding: 12px 12px calc(var(--navH) + var(--safeB) + 84px); }
  .card { scroll-margin-top: 68px; padding: 12px; }
  .bottomTabs { display: grid; grid-template-columns: repeat(6, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safeB); }
  .bottomTabs button { border: 0; background: transparent; height: var(--navH); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 11px; color: var(--sub); cursor: pointer; }
  .bottomTabs button i { font-style: normal; font-size: 18px; line-height: 1.1; }
  .bottomTabs button.on { color: var(--accent); font-weight: 700; }
  .bottomTabs button.on i { transform: scale(1.1); }
  body[data-tab="belts"] .fab { display: flex; }
  .fab { position: fixed; right: 16px; bottom: calc(var(--navH) + var(--safeB) + 16px); z-index: 11; width: 56px; height: 56px; border-radius: 50%;
    border: 0; background: var(--accent); color: var(--accentInk); font-size: 28px; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(0,0,0,.25); cursor: pointer; }
  .hideSm { display: none !important; }
  .toast { bottom: calc(var(--navH) + var(--safeB) + 12px); }
  body[data-tab="belts"] .toast { bottom: calc(var(--navH) + var(--safeB) + 84px); }
  .toolbar input[type=search], .toolbar select, .login input, .item input.memo, select.st { font-size: 16px; }
  .toolbar select { flex: 1 1 0; min-width: 0; }
  .grid { grid-template-columns: 1fr; }
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; margin: 0; }
  dialog form { height: 100%; }
  .dlgHead { padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .dlgBody { flex: 1 1 auto; padding-bottom: calc(24px + var(--safeB)); }
  dialog .row { grid-template-columns: 1fr 1fr; }
  dialog .row .wide { grid-column: 1 / -1; }
  .stat b { font-size: 20px; }
}
@media (hover: none) { .card.belt:hover { border-color: var(--line); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* 追加：ヘルプ・リンク・切替 */
details summary { list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: '▸'; display: inline-block; width: 1.1em; transition: transform .15s; color: var(--sub); }
details[open] > summary::before { transform: rotate(90deg); }
.help { margin: 0 0 8px; }
.help summary { font-size: 13px; min-height: 36px; display: flex; align-items: center; }
.help .note { margin: 0 0 8px; }
button.link { border: 0; background: none; padding: 2px 0; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; min-height: 28px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 0 0 10px; }
.seg button { border: 0; background: var(--panel); padding: 8px 16px; min-height: 40px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accentInk); font-weight: 600; }
button.tg { border-radius: 8px; border: 1px solid var(--line); background: transparent; cursor: pointer; min-height: 40px; min-width: 96px; padding: 4px 10px; font-size: 14px; }
td.cell button.tg { min-width: 56px; min-height: 38px; font-size: 13px; padding: 4px 6px; }
button.tg.done { background: var(--okbg); color: var(--ok); border-color: transparent; font-weight: 700; }
button.tg.todo { background: var(--ngbg); color: var(--ng); border-color: transparent; }
button.tg.opt { background: var(--midbg); color: var(--mid); border-color: transparent; }
#armorType { flex: 1 1 auto; }
@media (max-width: 720px) {
  #beltBase { flex: 0.8 1 0; } #beltUse { flex: 1.2 1 0; } #beltSort { flex: 1 1 0; }
  .item .nm .meta { display: block; font-weight: 400; }
}
