* { box-sizing: border-box; }
:root, :root[data-theme="dark"] {
  --bg: #131314; --surface: #1e1f20; --surface2: #28292a; --text: #e3e3e3; --muted: #9aa0a6;
  --border: #3c4043; --accent: #0b57d0; --accent2: #a8c7fa; --accent-soft: #303134;
  --active-bg: #004a77; --active-text: #c2e7ff;
  --ok: #34d399; --ng: #f87171; --warn: #fbbf24; --star: #f9ab00;
  --sidebar-w: 256px;
}
:root[data-theme="light"] {
  --bg: #fff; --surface: #f0f4f9; --surface2: #fff; --text: #1f1f1f; --muted: #5f6368;
  --border: #dde3ea; --accent: #0b57d0; --accent2: #0b57d0; --accent-soft: #e8f0fe;
  --active-bg: #c2e7ff; --active-text: #001d35;
}
:root[data-theme="solarized-light"] {
  --bg: #fdf6e3; --surface: #eee8d5; --surface2: #fdf6e3; --text: #073642; --muted: #657b83;
  --border: #ddd6b8; --accent: #268bd2; --accent2: #268bd2; --accent-soft: #eee8d5;
  --active-bg: #268bd2; --active-text: #fdf6e3;
}
:root[data-theme="solarized-dark"] {
  --bg: #002b36; --surface: #073642; --surface2: #073642; --text: #eee8d5; --muted: #839496;
  --border: #155263; --accent: #2aa198; --accent2: #2aa198; --accent-soft: #0a4552;
  --active-bg: #2aa198; --active-text: #002b36;
}
body { margin: 0; font-family: "Google Sans", system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", sans-serif; background: var(--bg); color: var(--text); }
button { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface2); color: var(--text); border-radius: 999px; padding: 7px 14px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .5; cursor: default; }
input[type="text"], input[type="search"], input[type="password"], textarea, select { font: inherit; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface2); color: var(--text); width: 100%; }

