:root {
    --bg: #0d0f12;
    --surface: #161a1f;
    --surface-alt: #1f242b;
    --border: #2a3038;
    --text: #e8ecf1;
    --muted: #8a93a0;
    --accent: #4f9cf9;
    --accent-strong: #2d7af0;
    --danger: #e2574c;
    --ok: #46c272;
    --warn: #e6a23c;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
                 "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

body {
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    padding: 12px 16px 32px;
}

header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: env(safe-area-inset-top, 0) 16px 0;
    padding-bottom: 8px;
    padding-top: max(env(safe-area-inset-top, 12px), 12px);
    background: rgba(13, 15, 18, 0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.brand {
    font-weight: 700;
    font-size: 18px;
    color: var(--text);
    text-decoration: none;
    letter-spacing: 0.02em;
}

.link {
    color: var(--accent);
    text-decoration: none;
    font-size: 15px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 16px;
}

.card h1, .card h2, .card h3 {
    margin: 0 0 12px;
    font-weight: 700;
}

.card h1 { font-size: 20px; }
.card h2 { font-size: 17px; }
.card h3 { font-size: 15px; color: var(--muted); }

form.stacked, form.card.stacked { display: flex; flex-direction: column; gap: 12px; }
form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }

input[type=text], input[type=password], textarea, select {
    width: 100%;
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus { border-color: var(--accent); }

textarea { resize: vertical; min-height: 120px; }

button {
    appearance: none;
    border: none;
    border-radius: 12px;
    padding: 14px 18px;
    background: var(--accent);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    transition: background 0.1s, transform 0.05s;
}
button:hover { background: var(--accent-strong); }
button:active { transform: scale(0.98); }
button:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }

button.primary { background: var(--ok); }
button.warn { background: var(--danger); }

.hint { color: var(--muted); font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-weight: 600; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row.sub { font-size: 13px; margin-top: 4px; }

progress {
    width: 100%;
    height: 8px;
    accent-color: var(--accent);
    border: none;
    border-radius: 4px;
    overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--surface-alt); border-radius: 4px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 4px; }

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--surface-alt);
    color: var(--muted);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.status-pending     { color: var(--muted); }
.status-downloading { color: var(--accent); border-color: var(--accent); }
.status-scoring     { color: var(--accent); border-color: var(--accent); }
.status-ready       { color: var(--ok); border-color: var(--ok); }
.status-uploading   { color: var(--warn); border-color: var(--warn); }
.status-done        { color: var(--ok); border-color: var(--ok); background: rgba(70, 194, 114, 0.12); }
.status-failed      { color: var(--danger); border-color: var(--danger); background: rgba(226, 87, 76, 0.1); }

.job-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.job-list a {
    display: block;
    text-decoration: none;
    color: var(--text);
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
}
.job-list a:active { background: var(--border); }

.thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}
.thumb {
    position: relative;
    cursor: pointer;
    border: 2px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    transition: border-color 0.15s, transform 0.05s;
}
.thumb:active { transform: scale(0.98); }
.thumb input[type=radio] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.thumb img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}
.thumb-meta {
    display: flex;
    justify-content: space-between;
    padding: 6px 8px;
    font-size: 11px;
    color: var(--muted);
    background: var(--surface-alt);
}
.thumb.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(79, 156, 249, 0.3);
}
.thumb.selected .thumb-meta {
    color: var(--accent);
}

.danger { border-color: rgba(226, 87, 76, 0.4); }

.targets {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}
.target-item {
    display: flex !important;
    flex-direction: row !important;
    gap: 12px;
    align-items: center;
    padding: 12px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
}
.target-item:has(input:checked) {
    border-color: var(--accent);
    background: rgba(79, 156, 249, 0.08);
}
.target-item:has(input:disabled) {
    opacity: 0.55;
    cursor: not-allowed;
}
.target-item input[type=checkbox] {
    width: 22px;
    height: 22px;
    accent-color: var(--accent);
    flex-shrink: 0;
}
.target-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: var(--text);
    font-size: 14px;
}
.target-label .ok { color: var(--ok); font-size: 12px; }
.target-label .warn { color: var(--warn); font-size: 12px; }

.target-results {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.target-results li {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.target-results a {
    color: var(--accent);
    word-break: break-all;
}

footer {
    padding: 16px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    border-top: 1px solid var(--border);
}

@media (min-width: 720px) {
    .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
