:root {
  --bg: #f5f6f8; --panel: #fff; --panel2: #eef0f4; --text: #14171c; --muted: #6a7280;
  --line: #e0e3e9; --accent: #3d6bf0; --accent-t: #fff; --danger: #d4392f;
  --nav-h: 58px; --rail-w: 76px;
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left); --sar: env(safe-area-inset-right);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --panel: #181b21; --panel2: #20242c; --text: #eceef2; --muted: #8b93a3; --line: #272c35; --accent: #6a8cff; --accent-t: #0b1020; --danger: #ff6b60; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Mobile first: content on top, tab bar at the bottom */
#shell { display: flex; flex-direction: column; height: 100dvh; }
#view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 16px) 24px calc(var(--sal) + 16px); }
#nav { order: 2; display: flex; background: var(--panel); border-top: 1px solid var(--line);
  padding: 0 var(--sar) var(--sab) var(--sal); }
#nav a { flex: 1; min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); }
#nav a.on { color: var(--accent); }
.brand { display: none; }

h1 { font-size: 28px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 10px; }
.sub { color: var(--muted); margin: 0 0 8px; }
.wrap { max-width: 1100px; margin: 0 auto; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px;
  display: flex; flex-direction: column; gap: 10px; min-height: 108px; text-align: left; }
.tile:active, .row:active { background: var(--panel2); }
.tile .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; }
.tile b { font-weight: 600; }
.tile small { color: var(--muted); font-size: 13px; word-break: break-all; }

.list { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 56px; width: 100%;
  background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .grow b, .row .grow small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row small { color: var(--muted); }
.row .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; flex: none; }
.chev { color: var(--muted); width: 18px; height: 18px; }

