:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --text: #15171b;
  --muted: #646b78;
  --border: #e1e4ea;
  --accent: #d93a35;
  --accent-press: #bd2f2b;
  --accent-text: #ffffff;
  --ok: #1d8a4b;
  --down: #a86a12;
  --error: #b42318;
  --shadow: 0 1px 2px rgba(16, 18, 22, 0.06), 0 4px 16px rgba(16, 18, 22, 0.05);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #171a1f;
    --surface-2: #1f232a;
    --text: #eceef2;
    --muted: #9aa1ad;
    --border: #2a2f37;
    --accent: #ef4b44;
    --accent-press: #d93a35;
    --ok: #4cc38a;
    --down: #e3a64b;
    --error: #ff8a80;
    --shadow: none;
  }
}

/* Author display rules (grid/flex) would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 600px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

h1 { margin: 0; font-size: 1.25rem; letter-spacing: -0.01em; }

.center { min-height: calc(100dvh - 48px); display: grid; place-items: center; }

/* ---- sign-in ---- */
.signin { width: 100%; max-width: 340px; text-align: center; }
.signin h1 { font-size: 1.6rem; margin-top: 14px; }
.signin p { margin: 6px 0 0; }
.signin .button { margin-top: 24px; }
.logo { width: 56px; height: 56px; color: var(--accent); }
.logo.small { width: 30px; height: 30px; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- header ---- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.brand { display: flex; align-items: center; gap: 10px; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 0.82rem; font-weight: 600; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
  padding: 5px 11px; border-radius: 999px; white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--ok); }
.pill.down { color: var(--down); }
.pill.down .dot { background: var(--down); }

/* ---- cards & controls ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

label { display: block; font-weight: 600; font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; }

input, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 48px;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.field { position: relative; }
.field input { padding-right: 84px; }
.field .ghost { position: absolute; right: 6px; top: 6px; bottom: 6px; min-height: 0; padding: 0 12px; }

.row { display: flex; gap: 10px; margin-top: 10px; }
.row select { flex: 1 1 auto; }
.row button { flex: none; min-width: 120px; }

button, .button {
  font: inherit; font-weight: 600;
  border-radius: 12px;
  padding: 10px 18px;
  min-height: 48px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible, .button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.primary:active { background: var(--accent-press); }
.secondary { background: transparent; }
.ghost { background: var(--surface); border-color: var(--border); font-size: 0.85rem; border-radius: 9px; }
.wide { width: 100%; }
button:disabled { opacity: 0.55; cursor: default; }

.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--accent); font-weight: 600; }

.error { color: var(--error); margin: 10px 0 0; font-size: 0.9rem; }
.note { margin: 10px 0 0; font-size: 0.85rem; }
.warn { color: var(--down); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---- network setting: three-way segmented control ---- */
fieldset.setting { border: 0; border-top: 1px solid var(--border); margin: 14px 0 0; padding: 12px 0 0; min-width: 0; }
.setting-title { float: left; width: 100%; padding: 0; margin: 0 0 8px; color: var(--text); font-size: 0.92rem; font-weight: 600; }
.setting-help { clear: both; margin: 8px 0 0; font-size: 0.8rem; color: var(--muted); }
.segmented { clear: both; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.segmented label { margin: 0; text-align: center; padding: 9px 4px; border-radius: 9px; font-size: 0.85rem; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.segmented input:checked + label { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }
.segmented input:disabled + label { opacity: 0.6; cursor: default; }

/* ---- jobs ---- */
.jobs { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 10px; }
.empty { text-align: center; color: var(--muted); margin: 28px 0 8px; }

.job {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
}
.thumb { width: 112px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.thumb.missing { visibility: hidden; }
.body { min-width: 0; }
.title { margin: 0; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { margin: 3px 0 0; font-size: 0.8rem; color: var(--muted); }
.status { margin: 6px 0 0; font-size: 0.88rem; }
.job .note { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }
.job.failed .status { color: var(--error); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.actions .button, .actions button { min-height: 40px; padding: 8px 14px; font-size: 0.9rem; border-radius: 10px; }

.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.4s ease; }
.bar.indeterminate span { width: 35% !important; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }

/* ---- footer ---- */
.foot { margin-top: 28px; display: grid; gap: 12px; }
.foot p { margin: 0; }
.account { text-align: center; }

.panel { padding: 0; }
.panel summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px; font-weight: 600; }
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: "›"; color: var(--muted); font-size: 1.3rem; line-height: 1; transition: transform 0.2s; margin-left: auto; }
.panel[open] summary::after { transform: rotate(90deg); }
.panel > :not(summary) { margin-left: 16px; margin-right: 16px; }
.panel > :last-child { margin-bottom: 16px; }
.panel p { margin-top: 8px; margin-bottom: 8px; }
.panel input[type="file"] { background: transparent; border: 1px dashed var(--border); padding: 10px; }
.badge { font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.down { color: var(--down); border-color: currentColor; }
.steps { margin: 8px 0; padding-left: 20px; }
.steps li { margin: 4px 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }

@media (max-width: 440px) {
  .job { grid-template-columns: 88px minmax(0, 1fr); gap: 10px; }
  .thumb { width: 88px; }
  .row button { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  .bar span { transition: none; }
  .bar.indeterminate span { animation: none; width: 100% !important; opacity: 0.5; }
  .panel summary::after { transition: none; }
}

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
