:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1c1f24;
  --text-muted: #5a6270;
  --border: #e0e3e8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --radius: 10px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2025;
    --text: #eef0f3;
    --text-muted: #a3aab5;
    --border: #2c3038;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --danger: #f87171;
    --danger-bg: #3a1a1a;
    --success: #4ade80;
    --success-bg: #123420;
  }
}

html.theme-light {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1c1f24;
  --text-muted: #5a6270;
  --border: #e0e3e8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
}

html.theme-dark {
  --bg: #14161a;
  --surface: #1d2025;
  --text: #eef0f3;
  --text-muted: #a3aab5;
  --border: #2c3038;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
}

* { box-sizing: border-box; }

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  line-height: 1.6;
}

a { color: var(--primary); }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}

.header .brand {
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--text);
}

.lang-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 0.82rem;
}

.lang-switch a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 2px;
}

.lang-switch a:hover {
  color: var(--text);
  text-decoration: underline;
}

.lang-switch a.lang-current {
  color: var(--text);
  font-weight: 700;
  text-decoration: underline;
}

.container h1 {
  font-size: 1.5rem;
  margin: 4px 0 6px;
}

.header .auth-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

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

.service-description {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin: 4px 0 18px;
}

.card h2 {
  margin-top: 0;
  font-size: 1.05rem;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.field .hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
select {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

input:focus, select:focus, button:focus, a:focus, summary:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.row-2 .field {
  min-width: 0;
}

@media (max-width: 480px) {
  .row-2 { grid-template-columns: 1fr; }
}

button, .btn {
  display: inline-block;
  padding: 13px 20px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  text-align: center;
  text-decoration: none;
  width: 100%;
}

button:hover, .btn:hover { background: var(--primary-hover); }

/* Shared by every primary-styled button/link (incl. #file-picker-btn and
   #submit-btn — see section 2 of the UI-polish request, which asks the
   file-picker button to reuse the submit button's exact look rather than
   duplicating CSS: both are plain `.btn`/`button` with no modifier class,
   so this rule already covers both). */
button:active, .btn:active {
  filter: brightness(0.92);
}

button:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
  filter: none;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-google {
  background: #ffffff;
  color: #1c1f24;
  border: 1px solid var(--border);
}

.btn-small {
  width: auto;
  padding: 8px 14px;
  font-size: 0.85rem;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  filter: brightness(0.9);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

@media (min-width: 480px) {
  .modal-actions {
    flex-direction: row-reverse;
  }

  .modal-actions .btn {
    width: auto;
    flex: 1;
  }
}

.inline-form {
  display: inline;
}

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.92rem;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success);
}

.progress-box {
  display: none;
  text-align: center;
  padding: 20px;
}

.progress-box.active { display: block; }

.spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto 12px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.progress-track {
  width: 100%;
  max-width: 320px;
  height: 8px;
  margin: 4px auto 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.3s ease;
}

.progress-percent {
  display: block;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 4px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Original-video info (section 3 of the UI-polish request): a compact
   2-column grid on narrow screens, 3 columns on wider ones, so this block
   stays short even with 5 fields — it now sits above the preview/trim
   inputs (see public/index.php) and pushing those down defeats the point
   of moving it there. */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 16px;
  margin: 0;
}

@media (min-width: 600px) {
  .meta-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.meta-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.meta-item dt {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0;
}

.meta-item dd {
  margin: 4px 0 0;
  font-weight: 600;
  font-size: 0.92rem;
  overflow-wrap: break-word;
}

video {
  width: 100%;
  border-radius: 8px;
  background: #000;
  margin-top: 10px;
}

/* Congestion ("processing"/"waiting") and personal queue-position boxes on
   the top page — see public/index.php and public/assets/js/app.js. Two
   separate cards by design: the spec these implement requires the
   site-wide waiting count and "how many are ahead of me" to always be
   visually and textually distinct, never merged into one line/label. */
.queue-status-card { font-size: 0.95rem; }

.queue-status-line {
  margin: 0 0 6px;
  font-weight: 600;
}

.queue-status-line:last-of-type { margin-bottom: 0; }

.queue-status-error-note {
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 0.85rem;
}

.queue-status-updated {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 400;
}

/* Still used inside the conversion-status modal (#modal-users-ahead) —
   see below. */
.queue-personal-detail {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 400;
}

/* Conversion-status modal (public/index.php #conversion-modal,
   public/assets/js/app.js) — consolidates job status, queue position,
   upload/conversion progress, cancel, and download into one place instead
   of duplicating them inline on the page. Reuses .queue-status-line /
   .queue-personal-detail / .queue-status-error-note / .queue-status-updated
   / .progress-box / .modal / .modal-actions as-is; only the pieces below
   are new. */
.conversion-modal-dialog {
  border-top: 4px solid var(--primary);
  text-align: left;
}

/* Never relies on color alone — the status line text itself always names
   the outcome too (e.g. "変換が完了しました。" / "動画の変換に失敗しました。"). */
.conversion-modal-dialog.modal-state-done { border-top-color: var(--success); }
.conversion-modal-dialog.modal-state-error { border-top-color: var(--danger); }
.conversion-modal-dialog.modal-state-cancelled { border-top-color: var(--text-muted); }

.modal-status-line {
  font-weight: 700;
  font-size: 1.02rem;
  margin: 0 0 14px;
}

.modal-queue-counts {
  margin-bottom: 10px;
}

.modal-progress-box {
  padding: 12px 0 4px;
}

#modal-download-box .btn {
  margin-top: 4px;
}

/* Status bar on the page itself, shown only while the modal is closed but
   this user's own job is still queued/processing — the one way back into
   the modal (see public/assets/js/app.js openModal()/updateReopenBar()). */
.reopen-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.reopen-status-text {
  font-weight: 600;
}

.reopen-status-bar .btn {
  width: auto;
}

.footer {
  text-align: center;
  padding: 24px 16px 40px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer a { color: var(--text-muted); margin: 0 6px; }

.legal h1 { font-size: 1.4rem; }
.legal h2 { font-size: 1.1rem; margin-top: 1.6em; }
.legal p, .legal li { color: var(--text); }
.legal-updated { color: var(--text-muted); font-size: 0.85rem; margin-top: 2em; }

.card h3 { font-size: 0.98rem; margin: 0; }

.faq-list { display: flex; flex-direction: column; gap: 4px; }

.faq-question-heading { margin: 0; }

.faq-question {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: none;
  border-top: 1px solid var(--border);
  padding: 14px 4px;
  font-weight: 600;
  font-size: 0.95rem;
}

.faq-list .faq-item:first-child .faq-question {
  border-top: none;
}

.faq-question::after {
  content: "+";
  flex-shrink: 0;
  font-weight: 400;
  font-size: 1.2rem;
  color: var(--text-muted);
}

.faq-question[aria-expanded="true"]::after {
  content: "\2212";
}

.faq-answer {
  padding: 0 4px 14px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.faq-answer p {
  margin: 0;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  max-width: 400px;
  width: 100%;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--border);
  color: var(--text-muted);
}

/* Full-sentence content ("Logged in as ...") instead of a short pill label:
   a 999px pill radius reads oddly once the text wraps, and long usernames /
   longer-language sentences (es/pt-br) need normal wrapping, not truncation. */
.badge-account {
  border-radius: 8px;
  padding: 5px 10px;
  white-space: normal;
  word-break: break-word;
  max-width: 100%;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.header-actions .btn {
  width: auto;
}

.visually-hidden {
  position: absolute;
  width: 1px !important;
  height: 1px !important;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.file-picker .btn {
  width: auto;
  flex-shrink: 0;
}

.file-picker-status {
  color: var(--text-muted);
  font-size: 0.9rem;
  word-break: break-all;
}

.file-picker-status-error {
  color: var(--danger);
  font-weight: 600;
}

.selected-account {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.92rem;
  word-break: break-all;
  margin: 0;
}

/* Login modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

.modal h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.3rem;
  line-height: 1;
}

.modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

@media (max-width: 480px) {
  .modal {
    padding: 24px 16px 20px;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .btn {
    flex: 1 1 auto;
  }

  .file-picker {
    flex-direction: column;
    align-items: stretch;
  }

  .file-picker .btn {
    width: 100%;
  }

  /* "Logged in as <username>" + logout button: stack instead of
     squeezing onto one line, since usernames (up to 15 chars) combined
     with the longer es/pt-br sentences can exceed the available width. */
  .header .auth-status {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .header .auth-status .inline-form {
    display: block;
  }

  .header .auth-status .inline-form .btn {
    width: 100%;
  }
}

/* Generic hint text — .field .hint (above) already covers hints nested in
   a .field; this covers standalone <p class="hint"> paragraphs that sit
   directly in a .card (e.g. the STEP1 upload hint, the resize-mode hint). */
.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Hero quick-specs line (section 4): "MP4 / MOV / WebM / MKV · up to 2GB · up to 60 min" */
.quick-specs {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 18px;
}

/* STEP 1/2/3 layout (section 8) */
.step-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 2px 9px;
  border-radius: 999px;
  margin: 0 0 8px;
}

.step-card-disabled {
  background: var(--bg);
}

/* Explains *why* STEP 2 is inert while logged out — not just a disabled
   look, an actual sentence (section 3). */
.step-disabled-notice {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 14px;
}

.step-fields[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

/* Prominent pre-login CTA inside the STEP1 card (section 3) */
.main-login-cta-box {
  margin: 4px 0 18px;
}

/* Hour/minute/second trim inputs (section 7) */
.time-inputs {
  display: flex;
  align-items: center;
  gap: 6px 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.time-input-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

/* +/- step buttons (section 4): sit either side of each h/m/s/ms field.
   Deliberately not full-width/default `.btn` sizing — these are compact,
   fixed-size steppers, not primary actions. */
.time-step-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  flex-shrink: 0;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 6px;
}

.time-input {
  width: 52px !important;
  padding: 8px 4px !important;
  text-align: center;
}

.time-unit {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-left: 2px;
}

/* Per-option explanation shown under the resize-mode <select> (section 6) */
.resize-mode-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 8px 0 0;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 6px;
}

/* Mobile language switcher (section 10): the existing .lang-switch link
   row stays for wider screens; under 600px it's replaced by a single
   native <select> so language links never wrap/overflow the header. */
.lang-switch-mobile {
  display: none;
}

.lang-switch-mobile select {
  width: auto;
  padding: 6px 10px;
  font-size: 0.85rem;
  border-radius: 8px;
}

@media (max-width: 599px) {
  .lang-switch {
    display: none;
  }

  .lang-switch-mobile {
    display: inline-block;
  }
}

@media (max-width: 360px) {
  .time-input {
    width: 44px !important;
    padding: 8px 2px !important;
  }

  .time-step-btn {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }
}

.guide-links {
  margin: 0;
  padding-left: 20px;
}

.guide-links li {
  margin-bottom: 8px;
}
