:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #141414;
  --muted: #74706a;
  --line: #e3e0da;
  --accent: #ff4d1f;
  --accent-ink: #ffffff;
  --dot: #d8d4cc;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 24px rgba(0,0,0,.06);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --panel: #1b1b1a;
    --ink: #f1efea;
    --muted: #9a958c;
    --line: #2e2d2a;
    --dot: #2b2a27;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); }
a { color: inherit; }
button { font: inherit; color: inherit; }
kbd {
  font: 600 13px var(--mono); display: inline-grid; place-items: center;
  min-width: 34px; height: 34px; padding: 0 8px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line); border-bottom-width: 3px;
}

.logo { font: 800 20px/1 var(--mono); text-decoration: none; letter-spacing: -.02em; }
.logo span { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 9px 16px; border-radius: 999px; border: 1px solid var(--ink);
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 14px;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink); opacity: 1; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0; text-decoration: underline; }

/* ---------------- home ---------------- */
.home .wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px 16px 72px; }
.zone { display: grid; place-items: center; padding: 48px; border-radius: 24px; cursor: pointer; transition: background .15s; }
.drag .zone, .drag .stage { background: var(--panel); border-radius: 24px; }
.keys { display: flex; gap: 10px; }
.keys kbd { min-width: 64px; height: 64px; font-size: 26px; border-radius: 14px; }

.stage { width: 100%; display: grid; place-items: center; animation: pop .2s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } }
.stage .cell { display: grid; place-items: center; max-width: 100%; }
.pv-media { display: block; max-width: 100%; max-height: calc(100dvh - 120px); object-fit: contain; border-radius: 8px; }
.pv-text {
  margin: 0; max-width: min(820px, 100%); max-height: calc(100dvh - 120px); overflow: auto;
  padding: 20px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  font: 14px/1.6 var(--mono); white-space: pre-wrap; word-break: break-word; text-align: left;
}
.pv-link { font: 600 clamp(16px, 3vw, 26px) var(--mono); word-break: break-all; text-align: center; }
.pv-audio { width: min(480px, 100%); }
.pv-pdf { display: block; width: min(900px, calc(100vw - 32px)); height: calc(100dvh - 120px); border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.stage.grid .pv-pdf { width: 100%; height: 360px; }
.pv-file { display: grid; gap: 4px; place-items: center; text-align: center; color: var(--muted); font: 13px var(--mono); }
.pv-file b { font-size: 28px; color: var(--ink); text-transform: uppercase; }

.stage.grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; place-items: start stretch; max-width: 1200px; }
.stage.grid .cell { display: block; }
.stage.grid .pv-media { width: 100%; max-height: 360px; object-fit: cover; }
.stage.grid .pv-text { max-height: 360px; width: 100%; }
.stage.grid .pv-file, .stage.grid .pv-link { display: grid; width: 100%; min-height: 160px; align-content: center; padding: 32px 16px; background: var(--panel); border-radius: 12px; }

.foot {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 16px;
  padding: 14px max(16px, env(safe-area-inset-left)) calc(14px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line); font: 15px var(--mono);
}
.foot .url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; text-align: center; }
.foot .url:hover { text-decoration: underline; }
.foot .prog { position: absolute; left: 0; right: 0; top: -1px; height: 4px; background: var(--line); }
.foot .prog i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }
.foot .pct { color: var(--muted); font-size: 13px; min-width: 4ch; text-align: right; font-variant-numeric: tabular-nums; }
.foot.busy .url { opacity: .6; }
.home .pending { font: 15px var(--mono); color: var(--muted); }
.foot .copy { background: none; border: 0; padding: 0; cursor: pointer; color: var(--muted); font: inherit; font-size: 13px; }
.foot .copy:hover { color: var(--ink); }
.foot.err .url { color: var(--accent); }

/* ---------------- shared bar ---------------- */
.bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.bar .meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.bar .grow { flex: 1; }

/* ---------------- text page ---------------- */
.text {
  margin: 0; padding: 24px 16px 80px; font: 14px/1.6 var(--mono); tab-size: 4;
  max-width: 1000px; margin-inline: auto; overflow-x: auto;
}
.text.wrapped { white-space: pre-wrap; word-break: break-word; }

/* ---------------- canvas page ---------------- */
.canvaspage { overflow: hidden; height: 100vh; height: 100dvh; }
.bar.floating {
  position: fixed; top: 12px; left: 12px; right: 12px; border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); padding: 8px 10px 8px 16px;
}
.bar .title {
  font: 600 15px var(--sans); border: 0; background: transparent; color: var(--ink); outline: none;
  min-width: 60px; max-width: 360px; flex: 0 1 auto; padding: 4px 6px; border-radius: 6px;
}
.bar .title:not([readonly]):hover, .bar .title:not([readonly]):focus { background: var(--bg); }
.bar .title[readonly] { pointer-events: none; }

.viewport {
  position: fixed; inset: 0; overflow: hidden; cursor: grab; touch-action: none;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.2px, transparent 1.2px);
  background-size: 24px 24px;
}
.viewport.panning { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

.card {
  position: absolute; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden; user-select: none;
}
.card.media { background: #000; border-color: transparent; }
.card img, .card video { display: block; width: 100%; height: auto; pointer-events: none; }
.card video { pointer-events: auto; }
.card img { cursor: zoom-in; pointer-events: auto; -webkit-user-drag: none; }
.card .cap {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px);
  font: 600 11px var(--mono); padding: 3px 7px; border-radius: 6px;
  background: rgba(0,0,0,.6); color: #fff; opacity: 0; transition: opacity .15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none;
}
.card:hover .cap { opacity: 1; }
.card .txt {
  margin: 0; padding: 16px 18px; font: 13.5px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word;
  max-height: 520px; overflow: auto; user-select: text; cursor: text;
}
.card.link a, .card a.filebox {
  display: flex; gap: 12px; align-items: center; padding: 16px 18px; text-decoration: none;
}
.card .fav {
  width: 36px; height: 36px; border-radius: 9px; background: var(--bg); flex: none;
  display: grid; place-items: center; overflow: hidden; font: 700 11px var(--mono); color: var(--muted);
  text-transform: uppercase;
}
.card .fav img { width: 20px; height: 20px; cursor: inherit; }
.card .lk { min-width: 0; }
.card .lk b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .lk span { display: block; font: 12px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card iframe.pdf { display: block; width: 100%; height: 640px; border: 0; border-top: 1px solid var(--line); background: #fff; }
.card audio { display: block; width: calc(100% - 24px); margin: 0 12px 14px; }

.editing .card { cursor: move; }
.editing .card:hover { outline: 2px solid var(--accent); outline-offset: 2px; }
.card .handle {
  display: none; position: absolute; right: 0; bottom: 0; width: 22px; height: 22px; cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--accent) 50%); z-index: 2;
}
.card .del {
  display: none; position: absolute; top: 6px; right: 6px; z-index: 2; width: 26px; height: 26px;
  border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; font-size: 15px; line-height: 1;
}
.editing .card:hover .handle, .editing .card:hover .del { display: block; }
.card.ghost { opacity: .5; }

.hint {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); font-size: 13px; padding: 8px 14px; border-radius: 999px;
  box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center;
}
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 50; display: grid; place-items: center;
  cursor: zoom-out; padding: 20px;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.droptarget .viewport { box-shadow: inset 0 0 0 4px var(--accent); }

@media (max-width: 560px) {
  .bar.floating { top: 8px; left: 8px; right: 8px; gap: 8px; }
  .bar .title { max-width: 120px; }
  .bar #count, .bar #status { display: none; }
}
