:root {
  --bg: #f4f7f3; --panel: #ffffff; --ink: #1f2a26; --muted: #5f6f68; --line: #dde5df;
  --accent: #2f7d5c; --accent-ink: #ffffff; --gold: #e3b341; --danger: #b43b3b;
  --radius: 12px; --fs: 16px;
  /* 公式サイトの画素から採取: ヘッダー濃紺 / 枠線ティール / 強調の黄 / フッター帯の水色 / フッター文字 */
  --navy: #142247; --teal: #61c8ab; --sun: #f7cd46; --mint: #e6f6f7; --navy-ink: #1b242d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #121715; --panel: #1b2420; --ink: #e8efe9; --muted: #9db1a7; --line: #2c3934; --accent: #4fa97e; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #121715; --panel: #1b2420; --ink: #e8efe9; --muted: #9db1a7; --line: #2c3934; --accent: #4fa97e; color-scheme: dark; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: var(--fs)/1.6 -apple-system, "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; }
body { padding-bottom: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
main { flex: 1 0 auto; width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-weight: 600; margin: 0; }
h1 { font-size: 18px; }
h2 { font-size: 17px; }
small, .muted { color: var(--muted); font-size: 14px; }

.topbar { position: sticky; top: 0; z-index: 5; background: var(--navy); color: #fff; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; }
.tabs { display: flex; align-items: center; gap: 2px; max-width: 760px; margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; background: none; border: 1.5px solid transparent; border-radius: 999px; padding: 7px 12px; font-size: 15px; font-weight: 600; color: #fff; line-height: 1.3; white-space: nowrap; min-height: 40px; }
.tabs button.on { border-color: var(--teal); }
.tabs .pill { margin-left: auto; border-color: var(--teal); max-width: 42vw; overflow: hidden; text-overflow: ellipsis; }
.tabs .pill.on { background: rgba(97,200,171,.18); }
.pageh { font-size: 17px; margin: 2px 0 10px; }
.subtabs { display: flex; gap: 6px; margin: 0 0 12px; }
.subtabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0; background: var(--panel); border: 1.5px solid var(--line); border-radius: 12px; padding: 8px 4px; font-size: 15px; font-weight: 600; color: var(--muted); min-height: 52px; }
.subtabs button small { font-size: 14px; font-weight: 500; color: inherit; opacity: .85; }
.subtabs button.on { color: var(--navy); border-color: var(--teal); background: var(--mint); }
:root[data-theme="dark"] .subtabs button.on { color: #fff; background: rgba(97,200,171,.16); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .subtabs button.on { color: #fff; background: rgba(97,200,171,.16); } }

main { padding: 12px 16px 96px; max-width: 760px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--accent); color: var(--accent-ink); border: none; border-radius: 10px; padding: 12px 18px; font-size: 16px; font-weight: 600; min-height: 44px; }
.btn.ghost { background: transparent; color: var(--accent); border: 1.5px solid var(--accent); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 8px 12px; font-size: 14px; min-height: 36px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 14px; color: var(--muted); }
.field input, .field select, .field textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: 16px; min-height: 44px; width: 100%; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

.crumbs { display: flex; flex-wrap: wrap; gap: 4px 2px; font-size: 15px; margin-bottom: 10px; align-items: center; }
.crumbs button { background: none; border: none; color: var(--accent); padding: 6px 4px; font-size: 15px; border-radius: 8px; }
.crumbs button.cur { color: var(--ink); font-weight: 600; }
.crumbs button.dropover { background: var(--accent); color: #fff; }
.crumbs .sep { color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.folder { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 12px; min-height: 60px; user-select: none; touch-action: pan-y; -webkit-touch-callout: none; }
.folder .ico { width: 26px; height: 38px; flex: none; background: url("img/mark.png") no-repeat center / contain; }
.brand { display: flex; align-items: center; gap: 8px; flex: 1; }
.brand .mark { width: 22px; height: 32px; background: url("img/mark.png") no-repeat center / contain; flex: none; }
.fab .mark { width: 18px; height: 26px; background: url("img/mark.png") no-repeat center / contain; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 0 6px; }
.hero img { width: 84px; height: 123px; }
.hero .name { font-size: 22px; font-weight: 600; letter-spacing: .04em; }
.empty .mark { width: 76px; height: 111px; margin: 6px auto 14px; background: url("img/mark.png") no-repeat center / contain; opacity: .9; }
.folder .name { flex: 1; font-size: 16px; font-weight: 600; word-break: break-all; }
.folder.dropover, .badge.dropover { outline: 3px solid var(--accent); }
.folder.dragging, .badge.dragging { opacity: .35; }
.folder.ins-before { box-shadow: -5px 0 0 var(--teal, #61c8ab); }
.folder.ins-after { box-shadow: 5px 0 0 var(--teal, #61c8ab); }
.badge { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; user-select: none; touch-action: pan-y; -webkit-touch-callout: none; }
.badge img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; background: var(--bg); }
.badge .name { font-size: 14px; margin-top: 6px; line-height: 1.4; word-break: break-all; min-height: 2.8em; }
.badge .restored { display: inline-block; font-size: 14px; background: var(--gold); color: #3a2a00; border-radius: 6px; padding: 0 6px; margin-right: 4px; }
.dragghost { position: fixed; z-index: 50; pointer-events: none; opacity: .85; width: 120px; transform: translate(-50%, -50%); }
.dragghost img { width: 100%; border-radius: 8px; }
.dragghost .folder { width: 100%; }

.fab { position: fixed; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 6; border-radius: 999px; padding: 14px 20px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; }

[hidden] { display: none !important; }
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet .panel { background: var(--panel); width: 100%; max-width: 760px; max-height: 88vh; overflow: auto; border-radius: 18px; padding: 16px 16px 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.sheet .panel h2 { margin-bottom: 10px; }
.review { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: start; margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.review .stats, .review .warn, .review > label { grid-column: 1 / -1; }
.review img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; background: var(--bg); }
.review .field { margin-bottom: 8px; }
.review .stats, .sheet .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.review > div { min-width: 0; }
.review .stats input, .sheet .stats input { width: 100%; min-width: 0; padding: 8px 6px; font-size: 15px; min-height: 40px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.warn { color: var(--danger); font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.chip button { background: none; border: none; color: var(--muted); font-size: 16px; padding: 0; line-height: 1; }

.detail img.full { display: block; width: auto; max-width: 100%; max-height: 34vh; margin: 0 auto; border-radius: 12px; object-fit: contain; background: var(--bg); }
.detail .statrow { margin: 10px 0 6px; }
.detail > p.muted { margin: 0 0 8px; font-size: 14px; }
@media (min-width: 700px) { .detail img.full { max-height: 40vh; } }
.statrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.statrow div { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.statrow .k { font-size: 14px; color: var(--muted); }
.statrow .v { font-size: 17px; font-weight: 600; word-break: keep-all; }

.ranklist { list-style: none; margin: 0; padding: 0; }
.ranklist li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ranklist img { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; flex: none; }
.ranklist .n { flex: 1; font-size: 15px; }
.ranklist .v { font-weight: 600; font-size: 16px; }
.ranklist .rank { width: 28px; text-align: right; color: var(--muted); font-size: 14px; }

.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 15px; z-index: 30; max-width: 90vw; }
.recovery { font-family: ui-monospace, Menlo, monospace; font-size: 22px; letter-spacing: 2px; text-align: center; background: var(--bg); border-radius: 10px; padding: 14px; margin: 10px 0; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 15px; }
.tip.dup { border-left-color: var(--teal); }
.tip .btn { margin-top: 6px; }
.tip { background: var(--bg); border-left: 4px solid var(--gold); border-radius: 0 10px 10px 0; padding: 10px 12px; font-size: 15px; margin-bottom: 12px; }

/* 国旗入り金バッジ(インラインSVG) */

.folder .gb.ico { --w: 26px; height: auto; background: none; }
.cpick .clist { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.crow { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: none; border-bottom: 1px solid var(--line); padding: 10px 12px; min-height: 48px; text-align: left; font-size: 16px; color: var(--ink); }
.crow:last-child { border-bottom: none; }
.crow.cur { background: rgba(230,184,66,.14); }
.crow .gb { --w: 22px; }
.crow span { flex: 1; }
.crow small { font-size: 14px; color: var(--muted); }
.cpreview { display: flex; align-items: center; gap: 10px; min-height: 0; margin: -4px 0 12px; font-size: 14px; color: var(--muted); }
.cpreview:empty { display: none; }
.cpreview .gb { --w: 30px; }

/* 金ジムバッジ部品(frame.png を基準フレームとして使う) */
.gb { position: relative; display: inline-block; width: var(--w, 26px); aspect-ratio: 1038 / 1515; flex: none; vertical-align: middle; }
.gb .gb-in { position: absolute; left: 14.07%; top: 19.14%; width: 71.48%; height: 65.35%; clip-path: polygon(50% 0, 100% 51.5%, 50% 100%, 0 51.5%); background: #8fc7a9; overflow: hidden; }
.gb .gb-in img { display: block; width: 100%; height: 100%; object-fit: cover; }
.gb .gb-fr { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* 確認画面の3数値ラベル */
.review .stats > div, .sheet .stats > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.review .stats small, .sheet .stats small { font-size: 14px; color: var(--muted); }

/* プロフィール */
.prof { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
.prof .avatar { --w: 84px; }
.prof .pname { font-size: 20px; font-weight: 700; }
.prof .actions { margin-top: 8px; }

/* 画像なしバッジ */
.noimg { width: 100%; aspect-ratio: 1; border-radius: 8px; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.noimg.big { aspect-ratio: auto; min-height: 160px; max-height: 34vh; flex-direction: column; gap: 10px; padding: 16px; }
.gb .gb-in.dim { background: #cfd6da; display: flex; align-items: center; justify-content: center; }
.gb .gb-in.dim span { font-size: 14px; color: #3d4a44; font-weight: 700; transform: translateY(2%); }
.badge .gb .gb-in.dim span, .records .gb .gb-in.dim span { display: none; }
.addopt { margin-bottom: 16px; }
.addopt .btn { width: 100%; }
.addopt p { margin-top: 6px; font-size: 15px; }

/* ---------- 送信待ちキューの帯 ---------- */
.outbox { position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 4; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; max-width: 760px; margin: 8px auto 0; padding: 8px 12px; background: var(--mint); color: var(--navy-ink); border: 1.5px solid var(--teal); border-radius: 12px; font-size: 14px; }
.outbox .ob-n { font-weight: 700; font-size: 15px; }
.outbox .ob-s { flex: 1; min-width: 0; }
.outbox .btn.small { min-height: 34px; }
@media (max-width: 791px) { .outbox { margin-left: 16px; margin-right: 16px; } }
:root[data-theme="dark"] .outbox { background: #22302b; color: #e8efe9; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .outbox { background: #22302b; color: #e8efe9; } }

/* ---------- 金バッジの中の文字(アイコン・復元バッジ) ---------- */
.gb .gb-in { container-type: size; }
.gb .gb-tx { position: absolute; left: 50%; top: 51.5%; transform: translate(-50%, -50%); font-weight: 800; line-height: 1; color: #1f2a26; letter-spacing: .02em; white-space: nowrap; text-align: center; pointer-events: none; }
.gb .gb-tx.onimg { color: #fff; text-shadow: 0 0 3px rgba(0,0,0,.75), 0 1px 2px rgba(0,0,0,.6); }
.gb .gb-tx.v { display: flex; flex-direction: column; align-items: center; letter-spacing: 0; line-height: 1.04; }
.gb .gb-tx.v span { display: block; }
.gb .gb-tx.l1 { font-size: 46cqw; } .gb .gb-tx.l2 { font-size: 38cqw; } .gb .gb-tx.l3 { font-size: 30cqw; } .gb .gb-tx.l4 { font-size: 26cqw; } .gb .gb-tx.l5, .gb .gb-tx.l6 { font-size: 22cqw; }
.gb .gb-tx.v.l2 { font-size: 40cqw; } .gb .gb-tx.v.l3 { font-size: 34cqw; } .gb .gb-tx.v.l4 { font-size: 28cqw; } .gb .gb-tx.v.l5, .gb .gb-tx.v.l6 { font-size: 23cqw; }
/* container query 非対応ブラウザ向けの下限 */
@supports not (font-size: 1cqw) { .gb .gb-tx { font-size: calc(var(--w, 26px) * .3); } .gb .gb-tx.l3, .gb .gb-tx.l4 { font-size: calc(var(--w, 26px) * .22); } .gb .gb-tx.l5, .gb .gb-tx.l6 { font-size: calc(var(--w, 26px) * .17); } }
.folder .gb.ico { --w: 46px; }
.folder { padding: 8px 12px; }
.gb.big { --w: 58%; }
.gb.detail-art { --w: 46%; }
.noimg.art { background: transparent; }
.ranklist .noimg { width: 48px; height: 48px; flex: none; border-radius: 8px; }
.ranklist .noimg .gb { --w: 58%; }

/* ---------- アイコンメーカー ---------- */
.imk { margin-bottom: 8px; }
.imk-top { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.imk-prev .gb.imk-big { --w: 96px; }
.imk-help { font-size: 14px; }
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 6px; }
.palette .sw { width: 34px; height: 34px; border-radius: 8px; border: 2px solid rgba(0,0,0,.08); padding: 0; cursor: pointer; }
.palette .sw.cur { outline: 3px solid var(--accent); outline-offset: 1px; }
.palette .sw.none { background: var(--bg); color: var(--muted); font-size: 14px; font-weight: 600; width: auto; grid-column: span 2; }
.imk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; max-height: 32vh; overflow: auto; }
.imk-c { padding: 0; border: 2px solid transparent; border-radius: 10px; background: var(--bg); overflow: hidden; aspect-ratio: 1; }
.imk-c img { width: 100%; height: 100%; object-fit: cover; display: block; }
.imk-c.cur { border-color: var(--accent); }

/* ---------- データベース検索の結果・復元プレビュー ---------- */
.badge.db .btn.small { width: 100%; margin-top: 8px; }
.badge.db .name { min-height: 0; }
.badge.db .muted.small { font-size: 14px; margin-top: 2px; }
.dbprev { display: flex; align-items: center; gap: 14px; margin: 6px 0 10px; }
.dbprev img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; background: var(--bg); }
.dbprev .noimg { width: 96px; height: 96px; }
.dbprev .n { font-size: 17px; font-weight: 700; }

/* ---------- 記録: スクショの薄い緑に合わせた背景 ---------- */
:root { --rank-bg: #f2fbf3; }
.card.records { background: var(--rank-bg); border-color: #d9eedd; }
.card.records .ranklist li { border-bottom-color: #d9eedd; }
.card.records .ranklist img { background: transparent; }
:root[data-theme="dark"] .card.records { background: var(--panel); border-color: var(--line); }
:root[data-theme="dark"] .card.records .ranklist li { border-bottom-color: var(--line); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .card.records { background: var(--panel); border-color: var(--line); } :root:not([data-theme="light"]) .card.records .ranklist li { border-bottom-color: var(--line); } }
/* 一覧・記録の中の金バッジ部品は、サムネ用の img ルール(正方形・背景色)を打ち消す */
.badge .gb img, .ranklist .gb img, .dbprev .gb img { width: 100%; height: 100%; aspect-ratio: auto; object-fit: cover; background: transparent; border-radius: 0; margin: 0; }
.badge .gb .gb-fr, .ranklist .gb .gb-fr, .dbprev .gb .gb-fr { object-fit: contain; }

/* ---------- 1) フォルダ内のバッジ画像をアイコンに使うとき: フレーム込みのサムネなので、ひし形の中身だけを拡大 ---------- */
.gb .gb-in img.crop { transform: scale(1.72); transform-origin: 50% 52%; }
/* ---------- 7) 設定のお礼カード ---------- */
.card.thanks { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card.thanks h2 { margin-bottom: 2px; }
.card.thanks .btn { flex: none; text-decoration: none; }
