:root {
    color-scheme: light dark;
    --radius: 1.25rem;
    --radius-sm: 0.75rem;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 14px 44px rgba(15, 23, 42, 0.08);
    --font: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  }

  @media (prefers-color-scheme: light) {
    :root {
      --danger-soft: rgba(220, 38, 38, 0.1);
      --bg: #f4f6f8;
      --bg-elevated: #ffffff;
      --fg: #0f172a;
      --muted: #64748b;
      --border: #e2e8f0;
      --border-strong: #cbd5e1;
      --accent: #2563eb;
      --accent-soft: rgba(37, 99, 235, 0.08);
      --accent-ring: rgba(37, 99, 235, 0.25);
      --zone-bg: #f8fafc;
      --success: #059669;
      --danger: #dc2626;
      --glow: radial-gradient(ellipse 120% 80% at 50% -40%, rgba(37, 99, 235, 0.09), transparent 55%);
      --btn-fg: #ffffff;
    }
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --danger-soft: rgba(248, 113, 113, 0.12);
      --bg: #0c0f14;
      --bg-elevated: #151a22;
      --fg: #f1f5f9;
      --muted: #94a3b8;
      --border: rgba(148, 163, 184, 0.18);
      --border-strong: rgba(148, 163, 184, 0.35);
      --accent: #60a5fa;
      --accent-soft: rgba(96, 165, 250, 0.12);
      --accent-ring: rgba(96, 165, 250, 0.35);
      --zone-bg: rgba(255, 255, 255, 0.03);
      --success: #34d399;
      --danger: #f87171;
      --glow: radial-gradient(ellipse 100% 70% at 50% -30%, rgba(96, 165, 250, 0.12), transparent 50%);
      --btn-fg: #0c0f14;
      --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 18px 48px rgba(0, 0, 0, 0.35);
    }
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }
  html, body { min-height: 100%; }
  body {
    font-family: var(--font);
    font-weight: 400;
    background: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    padding: clamp(1.25rem, 3vw, 2rem) clamp(1rem, 3vw, 2rem) clamp(2rem, 5vw, 3.5rem);
    -webkit-font-smoothing: antialiased;
  }
  body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: var(--glow);
    pointer-events: none;
    z-index: 0;
  }

  .wrap {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: min(96vw, 72rem);
    margin: 0 auto;
  }

  .card {
    background: var(--bg-elevated);
    border-radius: calc(var(--radius) + 0.35rem);
    padding: clamp(1.75rem, 4vw, 2.75rem);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    animation: rise 0.75s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    opacity: 0;
  }
  .card--narrow {
    max-width: 26rem;
    margin-left: auto;
    margin-right: auto;
  }
  @keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }

  header {
    text-align: center;
    margin-bottom: 1.75rem;
  }
  .eyebrow {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.65rem;
  }
  h1 {
    font-family: var(--font);
    font-weight: 600;
    font-size: clamp(1.65rem, 4.5vw, 2.1rem);
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
  }
  .sub {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 300;
    line-height: 1.55;
    max-width: 38rem;
    margin: 0 auto;
  }
  .card--narrow .sub {
    max-width: 22rem;
  }
  .sub a {
    color: var(--accent);
    font-weight: 500;
    text-decoration: none;
  }
  .sub a:hover { text-decoration: underline; text-underline-offset: 3px; }

  .form-row { margin-bottom: 1rem; text-align: left; }
  .form-row label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.4rem;
  }
  .form-row input {
    width: 100%;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    background: var(--bg);
    color: var(--fg);
  }
  .form-row input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
  }
  .btn {
    width: 100%;
    margin-top: 0.35rem;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 600;
    background: var(--accent);
    color: var(--btn-fg);
    cursor: pointer;
  }
  .btn:hover { filter: brightness(1.06); }
  .btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-ring);
  }
  .btn--inline {
    width: auto;
    margin-top: 0;
    display: inline-block;
    text-decoration: none;
    text-align: center;
    line-height: 1.2;
  }
  .btn--ghost {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--border-strong);
  }
  .btn--ghost:hover {
    background: var(--accent-soft);
    filter: none;
  }
  .btn--danger {
    background: var(--danger);
    color: var(--btn-fg);
  }
  .btn--danger:hover {
    filter: brightness(1.06);
  }
  .project-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
  }
  .project-list__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--zone-bg);
  }
  .project-list__name {
    font-weight: 500;
    word-break: break-all;
  }
  .project-list__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
  }
  .project-list__delete-form {
    display: inline;
    margin: 0;
  }
  .login-error {
    margin-top: 1rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--danger);
    text-align: center;
  }

  .upload-layout {
    display: grid;
    gap: clamp(1.35rem, 3.5vw, 2.25rem);
    align-items: stretch;
  }
  @media (min-width: 900px) {
    .upload-layout {
      grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
      gap: clamp(1.5rem, 3vw, 2.5rem);
    }
  }
  .upload-panel {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
  }
  .files-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 12rem;
    padding: 1.15rem 1.2rem 1rem;
    background: var(--zone-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }
  @media (min-width: 900px) {
    .files-panel {
      position: sticky;
      top: 1.25rem;
      align-self: start;
      max-height: calc(100vh - 2.75rem);
    }
  }
  .files-panel-head {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
  }
  .files-panel-head h2 {
    font-family: var(--font);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .page-head {
    margin-bottom: clamp(1.35rem, 3vw, 2rem);
    text-align: center;
  }
  @media (min-width: 900px) {
    .page-head h1 {
      font-size: clamp(1.85rem, 2.8vw, 2.45rem);
    }
  }

  #list:empty::after {
    content: "No files yet — uploads appear here.";
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.5;
    padding: 1.35rem 0.75rem;
    text-align: center;
    font-weight: 300;
  }

  #zone {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: clamp(2rem, 5vw, 3.25rem) clamp(1.25rem, 3vw, 2rem);
    text-align: center;
    min-height: clamp(10rem, 22vh, 14rem);
    cursor: pointer;
    background: var(--zone-bg);
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.15s;
    outline: none;
  }
  #zone:hover, #zone.focus {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 0 4px var(--accent-ring);
  }
  #zone.drag {
    border-style: solid;
    border-color: var(--accent);
    background: var(--accent-soft);
    transform: scale(1.01);
  }
  #zone p strong {
    display: block;
    font-family: var(--font);
    font-weight: 600;
    font-size: clamp(1.02rem, 2vw, 1.15rem);
    margin-bottom: 0.3rem;
    color: var(--fg);
  }
  #zone p span {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 300;
  }
  input[type="file"] {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
  }

  .status-wrap {
    margin-top: 1rem;
    min-height: 1.5rem;
    text-align: center;
  }
  .progress-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    padding: 0.35rem 0 0.15rem;
  }
  .progress-panel[hidden] {
    display: none !important;
  }
  .progress-ring {
    position: relative;
    width: 7.5rem;
    height: 7.5rem;
  }
  .progress-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
  }
  .progress-ring .ring-bg {
    fill: none;
    stroke: var(--border-strong);
    stroke-width: 5;
    opacity: 0.45;
  }
  .progress-ring .ring-fg {
    fill: none;
    stroke: var(--accent);
    stroke-width: 5;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.12s ease-out;
  }
  .progress-center {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font);
    font-variant-numeric: tabular-nums;
    line-height: 1;
  }
  #progress-pct {
    font-size: 1.65rem;
    font-weight: 600;
    color: var(--fg);
    letter-spacing: -0.03em;
  }
  .pct-suffix {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--muted);
    margin-left: 0.05em;
    align-self: flex-end;
    padding-bottom: 0.2em;
  }
  .progress-meta {
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
  }
  .progress-meta time {
    color: var(--fg);
    font-weight: 500;
  }
  #status {
    font-size: 0.82rem;
    font-weight: 400;
    color: var(--muted);
    margin: 0;
  }
  #status.err { color: var(--danger); font-weight: 500; }
  #status.ok { color: var(--success); font-weight: 500; }
  #status.loading { color: var(--muted); font-weight: 500; }

  #zone.busy {
    pointer-events: none;
    opacity: 0.65;
    cursor: wait;
  }

  #list {
    margin-top: 0;
    list-style: none;
    font-size: 0.86rem;
    border-top: none;
    padding-top: 0;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.4rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--muted);
  }
  #list li:last-child { margin-bottom: 0; }
  .file-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-shrink: 0;
  }
  #list a.dl-link {
    color: var(--accent);
    font-weight: 600;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-decoration: none;
    flex: 0 0 auto;
    padding: 0.35rem 0.65rem;
    border-radius: 0.45rem;
    background: var(--accent-soft);
    border: 1px solid transparent;
    white-space: nowrap;
  }
  #list a.dl-link:hover {
    border-color: var(--accent);
    text-decoration: none;
  }
  #list .del-link {
    font-family: var(--font);
    color: var(--danger);
    font-weight: 600;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 0.35rem 0.65rem;
    border-radius: 0.45rem;
    background: var(--danger-soft);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
  }
  #list .del-link:hover {
    border-color: var(--danger);
  }
  #list .del-link:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--danger-soft);
  }
  #list .del-link:disabled {
    opacity: 0.45;
    cursor: not-allowed;
  }
  #list .name {
    color: var(--fg);
    font-weight: 400;
    flex: 1;
    min-width: 0;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    border-bottom: 1px dotted transparent;
  }
  #list .name:hover {
    border-bottom-color: var(--accent);
    color: var(--accent);
  }
  #list .name-input {
    font-family: var(--font);
    font-size: inherit;
    font-weight: 400;
    color: var(--fg);
    max-width: none;
    flex: 1;
    min-width: 0;
    padding: 0.2rem 0.35rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--bg);
  }
  #list .name-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-ring);
  }

  .files-panel #list {
    margin-top: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
  }
  .files-panel #list::-webkit-scrollbar {
    width: 7px;
  }
  .files-panel #list::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 6px;
  }

  @media (min-width: 900px) {
    .progress-ring {
      width: 8.25rem;
      height: 8.25rem;
    }
    #progress-pct {
      font-size: 1.8rem;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .card { animation: none; opacity: 1; }
    #zone { transition: none; }
    .progress-ring .ring-fg { transition: none; }
  }

  body.app-has-sidebar {
    padding: 0;
  }
  .app-shell {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
    position: relative;
    z-index: 1;
  }
  .app-sidebar {
    width: 15rem;
    flex-shrink: 0;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    align-self: flex-start;
    min-height: 100vh;
    max-height: 100vh;
    padding: 1.15rem 0 1rem;
    box-shadow: 2px 0 12px rgba(15, 23, 42, 0.04);
  }
  @media (prefers-color-scheme: dark) {
    .app-sidebar {
      box-shadow: 2px 0 20px rgba(0, 0, 0, 0.25);
    }
  }
  .sidebar-brand {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0 1.15rem 1rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0 0.65rem;
    flex: 1;
    overflow-y: auto;
  }
  .nav-item {
    display: block;
    padding: 0.58rem 0.85rem;
    border-radius: var(--radius-sm);
    color: var(--muted);
    text-decoration: none;
    font-size: 0.86rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
  }
  .nav-item:hover {
    color: var(--fg);
    background: var(--zone-bg);
  }
  .nav-item.is-active {
    color: var(--accent);
    background: var(--accent-soft);
    font-weight: 600;
  }
  .sidebar-logout {
    display: block;
    margin-top: auto;
    padding: 1rem 1.15rem 0;
    border-top: 1px solid var(--border);
    color: var(--danger);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  .sidebar-logout:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
  }
  .app-main {
    flex: 1;
    min-width: 0;
    padding: clamp(0.85rem, 2.5vw, 1.65rem);
    overflow-x: hidden;
  }
  .settings-block {
    text-align: left;
    max-width: 36rem;
    margin: 0 auto 1.5rem;
  }
  .settings-block h2 {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.65rem;
  }
  .settings-block p, .settings-block li {
    font-size: 0.88rem;
    color: var(--muted);
    line-height: 1.55;
    font-weight: 300;
  }
  .settings-block ul { padding-left: 1.1rem; margin-top: 0.35rem; }
  .profile-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1rem;
    align-items: baseline;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--border);
    max-width: 28rem;
    margin: 0 auto;
    text-align: left;
  }
  .profile-row:last-of-type { border-bottom: none; }
  .profile-label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    min-width: 6rem;
  }
  .profile-value {
    font-size: 0.95rem;
    color: var(--fg);
    word-break: break-all;
  }

  @media (max-width: 768px) {
    .app-shell {
      flex-direction: column;
    }
    .app-sidebar {
      width: 100%;
      min-height: 0;
      max-height: none;
      position: relative;
      border-right: none;
      border-bottom: 1px solid var(--border);
      flex-direction: row;
      flex-wrap: wrap;
      align-items: center;
      padding: 0.65rem 0.5rem;
      gap: 0.35rem;
      box-shadow: none;
    }
    .sidebar-brand {
      flex: 1 1 auto;
      border: none;
      margin: 0;
      padding: 0.35rem 0.65rem;
      min-width: 0;
    }
    .sidebar-nav {
      flex-direction: row;
      flex-wrap: wrap;
      width: 100%;
      padding: 0 0.35rem;
      flex: none;
    }
    .nav-item {
      flex: 1 1 auto;
      text-align: center;
      min-width: 5rem;
    }
    .sidebar-logout {
      margin: 0;
      padding: 0.45rem 0.75rem;
      border: none;
      width: auto;
      flex: 0 0 auto;
    }
  }