.btn { background: var(--accent); color: var(--accent-t); border: 0; border-radius: 12px; padding: 0 16px;
  min-height: 44px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.btn.ghost { background: var(--panel2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.bar { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }

[hidden] { display: none !important; }
input[type=text], input[type=password], input[type=url], input[type=email] { width: 100%; min-height: 48px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 16px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; max-width: 460px; }
.err { color: var(--danger); margin-top: 10px; }

.crumbs { display: flex; gap: 6px; align-items: center; overflow-x: auto; white-space: nowrap; margin: 8px 0 12px; scrollbar-width: none; }
.crumbs button { background: none; border: 0; padding: 6px 4px; color: var(--accent); min-height: 36px; }
.crumbs span { color: var(--muted); }
.empty { color: var(--muted); padding: 32px 16px; text-align: center; }

.frame { width: 100%; height: calc(100dvh - var(--nav-h) - var(--sat) - var(--sab) - 150px); min-height: 360px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }

/* Files: master/detail */
.files { display: block; }
.files .libs { display: block; }
.files.open .libs { display: none; }
.files .main { display: none; }
.files.open .main { display: block; }
.backbtn { display: inline-flex; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--sab) + 16px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: .2s; max-width: 90vw; z-index: 10; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* Tablet / iPad (incl. 12.9" portrait 1024 + landscape 1366) and desktop: side rail */
@media (min-width: 768px) {
  #shell { flex-direction: row; }
  #nav { order: 0; flex-direction: column; width: var(--rail-w); border-top: 0; border-right: 1px solid var(--line);
    padding: calc(var(--sat) + 12px) 0 12px var(--sal); gap: 4px; }
  #nav a { flex: none; min-height: 64px; }
  .brand { display: block; width: 36px; height: 36px; margin: 4px auto 12px; }
  .brand img { width: 36px; height: 36px; border-radius: 10px; display: block; }
  .brand span { display: none; }
  #nav .spacer { flex: 1; }
  #view { padding: calc(var(--sat) + 28px) 32px 40px; }
  .grid { grid-template-columns: repeat(3, 1fr); gap: 16px; }
  #toast { bottom: 24px; }
  .frame { height: calc(100dvh - 190px); }
}
@media (min-width: 1024px) {
  :root { --rail-w: 220px; }
  #nav { padding: calc(var(--sat) + 16px) 12px 16px; }
  #nav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 14px; border-radius: 12px; font-size: 15px; min-height: 48px; }
  #nav a.on { background: var(--panel2); }
  .brand { display: flex; align-items: center; gap: 10px; width: auto; height: auto; margin: 0 0 16px 6px; font-weight: 700; font-size: 18px; }
  .brand span { display: inline; }
  .brand img { width: 32px; height: 32px; border-radius: 9px; }
  .grid { grid-template-columns: repeat(4, 1fr); }
  .files { display: grid; grid-template-columns: 300px 1fr; gap: 24px; align-items: start; }
  .files .libs, .files.open .libs, .files .main, .files.open .main { display: block; }
  .backbtn { display: none; }
}
@media (hover: hover) { .tile:hover, .row:hover { background: var(--panel2); } }

/* Bottom sheet (mobile) / centered dialog (tablet+) */
#sheet { position: fixed; inset: 0; z-index: 20; }
#sheet .scrim { position: absolute; inset: 0; background: rgba(0,0,0,.5); opacity: 0; transition: opacity .2s; }
#sheet .sheet { position: absolute; left: 0; right: 0; bottom: 0; background: var(--panel); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(var(--sab) + 16px); transform: translateY(100%); transition: transform .22s ease; max-height: 85dvh; overflow-y: auto; }
#sheet.on .scrim { opacity: 1; }
#sheet.on .sheet { transform: none; }
#sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
#sheet h3 { margin: 0 0 4px; font-size: 18px; word-break: break-all; }
#sheet .list { background: var(--panel2); border: 0; margin-top: 8px; }
#sheet .row.dng { color: var(--danger); }
@media (min-width: 768px) {
  #sheet .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 420px; border-radius: 20px;
    padding: 20px; transform: translate(-50%, -46%); opacity: 0; transition: .18s; }
  #sheet.on .sheet { transform: translate(-50%, -50%); opacity: 1; }
  #sheet .grip { display: none; }
}

/* Full-bleed editor: hide the tab bar/rail so the editor gets the screen */
body.editing #nav { display: none; }
body.editing #view { padding: 0; display: flex; flex-direction: column; }
.edbar { display: flex; align-items: center; gap: 12px; padding: calc(var(--sat) + 8px) calc(var(--sar) + 12px) 8px calc(var(--sal) + 12px); background: var(--panel); border-bottom: 1px solid var(--line); }
.edbar b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edwrap { flex: 1; min-height: 0; position: relative; }
.edwrap iframe, .edwrap #oo { width: 100%; height: 100%; border: 0; }

/* Music */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.seg { display: flex; gap: 6px; margin: 12px 0; overflow-x: auto; }
.seg a { padding: 8px 16px; border-radius: 999px; background: var(--panel2); color: var(--muted); white-space: nowrap; min-height: 40px; display: flex; align-items: center; }
.seg a.on { background: var(--accent); color: var(--accent-t); font-weight: 600; }
.agrid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.acard { display: block; min-width: 0; }
.acard .art { width: 100%; aspect-ratio: 1; border-radius: 12px; background: var(--panel2); object-fit: cover; display: block; }
.acard.round .art { border-radius: 50%; }
.acard b, .acard small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 6px; }
.acard small { color: var(--muted); margin-top: 0; font-size: 13px; }
.mhead { display: flex; gap: 16px; align-items: flex-end; margin-bottom: 8px; }
.mhead .art { width: 38vw; max-width: 200px; aspect-ratio: 1; border-radius: 14px; background: var(--panel2); object-fit: cover; flex: none; }
.mhead h1 { font-size: 24px; word-break: break-word; }
.num { width: 28px; text-align: right; color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.row.playing b { color: var(--accent); }
input[type=search] { width: 100%; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 16px; }

#player { background: var(--panel); border-top: 1px solid var(--line); }
#player[hidden] { display: none; }
.mini { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px calc(var(--sal) + 12px); position: relative; }
.mini .art { width: 44px; height: 44px; border-radius: 8px; background: var(--panel2); object-fit: cover; flex: none; }
.mini .meta { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; }
.mini .meta b, .mini .meta small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini .meta small { color: var(--muted); }
.ibtn { background: none; border: 0; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; }
.ibtn:active { background: var(--panel2); }
.ibtn.big { width: 64px; height: 64px; background: var(--accent); color: var(--accent-t); }
.ibtn.big svg { width: 30px; height: 30px; }
.mini .bar2 { position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--line); }
.mini .bar2 i { display: block; height: 100%; background: var(--accent); width: 0; }
.np { text-align: center; }
.np .art { width: min(72vw, 300px); aspect-ratio: 1; border-radius: 16px; object-fit: cover; background: var(--panel2); margin: 8px auto 16px; display: block; }
.np input[type=range] { width: 100%; accent-color: var(--accent); }
.np .times { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.np .ctl { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 8px; }

/* File rows with an actions button */
.row.it { padding: 4px 4px 4px 16px; }
.row.it .rmain { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; background: none; border: 0; padding: 8px 0; text-align: left; min-height: 48px; }
.row.it .rmain .grow b, .row.it .rmain .grow small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sheet .sheet.wide { max-height: 92dvh; }
@media (min-width: 768px) { #sheet .sheet.wide { width: min(720px, 92vw); } }
#sheet input[readonly] { margin-top: 8px; }

.searchbar { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px; margin: 12px 0 4px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.card2 { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.card2 .art { object-fit: cover; }
.row .art { object-fit: cover; flex: none; background: var(--panel2); }

.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }

/* Editor inside the Office tab: keep the nav, drop the page padding so the editor fills the space */
body.inedit #view { padding: 0; display: flex; flex-direction: column; }

/* Audiobooks frame lives outside #view so it keeps playing when you change tabs */
#audiowrap.off { position: fixed; left: -9999px; top: 0; width: 360px; height: 480px; overflow: hidden; }
#audiowrap.on { flex: 1; min-height: 0; padding: 0 calc(var(--sar) + 16px) 16px calc(var(--sal) + 16px); }
#audiowrap iframe { width: 100%; height: 100%; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
body.onaudio #view { flex: none; overflow: visible; padding-bottom: 8px; }
@media (min-width: 768px) { #audiowrap.on { padding-right: 32px; padding-left: 32px; padding-bottom: 24px; } }

/* Month calendar */
.mhdr { display: flex; align-items: center; gap: 6px; margin: 4px 0 10px; }
.cgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.cgrid.wk { background: none; border: 0; border-radius: 0; margin-bottom: 4px; gap: 0; }
.cgrid.wk span { text-align: center; color: var(--muted); font-size: 12px; padding: 4px 0; }
.cday { background: var(--panel); border: 0; padding: 4px 2px 6px; min-height: 54px; display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; min-width: 0; }
.cday.dim { background: var(--bg); color: var(--muted); }
.cday .dn { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; }
.cday.today .dn { background: var(--accent); color: var(--accent-t); font-weight: 700; }
.cday.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.cday .dots { display: flex; gap: 3px; min-height: 6px; }
.cday .dots i { width: 6px; height: 6px; border-radius: 50%; }
.cday .chips { display: none; }
@media (min-width: 768px) {
  .cday { min-height: 104px; align-items: stretch; padding: 6px; gap: 4px; }
  .cday .dn { align-self: flex-start; }
  .cday .dots { display: none; }
  .cday .chips { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .cday .chips em { font-style: normal; font-size: 12px; line-height: 1.25; padding: 1px 6px; border-radius: 5px; border-left: 3px solid var(--c); background: var(--panel2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
  .cday .chips small { color: var(--muted); font-size: 11px; text-align: left; padding-left: 6px; }
}

select, textarea, input[type=date], input[type=datetime-local] { width: 100%; min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 16px; color: var(--text); }
textarea { padding: 12px 14px; resize: vertical; font-family: inherit; }
.chk { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 16px; margin: 14px 0 0; }
.chk input { width: 22px; height: 22px; }
.row input[type=checkbox] { width: 22px; height: 22px; }

/* Several kept-alive frames share #audiowrap; only the active one is shown (the others stay loaded, out of sight) */
#audiowrap iframe:not(.act) { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; }
