:root {
  --primary: #1565c0;
  --primary-dark: #0d47a1;
  --bg: #f7f9fc;
  --card: #ffffff;
  --text: #263447;
  --muted: #66758a;
  --border: #d6e1ee;
  --danger: #b42318;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
  color: var(--text);
  background: var(--bg);
}
body.busy { cursor: progress; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

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

.hero,
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.hero { padding: 16px 18px; margin-bottom: 10px; }
.panel { padding: 14px; margin-bottom: 10px; }

h1 { margin: 0 0 6px; font-size: clamp(1.45rem, 3vw, 2rem); line-height: 1.25; }
h2 { margin: 0 0 10px; color: var(--primary-dark); font-size: 1rem; }
p { line-height: 1.7; }
.lead { margin: 0; color: var(--muted); }

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 118px;
  padding: 16px;
  text-align: center;
  border: 1px dashed #9db7d3;
  border-radius: 8px;
  background: #fbfdff;
}
.drop-zone.is-dragover { border-color: var(--primary); background: #eef6ff; }
.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
.upload-btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.upload-btn:hover, button:hover { background: var(--primary-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-secondary { background: #eef3f9; color: var(--primary-dark); border: 1px solid var(--border); }
.btn-secondary:hover { background: #dde9f6; color: var(--primary-dark); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8f1c12; }

.drop-title { margin: 10px 0 0; font-weight: 700; }
.drop-sub { margin: 4px 0 0; color: var(--muted); font-size: .88rem; }

.file-list { display: grid; gap: 6px; margin-top: 10px; }
.file-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: .88rem;
}
.file-item button { min-height: 28px; padding: 4px 8px; font-size: .8rem; }

.simple-controls {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(220px, 1fr);
  gap: 10px;
  margin-top: 12px;
}
.control { display: flex; flex-direction: column; gap: 5px; }
.control label { color: #314a69; font-size: .86rem; font-weight: 700; }
select, input[type="text"], textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
}
select, input[type="text"] { min-height: 38px; padding: 7px 9px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.status-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}
.progress-wrap { height: 9px; overflow: hidden; border-radius: 999px; background: #dce9f7; }
.progress-bar { height: 100%; width: 0%; border-radius: inherit; background: var(--primary); transition: width .18s ease; }
.status-text { color: var(--muted); font-size: .88rem; white-space: nowrap; }

.result-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.help-text { color: var(--muted); font-size: .84rem; line-height: 1.6; }
textarea#resultText { min-height: 430px; padding: 12px; line-height: 1.7; resize: vertical; white-space: pre-wrap; }
.log-box {
  max-height: 130px;
  overflow: auto;
  margin-top: 10px;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
  color: #42546a;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: .78rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.footer {
  text-align: center;
  padding: 9px 0 18px;
  font-size: .9rem;
  color: var(--primary);
  border-top: 1px solid var(--border);
  background: #fff;
}
.footer a { color: var(--primary); font-weight: 700; }

.ad-panel {
  width: min(900px, calc(100% - 24px));
  margin: 0 auto 14px;
  border: 1px solid #d7e6f8;
  border-radius: 8px;
  background: #fff;
  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-msg { font-size: .72rem; color: #4f6f91; line-height: 1.2; }
.ad-close-btn {
  margin: 0 !important;
  padding: 3px 8px !important;
  min-height: 0;
  height: auto;
  line-height: 1.2;
  border-radius: 999px;
  background: #1565c0;
  color: #fff;
  font-size: .72rem !important;
}
.ad-close-btn:hover { background: #0d47a1; }
.ad-close-btn[hidden] { display: none !important; }
.ad-body { padding: 8px; min-height: 90px; background: #fff; }

@media (max-width: 620px) {
  .app-shell { width: min(100% - 16px, 900px); margin-top: 10px; }
  .hero, .panel { padding: 12px; }
  .simple-controls { grid-template-columns: 1fr; }
  .status-row { grid-template-columns: 1fr; }
  textarea#resultText { min-height: 320px; }
}
