:root {
  color-scheme: dark;
  --bg: #0a0f0d;
  --surface: #121916;
  --surface-2: #18211d;
  --border: #28342f;
  --text: #f0f6f3;
  --muted: #8d9d96;
  --accent: #59e39f;
  --accent-strong: #31c980;
  --accent-soft: #173226;
  --danger: #ff7379;
  --danger-soft: #331a1c;
  --warning: #f1bf61;
  --radius: 17px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; min-height: 100%; }
body {
  background:
    radial-gradient(circle at 85% -15%, #19392b 0, transparent 33%),
    radial-gradient(circle at -10% 90%, #16271f 0, transparent 27%),
    var(--bg);
  color: var(--text);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .42; }
h1, h2, p, dl, dd { margin: 0; }

.app-shell {
  width: min(1540px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 24px 24px;
}
.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--border);
}
.brand, .topbar-actions { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: #07140e;
  background: var(--accent);
  box-shadow: 0 0 32px #59e39f22;
}
.brand-mark svg { width: 27px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
h1 { font-size: 18px; letter-spacing: -.02em; }
.brand p { color: var(--muted); font-size: 12px; margin-top: 3px; }
.back-link, .text-link {
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}
.back-link:hover, .text-link:hover { color: var(--accent); }
.text-link.disabled { opacity: .4; pointer-events: none; }
.connection-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: #111714cc;
  font-size: 12px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.connection-badge.online { color: var(--accent); border-color: #59e39f44; }
.connection-badge.online .status-dot { background: var(--accent); box-shadow: 0 0 0 4px #59e39f1c; }
.connection-badge.connecting .status-dot { background: var(--warning); animation: pulse 1s infinite; }

main {
  display: grid;
  grid-template-rows: auto auto minmax(390px, 1fr) 250px;
  gap: 14px;
  padding-top: 16px;
}
.panel {
  min-width: 0;
  background: linear-gradient(145deg, #151d19, #101613);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 15px 50px #00000018;
}
.eyebrow {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: 9px;
  font-weight: 780;
  margin-bottom: 4px;
}
h2 { font-size: 18px; letter-spacing: -.02em; }
.hint { color: var(--muted); font-size: 11px; }

.connection-panel {
  display: grid;
  grid-template-columns: minmax(210px, .7fr) minmax(420px, 1.7fr) auto;
  align-items: end;
  gap: 12px;
  padding-block: 14px;
}
.connection-panel .hint { grid-column: 2 / 4; margin-top: -5px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}
.field small { font-weight: 500; }
input[type="text"], input[type="url"] {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 11px;
  color: var(--text);
  background: #0b110e;
  border: 1px solid #2d3b35;
  border-radius: 9px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--accent-strong); box-shadow: 0 0 0 3px #59e39f12; }

.button {
  min-height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text);
  background: #25332e;
  border: 1px solid #35463f;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 750;
}
.button:active { transform: translateY(1px); }
.button.primary { color: #06110c; background: var(--accent); border-color: transparent; }
.button.primary:hover { background: #70e9ad; }
.button.danger { color: #ffdfe1; background: var(--danger-soft); border-color: #663035; }
.button.grow { flex: 1; }
.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 9px;
}
.icon-button:hover { color: var(--accent); }
.icon-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.storage-strip {
  display: grid;
  grid-template-columns: minmax(210px, .7fr) 1.7fr auto;
  gap: 18px;
  align-items: center;
  padding-block: 12px;
}
.storage-intro strong { display: block; font-size: 12px; color: #cbd6d1; }
.storage-facts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.storage-facts div { padding: 8px 12px; }
.storage-facts div + div { border-left: 1px solid var(--border); }
.storage-facts dt { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .09em; }
.storage-facts dd { margin-top: 3px; font-size: 12px; font-weight: 700; }

.workspace-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(480px, .92fr) minmax(560px, 1.08fr);
  gap: 14px;
}
.upload-panel, .catalog-panel {
  min-height: 0;
  overflow: hidden;
}
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.section-heading.compact { margin-bottom: 10px; }
.state-pill, .count-badge {
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: #101613;
  font-size: 10px;
  font-weight: 700;
}
.state-pill.uploading { color: var(--warning); border-color: #f1bf6144; }
.state-pill.success { color: var(--accent); border-color: #59e39f44; }
.state-pill.error { color: var(--danger); border-color: #ff737944; }
.count-badge { min-width: 28px; text-align: center; color: var(--accent); }
.source-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  margin-bottom: 12px;
  background: #0b110e;
  border: 1px solid var(--border);
  border-radius: 9px;
}
.source-tab {
  height: 33px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}
.source-tab.active { color: var(--text); background: #25342e; }
.source-panel { margin-bottom: 12px; }
.source-panel.hidden, .hidden { display: none !important; }
.file-picker {
  height: 62px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr 1fr;
  column-gap: 12px;
  align-items: center;
  padding: 10px 13px;
  color: var(--muted);
  background: #0b110e;
  border: 1px dashed #3a4b44;
  border-radius: 10px;
  cursor: pointer;
}
.file-picker:hover { border-color: var(--accent-strong); }
.file-picker input { position: absolute; opacity: 0; pointer-events: none; }
.file-picker-title {
  grid-row: 1 / 3;
  padding: 8px 12px;
  color: #07140e;
  background: var(--accent);
  border-radius: 7px;
  font-size: 11px;
  font-weight: 800;
}
.file-picker-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.metadata-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.checksum-field { margin-bottom: 11px; }
.progress-wrap { margin-top: 4px; }
.progress-track { height: 7px; overflow: hidden; background: #0a100d; border: 1px solid #26332e; border-radius: 999px; }
.progress-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--accent-strong), var(--accent)); transition: width .15s; }
.progress-meta { display: flex; justify-content: space-between; margin-top: 5px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.upload-actions { display: flex; gap: 9px; margin-top: 12px; }

.catalog-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.catalog-head, .catalog-row {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) 90px 160px;
  gap: 10px;
  align-items: center;
}
.catalog-head {
  padding: 0 10px 7px;
  color: #66756f;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.catalog-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 6px;
  padding-right: 3px;
}
.catalog-row {
  padding: 9px 10px;
  background: #0b110e;
  border: 1px solid #202b27;
  border-radius: 9px;
}
.content-name { min-width: 0; }
.content-name strong, .content-name small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content-name strong { font-size: 12px; }
.content-name small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.content-size { color: #c2cdc8; font-size: 11px; font-variant-numeric: tabular-nums; }
.catalog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mini-button {
  height: 30px;
  color: #cbd5d1;
  background: #26352f;
  border: 1px solid #34463e;
  border-radius: 7px;
  font-size: 10px;
  font-weight: 750;
}
.mini-button:hover { color: var(--accent); }
.mini-button.delete:hover { color: var(--danger); border-color: #613035; }
.empty-state { align-self: center; padding: 30px; color: var(--muted); font-size: 11px; text-align: center; }

.bottom-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 1.3fr .7fr;
  gap: 14px;
}
.player-panel, .activity-panel { min-height: 0; overflow: hidden; }
.player-panel { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.player-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #080d0b;
  border: 1px solid #202b27;
  border-radius: 10px;
}
.player-stage.empty { padding: 20px; }
.player-stage p { max-width: 540px; color: var(--muted); font-size: 11px; text-align: center; line-height: 1.5; }
.media-player, .image-player { width: 100%; height: 100%; object-fit: contain; background: #000; }
.audio-player { width: min(620px, calc(100% - 32px)); }
.player-status { margin-top: 6px; color: var(--muted); font-size: 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-panel { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.activity-log { min-height: 0; overflow: auto; list-style: none; padding: 0; margin: 0; display: grid; align-content: start; gap: 5px; }
.activity-item { display: grid; grid-template-columns: 58px 76px 1fr; gap: 8px; padding: 7px 8px; background: #0b110e; border-radius: 7px; font-size: 10px; }
.activity-time { color: #607069; font-variant-numeric: tabular-nums; }
.activity-method { color: var(--accent); font-family: monospace; overflow: hidden; text-overflow: ellipsis; }
.activity-message { color: #bdc8c3; overflow-wrap: anywhere; }
.activity-item.error .activity-method, .activity-item.error .activity-message { color: var(--danger); }
.empty-log { color: var(--muted); font-size: 11px; text-align: center; padding: 24px; }
.text-button { color: var(--muted); border: 0; background: transparent; padding: 4px; font-size: 11px; }
.text-button:hover { color: var(--accent); }
.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  color: #111815;
  background: #edf6f2;
  border-radius: 10px;
  box-shadow: 0 10px 40px #0008;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { color: #501216; background: #ffdade; }

@keyframes pulse { 50% { opacity: .35; } }

@media (min-width: 701px) and (max-height: 800px) {
  .app-shell { padding-bottom: 12px; }
  .topbar { min-height: 60px; }
  .brand-mark { width: 36px; height: 36px; }
  main { grid-template-rows: auto auto minmax(330px, 1fr) 180px; gap: 9px; padding-top: 9px; }
  .panel { padding: 12px 14px; }
  .connection-panel, .storage-strip { padding-block: 9px; }
  .connection-panel .hint { display: none; }
  .section-heading { margin-bottom: 9px; }
  .source-tabs { margin-bottom: 8px; }
  .source-panel { margin-bottom: 8px; }
  .file-picker { height: 52px; padding-block: 7px; }
  input[type="text"], input[type="url"] { height: 35px; }
  .metadata-grid, .checksum-field { margin-bottom: 7px; }
  .upload-actions { margin-top: 8px; }
  .button { min-height: 35px; }
}

@media (max-width: 1050px) {
  body { overflow: auto; }
  main { grid-template-rows: auto; }
  .workspace-grid, .bottom-grid { grid-template-columns: 1fr; }
  .workspace-grid { min-height: auto; }
  .upload-panel { overflow: visible; }
  .catalog-panel { min-height: 420px; }
  .player-panel, .activity-panel { min-height: 300px; }
}

@media (max-width: 700px) {
  .app-shell { padding: 0 12px 24px; }
  .topbar { min-height: 70px; }
  .brand p, .back-link { display: none; }
  .connection-badge { padding: 7px 9px; }
  .connection-panel, .storage-strip { grid-template-columns: 1fr; align-items: stretch; }
  .connection-panel .hint { grid-column: auto; margin-top: 0; }
  .storage-facts { grid-template-columns: 1fr 1fr; }
  .storage-facts div:nth-child(3) { border-left: 0; border-top: 1px solid var(--border); }
  .storage-facts div:nth-child(4) { border-top: 1px solid var(--border); }
  .metadata-grid { grid-template-columns: 1fr; }
  .catalog-head { display: none; }
  .catalog-row { grid-template-columns: 1fr 80px; }
  .catalog-actions { grid-column: 1 / -1; }
}
