/* Layout: 倉庫サイン。黒地に安全黄色、ハザード帯付きの固定ヘッダー、場所コードのブロックが各行の主役。下部にタブバー */
:root {
  --bg: #141414;
  --surface: #1f1f1f;
  --surface-2: #262626;
  --line: #333333;
  --fg: #f2f2f2;
  --muted: #9a9a9a;
  --dim: #6f6f6f;
  --yellow: #ffd400;          /* 安全黄色。唯一のアクセント */
  --on-yellow: #141414;
  --ok: #7ee2a8;
  --danger: #ff6b5b;
  --danger-bg: #3a1c19;

  --font-display: "Dela Gothic One", "M PLUS 2", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --font-body: "M PLUS 2", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --r: 6px;
  --tabbar-h: 62px;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  --hazard: repeating-linear-gradient(-45deg, var(--yellow) 0 12px, var(--bg) 12px 24px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 28px);
  overscroll-behavior-y: none;
}
body.no-tabs { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 28px); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
[hidden] { display: none !important; }
::selection { background: var(--yellow); color: var(--on-yellow); }

/* 見出し: 英数字は Dela、日本語は M PLUS 2 の ExtraBold。Dela に偽ボールドを掛けない */
.top h1, .section-head h2, .sheet h3, .brand, .sum .en, .sum .big, .hero .big-code, .hero .en, .loc, .ai-box .ai-title, .input.code-input {
  font-weight: 800; font-synthesis: none;
}
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; width: 1.25em; height: 1.25em; flex: none; }

/* ---------- ヘッダー ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: env(safe-area-inset-top, 0px) var(--gutter-r) 12px var(--gutter-l);
}
.top::before {
  content: ""; display: block; height: 8px; background: var(--hazard);
  margin: 0 calc(-1 * var(--gutter-r)) 14px calc(-1 * var(--gutter-l));
}
.top.scrolled { box-shadow: 0 1px 0 var(--line); }
.top-inner { max-width: 720px; margin: 0 auto; }
.top-row { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.top h1 {
  font-family: var(--font-display); font-size: 24px; line-height: 1.25;
  margin: 0; flex: 1; min-width: 0; letter-spacing: .03em; text-wrap: balance; overflow-wrap: anywhere;
}
.top .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; font-weight: 500; }
.top .sub b { color: var(--yellow); font-weight: 700; }
.back {
  width: 44px; height: 44px; margin-left: -10px; border: 0; background: none;
  display: grid; place-items: center; cursor: pointer; text-decoration: none; color: var(--yellow);
}
.back svg { width: 26px; height: 26px; stroke-width: 2.4; }
.brand { font-family: var(--font-display); font-size: 30px; letter-spacing: .05em; line-height: 1; margin: 2px 0 14px; }
.brand span { color: var(--yellow); }

main { padding: 6px var(--gutter-r) 0 var(--gutter-l); display: flex; flex-direction: column; gap: 22px; max-width: 720px; margin: 0 auto; }

/* ---------- 検索 ---------- */
.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--r);
  padding: 0 6px 0 14px; height: 54px;
}
.search:focus-within { border-color: var(--yellow); }
.search > svg { width: 22px; height: 22px; color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 17px; height: 100%; -webkit-appearance: none; appearance: none; }
.search input::placeholder { color: var(--dim); }
input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; display: none; }
.search .clear { width: 40px; height: 40px; border: 0; background: var(--surface-2); border-radius: var(--r); display: grid; place-items: center; cursor: pointer; }
.search .clear svg { width: 18px; height: 18px; }

/* ---------- セクション見出し（英字ラベル + 日本語） ---------- */
.section { display: flex; flex-direction: column; gap: 10px; }
.section-head { display: flex; align-items: center; gap: 10px; }
.section-head h2 {
  margin: 0; font-family: var(--font-display); font-size: 14px; letter-spacing: .1em; color: var(--yellow);
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; white-space: nowrap;
}
.section-head h2::after { content: ""; flex: 1; height: 2px; background: var(--line); min-width: 12px; }
.section-head .count { font-family: var(--font-mono); font-weight: 600; font-size: 13px; color: var(--muted); }