/* ---- Googleフォト風トップバー ---- */
header.top { display: flex; align-items: center; gap: 16px; padding: 10px 20px; position: sticky; top: 0; z-index: 10; background: var(--bg); }
.logo { font-size: 20px; white-space: nowrap; display: flex; gap: 8px; align-items: center; }
.logo b { font-weight: 500; }
.logo .sub { font-size: 11px; color: var(--muted); display: block; line-height: 1.1; }
.searchbar { flex: 1; max-width: 720px; margin: 0 auto; position: relative; }
.searchbar input { border-radius: 999px; padding: 12px 18px 12px 44px; background: var(--surface); border: none; font-size: 15px; }
.searchbar .ic { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.top-actions { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.demo-badge { background: var(--warn); color: #111; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 2px 9px; }

/* ---- レイアウト: ScratchAsset風サイドバー + メイン ---- */
.layout { display: flex; align-items: flex-start; }
aside.side { width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); position: sticky; top: 64px; height: calc(100vh - 64px); overflow-y: auto; padding: 8px 12px 20px; }
aside.side h3 { font-size: 12px; color: var(--muted); margin: 18px 10px 6px; font-weight: 600; letter-spacing: .02em; }
.navitem { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: none; background: transparent; border-radius: 999px; padding: 9px 14px; font-size: 14px; color: var(--text); }
.navitem:hover { background: var(--surface); }
.navitem.active { background: var(--active-bg); color: var(--active-text); font-weight: 600; }
.navitem .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.navitem.active .count { color: inherit; }
.side .clock { margin: 14px 10px 0; font-size: 22px; font-weight: 500; }
.side .clock small { display: block; font-size: 12px; color: var(--muted); }
main { flex: 1; min-width: 0; padding: 8px 24px 40px; }

/* ---- ビュー切替タブ（Googleフォトのアルバム画面風） ---- */
.viewtabs { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0 18px; }
.viewtabs .tab { border-radius: 10px; padding: 8px 16px; background: var(--surface2); border: 1px solid var(--border); }
.viewtabs .tab.active { background: var(--accent2); color: #041e49; border-color: transparent; font-weight: 700; }
.viewtabs .spacer { flex: 1; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: transparent; padding: 6px 12px; font-size: 13px; }
.seg button.active { background: var(--accent-soft); font-weight: 700; }
h2.viewtitle { font-size: 22px; font-weight: 500; margin: 4px 0 14px; }

/* ---- Googleフォト風: 時系列グリッド ---- */
.dategroup { margin-bottom: 10px; }
.dategroup h3 { font-size: 15px; font-weight: 500; margin: 18px 0 8px; }
.photogrid { display: grid; gap: 4px; }
.photogrid.size-s { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.photogrid.size-m { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.photogrid.size-l { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.photo { position: relative; aspect-ratio: 1; overflow: hidden; border: none; border-radius: 4px; padding: 0; background: var(--surface); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .fav { position: absolute; top: 6px; right: 8px; color: var(--star); text-shadow: 0 1px 4px rgba(0,0,0,.7); font-size: 16px; }
.photo:hover img { filter: brightness(1.08); }

/* ---- Googleフォト風: アルバムカード ---- */
.albumgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 22px 16px; }
.album { border: none; background: transparent; text-align: left; padding: 0; border-radius: 0; }
.album .cover { aspect-ratio: 1; border-radius: 16px; overflow: hidden; background: var(--surface); }
.album .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album .t { font-size: 14px; margin-top: 9px; color: var(--text); }
.album .c { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- ScratchAsset風: ファイルカード ---- */
.filegrid { display: grid; gap: 12px; }
.filegrid.size-s { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.filegrid.size-m { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.filegrid.size-l { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.item { background: var(--surface2); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; cursor: pointer; text-align: left; padding: 0; width: 100%; color: var(--text); }
.item .thumb { aspect-ratio: 4/3; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; font-size: 34px; overflow: hidden; }
.item .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item .meta { padding: 9px 11px; }
.item .name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.chip { font-size: 11px; background: var(--accent-soft); color: var(--accent2); border-radius: 999px; padding: 1px 8px; border: none; }
.chip.active { background: var(--accent); color: #fff; }
.star { color: var(--star); }
.crumbs { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; font-size: 14px; }
.crumbs button { border: none; background: none; color: var(--accent2); padding: 2px 4px; }

/* ---- 詳細ドロワー（ScratchAssetの詳細画面風） ---- */
.drawer-back { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 94vw); background: var(--surface2); z-index: 21; padding: 18px; overflow-y: auto; box-shadow: -8px 0 24px rgba(0,0,0,.35); }
.drawer img.big { width: 100%; border-radius: 12px; background: var(--accent-soft); }
.drawer h2 { font-size: 16px; word-break: break-all; }
.field { margin: 12px 0; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.muted { color: var(--muted); font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px; margin: 20px auto; max-width: 640px; }
.card h2 { margin-top: 0; }
table.checks { width: 100%; border-collapse: collapse; font-size: 12px; }
table.checks td, table.checks th { padding: 5px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.ok { background: var(--accent-soft); color: var(--ok); } .badge.ng { background: var(--accent-soft); color: var(--ng); } .badge.wait { background: var(--accent-soft); color: var(--warn); }
details.checks { margin: 16px 6px; font-size: 12px; color: var(--muted); }
#toast-root { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 50; }
.toast { background: #e3e3e3; color: #111; padding: 9px 16px; border-radius: 999px; font-size: 13px; margin-top: 6px; }
/* ---- モバイル対応 (Googleフォトアプリ風: 下部ナビ + ドロワー式サイドバー) ---- */
#btn-menu { display: none; }
#bottomnav { display: none; }
#side-backdrop { display: none; }
@media (max-width: 860px) {
  header.top { gap: 6px; padding: 10px 10px; }
  #btn-menu { display: inline-flex; padding: 8px; }
  .logo { font-size: 17px; }
  .logo .sub { display: none; }
  .top-actions { display: none; }
  .searchbar input { padding: 10px 14px 10px 40px; font-size: 14px; }
  .layout { display: block; }
  aside.side { position: fixed; top: 0; left: 0; bottom: 0; height: 100dvh; width: min(300px, 84vw); flex: none;
    background: var(--bg); z-index: 40; transform: translateX(-105%); transition: transform .25s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,.35); padding: 16px 12px 24px; }
  body.nav-open aside.side { transform: none; }
  body.nav-open #side-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 39; }
  main { padding: 8px 12px 96px; }
  h2.viewtitle { font-size: 19px; }
  .viewtabs { justify-content: flex-end; margin-bottom: 10px; }
  .viewtabs .tab { display: none; }
  .photogrid.size-s { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
  .photogrid.size-m { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
  .photogrid.size-l { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }
  .filegrid.size-s { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .filegrid.size-m { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
  .filegrid.size-l { grid-template-columns: 1fr; }
  .albumgrid { grid-template-columns: repeat(2, 1fr); gap: 18px 12px; }
  .card { margin: 12px 0; padding: 14px; }
  #bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  #bottomnav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    border: none; background: transparent; font-size: 10px; padding: 6px 2px; border-radius: 10px; color: var(--muted); }
  #bottomnav button.active { color: var(--accent2); font-weight: 700; }
  #bottomnav .ic { width: 21px; height: 21px; }
  #toast-root { bottom: 92px; }
}

/* ---- Lucide線アイコン ---- */
.ic { width: 18px; height: 18px; flex: 0 0 auto; vertical-align: -3px; }
.logo .ic { width: 24px; height: 24px; color: var(--accent2); }
.navitem .ic { width: 20px; height: 20px; }
.item .thumb .ic { width: 42px; height: 42px; color: var(--accent2); }
.photo .ic { width: 44px; height: 44px; color: var(--muted); }
.photo .fav .ic { width: 18px; height: 18px; fill: var(--star); color: var(--star); }
.item .name .star .ic { width: 13px; height: 13px; fill: var(--star); color: var(--star); vertical-align: -1px; }
.album .cover { display: flex; align-items: center; justify-content: center; }
.album .cover .ic { width: 48px; height: 48px; color: var(--muted); }
/* ---- テーマ選択 (ScratchAsset方式: 2x2グリッド) ---- */
.themepicker { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 4px 6px 8px; }
.themepicker button { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 4px; font-size: 11.5px; border-radius: 10px; background: var(--surface2); white-space: nowrap; overflow: hidden; }
.themepicker button .ic { width: 15px; height: 15px; }
.themepicker button.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.card .themepicker { margin: 4px 0 0; }
.card .themepicker button { font-size: 13px; padding: 9px 6px; }
aside.side .themepicker { grid-template-columns: 1fr; }
aside.side .themepicker button { justify-content: flex-start; padding-left: 12px; font-size: 12.5px; }

/* ---- フォルダピッカー等のモーダル ---- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 45; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface2); border: 1px solid var(--border); border-radius: 16px; padding: 18px; width: min(480px, 94vw); max-height: 84vh; overflow-y: auto; }
.modal h3 { margin: 0 0 10px; font-size: 16px; }
.modal .navitem { border-radius: 10px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; }

/* ---- 写真エディタ ---- */
.modal.editor { width: min(760px, 96vw); }
#ed-canvas { width: 100%; max-height: 56vh; object-fit: contain; background: #000; border-radius: 10px; touch-action: none; }
.ed-sliders { display: grid; gap: 6px; margin: 8px 0 12px; }
.ed-sliders label { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; }
.ed-sliders input[type="range"] { flex: 1; }

/* ---- ゴミ箱 ---- */
.trash-list { display: grid; gap: 6px; }
.trash-row { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; }
.trash-row .t-name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-row .t-ic svg { width: 18px; height: 18px; }

/* ---- スライドショー ---- */
#ss-root { position: fixed; inset: 0; background: #000; z-index: 200; display: flex; align-items: center; justify-content: center; }
#ss-root img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.ss-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.75)); color: #fff; }
.ss-bar #ss-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-bar button { background: rgba(255,255,255,.14); color: #fff; border-color: transparent; }
#ss-fab { position: fixed; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 90; display: inline-flex; align-items: center; gap: 7px; background: var(--accent); color: var(--on-accent); border: none; border-radius: 999px; padding: 11px 18px; font-weight: 700; box-shadow: var(--shadow); }
@media (max-width: 860px) { #ss-fab { bottom: calc(76px + env(safe-area-inset-bottom)); } }
