:root {
  --bg: #f6f7f9; --fg: #1b1f24; --muted: #667085; --card: #fff; --line: #dfe3e8;
  --accent: #2563eb; --accent-fg: #fff; --danger: #c62828;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --fg: #e8eaed; --muted: #98a2b3; --card: #1a1f26; --line: #2b323b;
    --accent: #5b8def; --accent-fg: #0b1220; --danger: #ef6a6a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 16px/1.5 system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif; padding-bottom: env(safe-area-inset-bottom); }
.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 14px; }

header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
h1 { margin: 0; font-size: 18px; }
h2 { margin: 0 0 8px; font-size: 17px; }
main { max-width: 960px; margin: 0 auto; padding: 16px; }

button {
  font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); cursor: pointer; min-height: 40px;
}
button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
button.danger { color: var(--danger); }
input[type=text], input[type=password], input[type=search] {
  width: 100%; font: inherit; padding: 10px 12px; margin: 6px 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
}
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.check input { margin-top: 4px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; max-width: 520px; margin: 24px auto; }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); }
.notice.err { border-color: var(--danger); color: var(--danger); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input { flex: 1; min-width: 140px; margin: 0; }
.tabs { display: flex; gap: 6px; overflow-x: auto; }
.tabs button { padding: 6px 12px; min-height: 36px; white-space: nowrap; }
.tabs button.on { background: var(--accent); color: var(--accent-fg); border-color: transparent; }

.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 0;
}
.item .ico { font-size: 28px; }
.item .name { font-size: 14px; word-break: break-all; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .sub { font-size: 12px; color: var(--muted); }

.up { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 14px; }
.up progress { width: 100%; height: 8px; }
.up.err { border-color: var(--danger); }

#drop {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 25%, transparent); font-size: 20px; pointer-events: none;
}

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--fg); padding: 16px; max-width: min(520px, 94vw); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog button { margin: 4px 4px 0 0; }
dialog label { display: block; }

#viewer { width: min(1000px, 98vw); max-width: 98vw; max-height: 96vh; padding: 10px; }
.viewer-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.viewer-bar strong { word-break: break-all; font-size: 15px; }
.viewer-bar button { margin: 0; padding: 6px 10px; min-height: 36px; }
#viewer-body { display: flex; justify-content: center; }
#viewer-body video, #viewer-body img { max-width: 100%; max-height: 74vh; background: #000; }
#viewer-body audio { width: 100%; }

.pathbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; color: var(--muted); }
.crumbs button { padding: 4px 8px; min-height: 32px; border-color: transparent; background: transparent; color: var(--accent); }
.pathbar > button { min-height: 36px; padding: 6px 10px; }
select { width: 100%; font: inherit; padding: 10px 12px; margin: 6px 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); }
#edit { width: min(420px, 94vw); }
#edit input[type=text] { margin-bottom: 10px; }

/* fullscreen viewer: media fills the screen in whichever orientation the device is in */
#viewer.full {
  position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh;
  max-width: none; max-height: none; margin: 0; padding: 0; border: 0; border-radius: 0; background: #000;
}
#viewer.full .viewer-bar, #viewer.full #viewer-msg { display: none; }
#viewer.full #viewer-body { width: 100%; height: 100%; align-items: center; }
#viewer.full #viewer-body video {
  width: 100%; height: 100%; max-width: none; max-height: none; object-fit: contain; background: #000;
}
/* The image box is sized to the picture itself by JS (fitFullImage), so the long-press preview is not stretched. */
#viewer.full #viewer-body img { max-width: none; max-height: none; background: #000; }
#viewer-debug { margin: 4px 0 0; font: 11px/1.4 ui-monospace, Menlo, monospace; white-space: pre-wrap; color: var(--muted); }
#viewer.full #viewer-debug { display: none; }
#full-ctl {
  position: fixed; z-index: 30; display: flex; gap: 6px; flex-wrap: wrap;
  top: calc(8px + env(safe-area-inset-top)); right: calc(8px + env(safe-area-inset-right));
}
#full-ctl { transition: opacity .25s; }
#full-ctl.dim { opacity: 0; pointer-events: none; }
#full-ctl button { margin: 0; background: rgba(0, 0, 0, .55); color: #fff; border-color: rgba(255, 255, 255, .35); }
