:root {
  --bg: #f2f4f3;
  --surface: #ffffff;
  --ink: #18211e;
  --muted: #5b6964;
  --line: #dce3e0;
  --hover: #e8eeeb;
  --accent: #0e7c66;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --led: #17b26a;
  --shadow: 0 10px 30px rgba(16, 32, 26, .14);
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --mono: "Cascadia Mono", Consolas, ui-monospace, "Roboto Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513;
    --surface: #161e1b;
    --ink: #e4ece8;
    --muted: #8fa19a;
    --line: #26312d;
    --hover: #1c2622;
    --accent: #39c29f;
    --accent-ink: #06221a;
    --danger: #f97066;
    --led: #3ee08f;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.quiet { background: transparent; border-color: transparent; }
.btn.quiet:hover { background: var(--hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn.wide { width: 100%; min-height: 44px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- sign in ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px 24px; box-shadow: var(--shadow);
}
.login-title { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 650; letter-spacing: -.01em; }
.login-sub { margin: 6px 0 22px; color: var(--muted); }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input {
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
#code { font-family: var(--mono); font-size: 20px; letter-spacing: .3em; }
.form-error { min-height: 1.4em; margin: 0 0 10px; color: var(--danger); font-size: 14px; }

/* ---------- layout ---------- */
.app { max-width: 1040px; margin: 0 auto; padding: 18px 20px 120px; }
.top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.crumbs { flex: 1 1 320px; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 4px; }
.crumbs a, .crumbs span { text-decoration: none; color: var(--muted); font-size: 15px; }
.crumbs a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.crumbs .sep { color: var(--line); padding: 0 2px; }
.crumbs .here { margin: 0; color: var(--ink); font-size: 24px; font-weight: 650; letter-spacing: -.01em; line-height: 1.2; overflow-wrap: anywhere; }

/* The one distinctive element: a hardware-style power indicator. */
.power {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 4px 4px 4px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface);
}
.led {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--led);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--led) 22%, transparent), 0 0 10px var(--led);
}
.power-label { font-size: 14px; color: var(--muted); }
.power .btn { min-height: 30px; border-radius: 999px; padding: 0 12px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.spacer { flex: 1; }

.main { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.list { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) 90px 150px 40px;
  align-items: center; gap: 10px; min-height: 48px; padding: 0 8px 0 14px;
  border-top: 1px solid var(--line); cursor: pointer; user-select: none;
}
.row:first-child { border-top: 0; }
.row:hover { background: var(--hover); }
.row .ico { width: 22px; height: 22px; color: var(--muted); }
.row.dir .ico { color: var(--accent); }
.row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .size, .row .date { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.row .size { text-align: right; }
.row .more { width: 36px; height: 36px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; }
.row .more:hover { background: var(--line); color: var(--ink); }
.row.trash { grid-template-columns: 28px minmax(0, 1fr) 150px auto; cursor: default; }
.row .orig { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .acts { display: flex; gap: 6px; }

.empty { margin: 0; padding: 48px 20px; text-align: center; color: var(--muted); }
.foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; color: var(--muted); font-size: 13px; }

/* ---------- menu ---------- */
.menu {
  position: fixed; z-index: 30; min-width: 180px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.menu button {
  display: block; width: 100%; text-align: left; padding: 9px 12px;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }
.menu button.danger { color: var(--danger); }

/* ---------- dialogs ---------- */
dialog { color: var(--ink); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(8, 14, 12, .45); }
.dlg { width: min(440px, calc(100% - 32px)); border-radius: 14px; padding: 22px; }
.dlg h2 { margin: 0 0 6px; font-size: 18px; }
.dlg p { margin: 0 0 12px; color: var(--muted); overflow-wrap: anywhere; }
.dlg input { width: 100%; min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); margin-bottom: 6px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.viewer { width: min(1100px, calc(100% - 24px)); height: min(860px, calc(100% - 24px)); max-width: none; max-height: none; padding: 0; border-radius: 14px; overflow: hidden; }
.viewer[open] { display: flex; flex-direction: column; }
.viewer-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--line); }
.viewer-head h2 { flex: 1; margin: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-state { color: var(--muted); font-size: 13px; }
.viewer-body { flex: 1; min-height: 0; display: grid; place-items: center; background: var(--bg); overflow: auto; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-body audio { width: min(520px, 90%); }
.viewer-body textarea {
  width: 100%; height: 100%; resize: none; border: 0; padding: 16px 18px;
  background: var(--surface); font: 14px/1.55 var(--mono); tab-size: 4;
}

/* ---------- uploads ---------- */
.drop {
  position: fixed; inset: 10px; z-index: 40; display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  font-size: 20px; font-weight: 600; pointer-events: none;
}
.uploads {
  position: fixed; right: 16px; bottom: 16px; z-index: 20; width: min(380px, calc(100% - 32px));
  max-height: 50vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.uploads-head { position: sticky; top: 0; display: flex; justify-content: space-between; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--line); font-weight: 600; }
.uploads ol { list-style: none; margin: 0; padding: 4px 0; }
.uploads li { padding: 8px 14px; }
.up-name { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.up-name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-pct { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.bar { height: 4px; margin-top: 6px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }
.uploads li.done .bar i { background: var(--led); }
.uploads li.failed .up-pct { color: var(--danger); }

/* ---------- toasts / asleep ---------- */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(440px, calc(100% - 32px)); }
.toast { padding: 11px 14px; border-radius: 10px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-size: 14px; }
.toast.err { background: var(--danger); color: #fff; }
.asleep { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; background: var(--bg); text-align: center; }
.asleep h1 { margin: 0 0 8px; font-size: 26px; }
.asleep p { margin: 0 auto; max-width: 42ch; color: var(--muted); }

@media (max-width: 680px) {
  .app { padding: 12px 12px 120px; }
  .row { grid-template-columns: 26px minmax(0, 1fr) 70px 40px; padding-left: 10px; }
  .row .date { display: none; }
  .row.trash { grid-template-columns: 26px minmax(0, 1fr) auto; }
  .row.trash .date { display: none; }
  .crumbs .here { font-size: 21px; }
  .toolbar .spacer { display: none; }
  .viewer { width: 100%; height: 100%; border-radius: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .bar i { transition: none; }
}
