:root {
  --bg: #eef5fb;
  --card: #ffffff;
  --ink: #1f2d3d;
  --muted: #65758b;
  --line: #d7e4f2;
  --primary: #1565c0;
  --primary-dark: #0d47a1;
  --soft: #f5f9ff;
  --danger: #b00020;
  --shadow: 0 18px 45px rgba(21, 101, 192, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Yu Gothic", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #f7fbff 0%, var(--bg) 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  width: min(1120px, calc(100% - 24px));
  margin: 24px auto 16px;
}

.hero {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 20px;
  align-items: stretch;
  margin-bottom: 18px;
}

.hero-text,
.preview-panel,
.control-panel,
.output-panel,
.help-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.hero-text {
  padding: 28px;
}

.hero-text h1 {
  margin: 0 0 12px;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.14;
  letter-spacing: 0.02em;
}

.lead {
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
}


.preview-panel {
  padding: 18px;
}

.preview-panel video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  background: #111827;
  object-fit: contain;
  border: 1px solid #0f172a;
}

.preview-panel video.is-empty {
  background: linear-gradient(135deg, #102a43, #1e6091);
}

.duration-info {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
  word-break: break-all;
}

.control-panel,
.output-panel,
.help-panel {
  padding: 22px;
  margin-bottom: 18px;
}

.section-title {
  margin: 0 0 16px;
  font-size: 1.2rem;
  color: var(--primary-dark);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 14px;
}

.file-row {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.checkbox-label {
  font-size: 0.9rem;
  color: #34455c;
  font-weight: 700;
}

.field input[type="file"],
.field input[type="number"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.field small {
  color: var(--muted);
  line-height: 1.55;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft);
}

.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 999px;
  color: #fff;
  background: var(--primary);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(21, 101, 192, 0.18);
  transition: transform 0.08s ease, background 0.18s ease, opacity 0.18s ease;
}

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

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: #536d89;
}

.btn-secondary:hover {
  background: #40556d;
}

.btn-ghost {
  color: var(--primary-dark);
  background: #eaf3ff;
  box-shadow: none;
}

.btn-ghost:hover {
  background: #dbeeff;
}

.status-box {
  margin-top: 18px;
  padding: 14px;
  border-radius: 16px;
  background: var(--soft);
  border: 1px solid var(--line);
}

.status-text {
  margin: 0 0 10px;
  min-height: 1.5em;
  color: var(--muted);
  line-height: 1.6;
}

.status-text.is-error {
  color: var(--danger);
  font-weight: 800;
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: #dce8f7;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1e88e5, #0d47a1);
  transition: width 0.18s ease;
}

.output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.summary {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.frame-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.frame-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
}

.frame-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #111827;
}

.frame-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  font-size: 0.84rem;
  color: var(--muted);
}

.frame-meta strong {
  color: var(--primary-dark);
}

.help-panel ul {
  margin: 0;
  padding-left: 1.2em;
  color: var(--muted);
  line-height: 1.9;
}

.app-footer {
  width: min(1120px, calc(100% - 24px));
  margin: 0 auto 18px;
  padding: 10px 0 18px;
  text-align: center;
  color: #1565c0;
  border-top: 1px solid #d7e6f8;
  background: rgba(255, 255, 255, 0.42);
  font-size: 0.92rem;
}

.app-footer a {
  color: #1565c0;
  text-decoration: none;
  font-weight: 800;
}

.app-footer a:hover {
  color: #0d47a1;
}

.ad-panel {
  max-width: 1120px;
  margin: 10px auto 0;
  padding: 0;
  border: 1px solid #d7e6f8;
  border-radius: 10px;
  background: #ffffff;
  overflow: hidden;
}

.ad-panel[hidden] {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

.ad-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  background: #f4f8ff;
  border-bottom: 1px solid #d7e6f8;
}

.ad-label,
.ad-wait {
  font-size: 0.72rem;
  color: #4f6f91;
  line-height: 1.3;
}

.ad-head-left {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ad-close-btn {
  margin: 0 !important;
  padding: 3px 8px !important;
  min-height: 0;
  height: auto;
  line-height: 1.2;
  border: none;
  border-radius: 999px;
  background: #1565c0;
  color: #ffffff;
  font-size: 0.72rem !important;
  font-weight: 700;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.ad-close-btn:hover {
  background: #0d47a1;
}

.ad-close-btn[hidden] {
  display: none !important;
}

.ad-body {
  padding: 8px;
  background: #ffffff;
}

@media (max-width: 860px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 14px, 1120px);
    margin-top: 10px;
  }

  .hero-text,
  .preview-panel,
  .control-panel,
  .output-panel,
  .help-panel {
    border-radius: 16px;
    padding: 16px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .action-row .btn {
    width: 100%;
  }

  .output-head {
    align-items: flex-start;
    flex-direction: column;
  }
}