/* ---------- サマリー ---------- */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sum {
  border-radius: var(--r); padding: 14px; text-decoration: none; display: flex; flex-direction: column;
  min-height: 150px; position: relative; overflow: hidden;
}
.sum.wh { background: var(--yellow); color: var(--on-yellow); }
.sum.mk { background: var(--surface-2); color: var(--yellow); box-shadow: inset 0 0 0 2px var(--yellow); }
.sum:active { transform: scale(.98); }
.sum .en { font-family: var(--font-display); font-size: 13px; letter-spacing: .12em; }
.sum .label { font-size: 14px; font-weight: 700; }
.sum .big { font-family: var(--font-display); font-size: 52px; line-height: 1; margin-top: auto; padding-top: 12px; font-variant-numeric: tabular-nums; }
.sum .big small { font-family: var(--font-body); font-size: 15px; font-weight: 700; margin-left: 4px; }
.sum .meta { font-size: 12.5px; font-weight: 700; opacity: .85; margin-top: 4px; }

/* ---------- 一覧の行 ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 12px; min-height: 64px;
  background: var(--surface); border: 0; border-left: 6px solid var(--yellow); border-radius: 4px;
  text-decoration: none; cursor: pointer; width: 100%; text-align: left;
}
.row:active { background: var(--surface-2); }
.row .body { flex: 1; min-width: 0; }
.row .title { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; line-height: 1.4; }
.row .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 3px 10px; align-items: center; margin-top: 3px; font-weight: 500; }
.row .meta .desc { color: var(--fg); opacity: .8; }
.row .chev { width: 20px; height: 20px; color: var(--dim); }
.row.dim { border-left-color: var(--line); }
.row.dim .title { color: var(--muted); }

/* 場所コードのブロック */
.loc {
  width: 54px; height: 54px; flex: none; border-radius: 4px; display: grid; place-items: center; text-align: center;
  font-family: var(--font-display); font-size: 15px; line-height: 1.1; letter-spacing: .02em; overflow: hidden; padding: 2px;
  background: var(--yellow); color: var(--on-yellow); overflow-wrap: anywhere;
}
.loc.small { font-size: 12px; }
.loc.mk { background: var(--surface-2); color: var(--yellow); font-size: 11px; letter-spacing: .06em; }
.loc.home { background: var(--surface-2); color: var(--muted); }
.loc svg { width: 24px; height: 24px; }
.thumb { width: 54px; height: 54px; border-radius: 4px; object-fit: cover; flex: none; background: var(--surface-2); }

.where { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--fg); }
.where svg { width: 14px; height: 14px; color: var(--yellow); }
.tape { font-family: var(--font-mono); font-weight: 600; font-size: 12.5px; color: var(--yellow); letter-spacing: .02em; white-space: nowrap; }

