:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --text: #18181b;
  --muted: #6b6b74;
  --line: #e2e0d9;
  --accent: #3b5bfd;
  --accent-text: #ffffff;
  --accent-soft: rgba(59, 91, 253, 0.1);
  --danger: #d4322c;
  --ok: #1f9d55;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1a1a1d;
    --surface-2: #232327;
    --text: #ececef;
    --muted: #9a9aa3;
    --line: #2d2d32;
    --accent: #7086ff;
    --accent-text: #0d0d10;
    --accent-soft: rgba(112, 134, 255, 0.14);
    --danger: #ff6b63;
    --ok: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 1080px; margin: 0 auto; padding: 8px 16px 72px; }
h1, h2 { margin: 0; letter-spacing: -0.015em; }
h1 { font-size: 26px; line-height: 1.2; }
h2 { font-size: 18px; }
a { color: inherit; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; margin: 2px 0 0; }
.error { color: var(--danger); margin: 0; font-size: 13px; }
.spacer { flex: 1; }
kbd {
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
  background: var(--surface);
}

/* ---------- header ---------- */
.top {
  max-width: 1080px; margin: 0 auto; padding: 16px;
  display: flex; align-items: center; gap: 20px;
}
.logo { display: inline-flex; align-items: center; gap: 9px; font-weight: 750; font-size: 20px; text-decoration: none; letter-spacing: -0.03em; }
.logo-mark {
  width: 20px; height: 24px; background: var(--accent);
  clip-path: path("M10 0C14 6 19 9.8 19 14.5A9 9 0 0 1 1 14.5C1 9.8 6 6 10 0Z");
}
.nav { display: flex; gap: 4px; }
.nav a {
  text-decoration: none; font-size: 14px; font-weight: 550; color: var(--muted);
  padding: 6px 12px; border-radius: 8px;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--text); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 14px; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit; font-size: 14px; font-weight: 550;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, filter 0.15s;
}
button:hover, .btn:hover { border-color: var(--muted); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: default; transform: none; }
.primary { background: var(--accent) !important; border-color: var(--accent) !important; color: var(--accent-text) !important; }
.primary:hover { filter: brightness(1.08); }
button.big { height: 44px; padding: 0 26px; font-size: 15px; }
button.ghost { border-color: transparent; background: transparent; height: 32px; padding: 0 10px; }
button.ghost:hover { background: var(--surface-2); }
.danger-btn { color: var(--danger); }
.danger-btn:hover { border-color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
}
input, select { height: 40px; padding: 0 12px; }
select { height: 36px; padding: 0 8px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.inline { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 20px; animation: rise 0.2s ease-out; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }

/* ---------- login ---------- */
.login { max-width: 410px; margin: 8vh auto 0; padding: 32px; }
.login p { margin: 8px 0 22px; font-size: 14px; }
.login form { display: grid; gap: 14px; }
.login label { display: grid; gap: 6px; font-size: 13px; font-weight: 550; }
.login button { height: 42px; margin-top: 4px; }

/* ---------- pick (hero) ---------- */
.hero { text-align: center; padding: 4vh 0 0; }
.hero > p { max-width: 560px; margin: 10px auto 26px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 56px 20px; border: 2px dashed var(--line); border-radius: 22px; background: var(--surface);
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.dz-icon { width: 44px; height: 44px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dz-title { font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }
.dz-btn { margin-top: 4px; pointer-events: none; }
.dz-hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; max-width: 520px; }

/* ---------- stage ---------- */
.stage-list, .result-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.scard { position: relative; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); animation: rise 0.18s ease-out; }
.scard.ok { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); }
.scard.err { border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); }
.scard-img { position: relative; aspect-ratio: 1; background: var(--surface-2); }
.scard-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.scard-progress { position: absolute; left: 8px; right: 8px; bottom: 8px; height: 5px; border-radius: 5px; background: rgba(0, 0, 0, 0.35); overflow: hidden; opacity: 0; transition: opacity 0.2s; }
.scard.busy .scard-progress { opacity: 1; }
.scard-fill { height: 100%; width: 0; background: #fff; transition: width 0.15s; }
.scard-meta { padding: 7px 9px 9px; display: grid; }
.scard-name { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scard-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scard.err .scard-sub { color: var(--danger); }
.scard-x {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; padding: 0; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55); border: 0; color: #fff;
}
.scard-x svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.scard.busy .scard-x, .scard.ok .scard-x { display: none; }
.noprev { width: 100%; height: 100%; display: grid; place-items: center; font-weight: 700; font-size: 18px; color: var(--muted); }

.stage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; }

