:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --line: rgba(255,255,255,.10);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-ink: #04263a;
  --danger: #f87171;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* hidden属性を最優先で効かせる（.busy/.modal の display:grid に負けないように） */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top));
  background: rgba(15,23,42,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .02em; }
.actions { display: flex; gap: 8px; }

button { font: inherit; cursor: pointer; border-radius: 12px; border: 1px solid transparent; }
.ghost { background: transparent; border-color: var(--line); color: var(--text); padding: 8px 12px; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 8px 16px; border: 0; }
.danger { background: transparent; color: var(--danger); border: 1px solid rgba(248,113,113,.4); padding: 10px 14px; }

.searchbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  position: sticky; top: 56px; z-index: 4; background: var(--bg);
}
.searchbar input {
  flex: 1; padding: 12px 14px; border-radius: 12px; font-size: 16px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.count { font-size: 12px; color: var(--muted); min-width: 42px; text-align: right; }

.list { padding: 4px 12px 120px; display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--muted); text-align: center; padding: 60px 20px; }

.item {
  display: flex; gap: 12px; align-items: center; padding: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.item:active { background: var(--panel-2); }
.thumb {
  width: 56px; height: 40px; border-radius: 8px; object-fit: cover; flex-shrink: 0;
  background: var(--panel-2); border: 1px solid var(--line);
}
.thumb.placeholder { display: grid; place-items: center; font-size: 18px; color: var(--muted); }
.item-main { min-width: 0; flex: 1; }
.item-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.item-tags { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; background: rgba(56,189,248,.14); color: var(--accent); padding: 2px 8px; border-radius: 999px; }

.fab {
  position: fixed; right: 20px; bottom: calc(24px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: 0; z-index: 6;
  background: var(--accent); color: var(--accent-ink); font-size: 30px; font-weight: 300;
  box-shadow: 0 10px 24px rgba(56,189,248,.35);
}
.fab:active { transform: scale(.96); }

.modal { position: fixed; inset: 0; z-index: 20; display: grid; align-items: end; background: rgba(0,0,0,.5); }
.sheet {
  background: var(--bg); border-top-left-radius: 20px; border-top-right-radius: 20px;
  max-height: 92dvh; display: flex; flex-direction: column; animation: up .18s ease;
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg);
}
.sheet-title { font-weight: 700; }
.sheet-body { overflow-y: auto; padding: 14px 16px 24px; }
.card-img { width: 100%; border-radius: 12px; border: 1px solid var(--line); margin-bottom: 14px; }

.banner { margin: 12px 16px 0; padding: 10px 12px; border-radius: 10px; font-size: 13px; }
.banner.ok { background: rgba(34,197,94,.14); color: #86efac; }
.banner.warn { background: rgba(250,204,21,.14); color: #fde047; }

.fields { display: flex; flex-direction: column; gap: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px; font-size: 16px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.field textarea { min-height: 60px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.sheet-foot { display: flex; justify-content: space-between; margin-top: 22px; }

.busy { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; gap: 14px; background: rgba(15,23,42,.72); }
.busy { grid-auto-flow: row; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#busyText { color: var(--muted); font-size: 14px; }

@media (min-width: 640px) {
  .modal { align-items: center; justify-content: center; }
  .sheet { max-width: 560px; width: 100%; border-radius: 20px; }
}