.pill { font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 3px; white-space: nowrap; letter-spacing: .03em; }
.pill.stored { background: var(--yellow); color: var(--on-yellow); }
.pill.home { background: var(--surface-2); color: var(--fg); box-shadow: inset 0 0 0 1px var(--line); }
.pill.cat { background: none; color: var(--muted); padding: 0; font-weight: 500; font-size: 13px; }
.pill.cat::before { content: "#"; color: var(--dim); margin-right: 1px; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px; border-radius: var(--r); border: 2px solid var(--line);
  background: var(--surface); font-weight: 700; font-size: 15px; cursor: pointer; text-decoration: none; white-space: nowrap; color: var(--fg);
}
.btn svg { width: 20px; height: 20px; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn.primary, .btn.wh, .btn.mk { background: var(--yellow); color: var(--on-yellow); border-color: var(--yellow); }
.btn.outline { background: none; color: var(--yellow); border-color: var(--yellow); }
.btn.danger { color: var(--danger); border-color: var(--danger-bg); background: none; }
.btn.block { width: 100%; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 14px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
.icon-btn { width: 44px; height: 44px; border-radius: var(--r); border: 0; background: none; display: grid; place-items: center; cursor: pointer; color: var(--yellow); text-decoration: none; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--surface-2); }

/* 行内の 出す / 戻す */
.act {
  min-height: 42px; min-width: 64px; padding: 0 12px; border-radius: 4px; border: 2px solid var(--yellow);
  background: none; color: var(--yellow); font-weight: 700; font-size: 14px; cursor: pointer; flex: none;
}
.act.in { background: var(--yellow); color: var(--on-yellow); }
.act:active { transform: scale(.96); }

/* 右下の追加ボタン */
.fab {
  position: fixed; z-index: 20;
  right: calc(var(--gutter-r) + 2px);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  height: 56px; padding: 0 22px 0 18px; border-radius: var(--r); border: 0;
  background: var(--yellow); color: var(--on-yellow); font-weight: 700; font-size: 16px;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 0 0 4px var(--bg), 0 8px 24px rgba(0,0,0,.5); cursor: pointer; text-decoration: none;
}
.fab svg { width: 22px; height: 22px; stroke-width: 2.6; }

/* ---------- フォーム ---------- */
.card { background: var(--surface); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.field .hint, .hint { font-size: 13px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 50px; padding: 10px 12px; border-radius: var(--r); border: 2px solid var(--line);
  background: var(--bg); font-size: 16px; outline: none;
}
.input::placeholder { color: var(--dim); }
textarea.input { min-height: 88px; resize: vertical; line-height: 1.5; }
.input:focus { border-color: var(--yellow); }
.input.code-input { font-family: var(--font-display); font-size: 20px; letter-spacing: .06em; text-transform: uppercase; max-width: 160px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 > * { min-width: 0; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--surface); padding: 4px; border-radius: var(--r); }
.seg button { min-height: 46px; border: 0; border-radius: 4px; background: none; font-weight: 700; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--yellow); color: var(--on-yellow); }

/* ---------- 箱・場所の詳細 ---------- */
.hero { border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; background: var(--surface); position: relative; overflow: hidden; }
.hero.wh { background: var(--yellow); color: var(--on-yellow); }
.hero.mk { box-shadow: inset 0 0 0 2px var(--yellow); }
.hero .hero-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.hero .big-code { font-family: var(--font-display); font-size: 40px; line-height: 1; letter-spacing: .03em; overflow-wrap: anywhere; }
.hero .en { font-family: var(--font-display); font-size: 12px; letter-spacing: .14em; }
.hero.mk .en { color: var(--yellow); }
.hero .mid { font-family: var(--font-mono); font-weight: 800; font-size: 20px; color: var(--yellow); letter-spacing: .04em; }
.hero .desc { font-size: 15.5px; overflow-wrap: anywhere; }
.hero .desc.empty-desc { color: var(--muted); }
.hero .facts { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; opacity: .85; }
.hero .facts b { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.hero.wh .facts { opacity: 1; }
.hero .note { font-size: 14px; overflow-wrap: anywhere; }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 4px; overflow: hidden; background: var(--surface-2); max-width: 100%; border: 0; padding: 0; }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo button.del { position: absolute; top: 4px; right: 4px; width: 34px; height: 34px; border-radius: 4px; border: 0; background: rgba(0,0,0,.7); color: #fff; display: grid; place-items: center; cursor: pointer; }
.photo button.del svg { width: 16px; height: 16px; }
.photo .badge { position: absolute; left: 6px; bottom: 6px; background: var(--yellow); color: var(--on-yellow); font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 3px; }
.photo[aria-pressed="true"] { box-shadow: inset 0 0 0 3px var(--yellow); }
.photo[aria-pressed="false"] img { opacity: .45; }
.photo-add { aspect-ratio: 1; border-radius: 4px; border: 2px dashed var(--line); display: grid; place-items: center; cursor: pointer; color: var(--yellow); background: none; }
.photo-add svg { width: 30px; height: 30px; }

/* AI 読み取り候補 */
.cand { display: flex; flex-direction: column; gap: 8px; }
.cand-row { display: grid; grid-template-columns: 1fr 66px 44px; gap: 6px; align-items: start; background: var(--surface); border-left: 6px solid var(--yellow); border-radius: 4px; padding: 10px; }
.cand-row .input { min-height: 46px; padding: 8px 10px; }
.cand-row .cat { grid-column: 1 / 3; }
.cand-row .icon-btn { height: 46px; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 30px 16px; display: flex; flex-direction: column; align-items: center; gap: 12px; border: 2px dashed var(--line); border-radius: var(--r); }
.empty > svg { width: 40px; height: 40px; color: var(--yellow); }
.empty p { margin: 0; max-width: 32ch; }

.timeline { font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; padding: 8px 2px; }
.timeline div { display: flex; gap: 12px; }
.timeline time { font-family: var(--font-mono); font-weight: 600; font-size: 12.5px; color: var(--yellow); flex: none; padding-top: 1px; min-width: 82px; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 8px 0; font-weight: 700; }

.notice { background: var(--surface); border-radius: var(--r); padding: 12px 14px; font-size: 14px; }
.notice.warn { border-left: 6px solid var(--yellow); }

.ai-box { background: var(--surface); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.ai-box .ai-title { font-family: var(--font-display); font-size: 15px; letter-spacing: .06em; color: var(--yellow); display: flex; align-items: center; gap: 8px; }
.ai-box .ai-title svg { width: 22px; height: 22px; }
.status { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); }
.spinner { width: 18px; height: 18px; border: 2.5px solid var(--yellow); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- ログイン ---------- */
.login { min-height: 100svh; display: flex; flex-direction: column; justify-content: center; gap: 28px; padding: 24px var(--gutter-r) 24px var(--gutter-l); max-width: 440px; margin: 0 auto; }
.login::before, .login::after { content: ""; position: fixed; left: 0; right: 0; height: 14px; background: var(--hazard); }
.login::before { top: env(safe-area-inset-top, 0px); }
.login::after { bottom: env(safe-area-inset-bottom, 0px); }
.login .brand { font-size: 52px; margin: 0; }
.login p { color: var(--muted); margin: 8px 0 0; }
.err { color: var(--danger); font-size: 14px; }

/* ---------- タブバー ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding: 0 var(--gutter-r) env(safe-area-inset-bottom, 0px) var(--gutter-l);
  background: #0c0c0c; border-top: 2px solid var(--surface-2);
}
#tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--dim); font-size: 11px; font-weight: 700; position: relative; }
#tabs a svg { width: 24px; height: 24px; }
#tabs a[aria-current="page"] { color: var(--yellow); }
#tabs a[aria-current="page"]::before { content: ""; position: absolute; top: -2px; left: 22%; right: 22%; height: 3px; background: var(--yellow); }

/* ---------- トースト ---------- */
#toast {
  position: fixed; left: 50%; z-index: 50; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 88px);
  background: var(--yellow); color: var(--on-yellow); padding: 11px 18px; border-radius: var(--r); font-size: 14.5px; font-weight: 700;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- ボトムシート ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; border-radius: 10px 10px 0 0;
  padding: 0 var(--gutter-r) calc(env(safe-area-inset-bottom, 0px) + 16px) var(--gutter-l);
  display: flex; flex-direction: column; gap: 14px; max-height: 88svh; overflow-y: auto; animation: up .2s ease-out;
}
.sheet .grab { height: 8px; background: var(--hazard); margin: 0 calc(-1 * var(--gutter-r)) 6px calc(-1 * var(--gutter-l)); border-radius: 10px 10px 0 0; flex: none; }
.sheet h3 { margin: 0; font-family: var(--font-display); font-size: 20px; line-height: 1.35; letter-spacing: .02em; }
.sheet p { margin: 0; color: var(--muted); font-size: 14.5px; }
.sheet .list { gap: 6px; }
.check-row { display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 4px 0; border-top: 1px solid var(--line); cursor: pointer; }
.check-row input { width: 22px; height: 22px; accent-color: var(--yellow); flex: none; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }

.save-bar {
  position: sticky; bottom: 0; z-index: 5;
  margin: 0 calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter-l));
  padding: 14px var(--gutter-r) calc(env(safe-area-inset-bottom, 0px) + 12px) var(--gutter-l);
  background: linear-gradient(to bottom, transparent, var(--bg) 28%);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 760px) {
  .fab { right: max(24px, calc(50vw - 360px)); }
}
.err:empty { display: none; }
