:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --fg: #1f2328;
  --muted: #656d76;
  --line: #d0d7de;
  --accent: #0969da;
  --accent-fg: #ffffff;
  --danger: #cf222e;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --card: #161b22;
    --fg: #e6edf3;
    --muted: #8b949e;
    --line: #30363d;
    --accent: #58a6ff;
    --accent-fg: #0d1117;
    --danger: #ff7b72;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 1;
}
.top h1 { margin: 0; font-size: 18px; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  max-width: 420px;
  margin: 40px auto;
}
.card h2 { margin: 0 0 6px; font-size: 18px; }

.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }

input, select {
  font: inherit;
  font-size: 16px; /* 避免 iOS 自動放大 */
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button, .ghost-link {
  font: inherit;
  font-size: 15px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  min-height: 40px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.ghost { background: transparent; }
button:disabled { opacity: 0.5; cursor: default; }

.muted { color: var(--muted); margin: 0; font-size: 14px; }
.msg { color: var(--muted); font-size: 14px; min-height: 1.4em; margin: 8px 0; word-break: break-word; }
.msg.error { color: var(--danger); }

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  margin: 4px 0 12px;
}
.crumbs button {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 4px 2px;
  min-height: 0;
}
.crumbs .sep { color: var(--muted); }

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  margin-bottom: 12px;
}
.toolbar button { white-space: nowrap; }

.desc {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0 0 12px;
  white-space: pre-wrap;
}

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  overflow: hidden;
}
.entries li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.entries li:last-child { border-bottom: 0; }
.entries .icon { font-size: 18px; text-align: center; }
.entries .name {
  background: none;
  border: 0;
  padding: 0;
  min-height: 0;
  text-align: left;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  width: 100%;
}
.entries .name.dir { color: var(--accent); font-weight: 600; }
.entries .meta {
  font-size: 12px;
  color: var(--muted);
  display: block;
}
.entries .actions { display: flex; gap: 6px; }
.entries .actions a,
.entries .actions button {
  font-size: 13px;
  padding: 5px 10px;
  min-height: 0;
}
.entries .path { color: var(--muted); font-size: 12px; }

.readme { margin-top: 16px; }
.readme pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  max-height: 60vh;
  overflow: auto;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  background: var(--card);
  color: var(--fg);
  width: min(960px, calc(100vw - 16px));
  height: min(86vh, 900px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog[open] { display: flex; flex-direction: column; }
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.preview-head span#preview-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-actions { display: flex; gap: 8px; flex-shrink: 0; }
#preview-body { flex: 1; min-height: 0; display: flex; }
#preview-body iframe,
#preview-body img {
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: contain;
}

@media (max-width: 600px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar input { grid-column: 1 / -1; }
  .entries li { grid-template-columns: 24px minmax(0, 1fr); }
  .entries .actions { grid-column: 2; }
}