/* ---------- result / embed ---------- */
.embed { display: grid; gap: 10px; margin-bottom: 18px; }
.embed textarea {
  width: 100%; resize: vertical; padding: 10px 12px; min-height: 48px;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2);
}
.embed-actions { display: flex; justify-content: flex-end; }
.rcard { display: flex; gap: 10px; align-items: center; min-width: 0; }
.result-list { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.rcard-img { flex: none; width: 56px; height: 56px; border-radius: 9px; overflow: hidden; background: var(--surface-2); }
.rcard-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rcard-meta { display: grid; min-width: 0; font-size: 13px; }
.rcard-name { font-weight: 550; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.rcard-name:hover { color: var(--accent); }

/* ---------- my images ---------- */
.my-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 14px; }
.my-tools { display: flex; gap: 8px; align-items: center; }
.my-tools select { height: 38px; }
.space { display: grid; gap: 6px; margin-bottom: 16px; }
.space-bar { height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.space-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.space-fill.low { background: var(--danger); }
/* floating, so toggling selection never shifts the grid under the cursor */
.selbar {
  position: fixed; left: 0; right: 0; bottom: 16px; z-index: 15; margin-inline: auto;
  width: fit-content; max-width: calc(100vw - 32px); justify-content: center;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 10px 8px 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); font-size: 14px; font-weight: 550;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  animation: rise 0.18s ease-out;
}
#view-my { padding-bottom: 72px; }
.empty { margin: 40px 0; text-align: center; }
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.tile { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.tile-img { position: relative; display: block; aspect-ratio: 1; background: var(--surface-2); }
.tile-img img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.25s; }
.tile:hover .tile-img img { transform: scale(1.03); }
.badge {
  position: absolute; left: 8px; bottom: 8px; padding: 1px 7px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 11px; font-weight: 650;
}
.badge-time { left: auto; right: 8px; }
.tile-meta { padding: 8px 10px 10px; display: grid; gap: 1px; }
.tile-name { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-actions { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; opacity: 0; transition: opacity 0.15s; }
.tile:hover .tile-actions, .tile:focus-within .tile-actions { opacity: 1; }
@media (hover: none) { .tile-actions { opacity: 1; } }
.icon-btn {
  width: 32px; height: 32px; padding: 0; border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(6px);
}
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }
.tile-check {
  position: absolute; top: 8px; left: 8px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0, 0, 0, 0.3); display: none; place-items: center; color: #fff;
}
.tile-check svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.grid.selecting .tile-check { display: grid; }
.grid.selecting .tile-actions { display: none; }
.grid.selecting .tile-img { cursor: pointer; }
.tile.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.tile.selected .tile-check { background: var(--accent); border-color: var(--accent); }
.tile.selected .tile-check svg { opacity: 1; }
.more { display: flex; justify-content: center; margin-top: 20px; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(4px);
  pointer-events: none;
}
.overlay-box {
  padding: 48px 64px; border: 2px dashed var(--accent); border-radius: 22px;
  background: var(--accent-soft); color: var(--accent); font-size: 20px; font-weight: 650; text-align: center;
}
.toast {
  position: fixed; left: 50%; bottom: 84px; z-index: 20; transform: translate(-50%, 16px);
  padding: 10px 18px; border-radius: 10px; background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 550; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.offscreen { position: fixed; left: -9999px; }

/* ---------- viewer page ---------- */
.stage-img { margin: 0; display: grid; place-items: center; padding: 8px 0 4px; }
.stage-img img {
  max-width: 100%; max-height: 74vh; width: auto; height: auto; display: block;
  border-radius: 10px; box-shadow: var(--shadow);
  background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 20px 20px;
}
.info { margin-top: 18px; padding: 16px 18px; display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; }
.info-main { min-width: 0; }
.info-name { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info-sub { font-size: 13px; margin: 3px 0 0; }
.info-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.embed-card { margin-top: 12px; padding: 16px 18px; }
.notfound { max-width: 440px; margin: 10vh auto 0; padding: 32px; text-align: center; }
.notfound p { margin: 8px 0 0; }

@keyframes rise { from { opacity: 0; transform: translateY(4px); } }

@media (max-width: 640px) {
  .top { gap: 10px; flex-wrap: wrap; }
  .nav { order: 3; width: 100%; }
  h1 { font-size: 22px; }
  .dropzone { padding: 40px 16px; }
  .panel { padding: 14px; }
  .stage-list { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stage-actions .spacer { display: none; }
  .stage-actions > * { flex: 1 1 auto; }
  .info-actions { width: 100%; }
  .info-actions > * { flex: 1; }
  .my-head { align-items: flex-start; }
}

/* ---------- documents ---------- */
.file-icon {
  width: 100%; height: 100%; display: grid; place-items: center;
  background: var(--surface-2);
}
.file-icon span {
  display: grid; place-items: center; width: 34px; height: 42px; border-radius: 4px 10px 4px 4px;
  background: var(--surface); border: 1.5px solid var(--line); color: var(--accent);
  font: 700 9px/1 ui-sans-serif, system-ui, sans-serif; text-transform: uppercase; letter-spacing: 0.02em;
}
.file-icon-lg span { width: 56px; height: 70px; font-size: 13px; border-radius: 6px 16px 6px 6px; }
.filecard { padding: 20px; display: grid; gap: 14px; justify-items: center; }
.filecard .file-icon { background: transparent; height: auto; padding: 12px 0 4px; }
.preview {
  width: 100%; max-height: 60vh; overflow: auto; margin: 0; padding: 14px 16px; border-radius: 10px;
  background: var(--surface-2); font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-word; tab-size: 4;
}

/* All / Images / Files */
.filter {
  display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 14px; border-radius: 11px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.filter button { height: 30px; padding: 0 14px; border: 0; background: transparent; color: var(--muted); border-radius: 8px; }
.filter button:hover { color: var(--text); }
.filter button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.tile-img, .rcard-img { text-decoration: none; }
@media (max-width: 640px) {
  .my-head { flex-wrap: wrap; }
  .my-tools { width: 100%; }
  .my-tools select { flex: 1; min-width: 0; }
}

/* ---------- upload settings menu (header) ---------- */
.auto { position: relative; margin-left: auto; }
.auto + .userbox { margin-left: 4px; }
.auto-btn { height: 34px; padding: 0 10px 0 12px; font-size: 13px; gap: 8px; }
.auto-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: 0.6; }
.auto.on .auto-dot { background: var(--ok); opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.chev { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.15s; }
.auto-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.auto-menu {
  position: absolute; left: 0; top: calc(100% + 8px); z-index: 30;
  width: 320px; max-width: calc(100vw - 32px); padding: 14px;
  display: grid; gap: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
  animation: rise 0.15s ease-out;
}
.switch-row { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch-row > span:first-child { flex: 1; display: grid; gap: 2px; }
.switch-title { font-weight: 600; font-size: 14px; }
.switch-sub { font-size: 12px; color: var(--muted); line-height: 1.35; }
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch {
  flex: none; width: 40px; height: 24px; border-radius: 12px; background: var(--surface-2);
  border: 1px solid var(--line); position: relative; transition: background 0.15s, border-color 0.15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--muted); transition: transform 0.15s, background 0.15s;
}
.switch-row input:checked + .switch { background: var(--accent); border-color: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(16px); background: var(--accent-text); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu-group { border: 0; margin: 0; padding: 12px 0 0; border-top: 1px solid var(--line); display: grid; gap: 4px; min-width: 0; }
.menu-group legend { float: left; width: 100%; padding: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.menu-select { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.menu-select select { width: 100%; margin-top: 6px; text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 14px; color: var(--text); }
.radio-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.radio-row:hover { background: var(--surface-2); }
.radio-row input { accent-color: var(--accent); margin: 0; }
.link-btn {
  height: auto; padding: 0; border: 0; background: none; color: var(--muted);
  font-size: 13px; font-weight: 500; text-align: left; white-space: normal;
}
.link-btn:hover { color: var(--accent); border: 0; }
@media (max-width: 720px) {
  .auto-btn { padding: 0 8px; }
  #auto-label { font-size: 12px; }
  .auto-menu { position: fixed; left: 16px; right: 16px; top: 64px; width: auto; max-width: none; }
}
.stage-choices { display: contents; }
.stage-choices[hidden] { display: none !important; }
