:root {
  --bg: #eef6ff;
  --card: #ffffff;
  --ink: #10233d;
  --muted: #66758a;
  --line: #d6e5f7;
  --blue: #1565c0;
  --blue-dark: #0d47a1;
  --blue-soft: #eaf4ff;
  --green: #168a45;
  --green-dark: #0e6e35;
  --warning: #b86700;
  --danger: #c0392b;
  --shadow: 0 12px 32px rgba(25, 75, 120, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
  color: var(--ink);
  background: linear-gradient(145deg, #edf7ff 0%, #f8fbff 55%, #f2f7fb 100%);
  line-height: 1.65;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.app-shell {
  width: min(1180px, calc(100% - 24px));
  margin: 22px auto 16px;
}
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-icon {
  width: 58px;
  height: 46px;
  border-radius: 9px 9px 4px 4px;
  background: linear-gradient(135deg, #ffd54f, #ffb300);
  position: relative;
  box-shadow: 0 6px 14px rgba(255, 179, 0, 0.24);
}
.brand-icon::before {
  content: "";
  position: absolute;
  left: 6px;
  top: -10px;
  width: 27px;
  height: 14px;
  border-radius: 7px 7px 0 0;
  background: #ffe082;
}
.brand-icon::after {
  content: "✎";
  position: absolute;
  right: -6px;
  bottom: -8px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 900;
  background: #1aa35a;
  border: 3px solid #fff;
}
h1 {
  margin: 0;
  font-size: clamp(2rem, 3.8vw, 3.4rem);
  letter-spacing: 0.04em;
  line-height: 1.05;
}
.subtitle { margin: 6px 0 0; color: #3c5067; font-size: 1rem; }
.header-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.small-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
  color: #24405f;
  background: rgba(255,255,255,0.82);
  box-shadow: 0 4px 12px rgba(36, 64, 95, 0.08);
}
.small-btn:hover { border-color: #9bc5ef; background: #fff; }
.top-work-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(420px, 1.45fr);
  gap: 14px;
  align-items: stretch;
  margin-bottom: 14px;
}
.top-work-grid .panel {
  margin-bottom: 0;
  min-height: 100%;
}
.top-work-grid .drop-zone {
  min-height: 318px;
}
.top-work-grid .name-box {
  min-height: 132px;
}
.top-work-grid .sortable-name-list {
  max-height: 220px;
}
.panel {
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,0.92);
  box-shadow: var(--shadow);
}
.step-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 1.22rem;
  font-weight: 800;
}
.step-num {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  background: var(--blue);
  font-weight: 900;
}
.lead { margin: -4px 0 12px; color: var(--muted); }
.drop-zone {
  min-height: 190px;
  display: grid;
  align-content: center;
  gap: 12px;
  padding: 22px;
  border: 2px dashed #9ac7f5;
  border-radius: 15px;
  background: #f8fcff;
  text-align: center;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease, border-color 0.16s ease;
}
.drop-zone.has-files {
  align-content: start;
  text-align: left;
}
.drop-zone-main {
  text-align: center;
}
.drop-zone.has-files .drop-zone-main {
  padding-bottom: 10px;
  border-bottom: 1px solid #d7e7f7;
}
.drop-file-list {
  display: none;
  width: 100%;
  max-height: 178px;
  overflow: auto;
  padding: 4px;
}
.drop-zone.has-files .drop-file-list {
  display: grid;
  gap: 8px;
}
.drop-file-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #315579;
  font-size: 0.9rem;
  font-weight: 800;
}
.upload-file-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 9px;
  border: 1px solid #dfeaf6;
  border-radius: 10px;
  background: rgba(255,255,255,0.9);
}
.upload-file-row.is-ignored { opacity: 0.58; background: #f7f8fa; }
.drop-zone.is-dragover {
  transform: translateY(-2px) scale(1.01);
  border-color: var(--green);
  background: #ecfff4;
  box-shadow: inset 0 0 0 4px rgba(22, 138, 69, 0.1), 0 12px 26px rgba(22, 138, 69, 0.16);
}
.drop-zone.is-dragover .drop-main { color: var(--green-dark); }
.drop-zone.is-dragover .drop-icon { background: var(--green); transform: translateY(-3px); }
.drop-icon {
  width: 62px;
  height: 44px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  color: #fff;
  background: var(--blue);
  font-size: 1.7rem;
  transition: background-color 0.16s ease, transform 0.16s ease;
}
.drop-main { margin: 0; font-size: 1.1rem; font-weight: 800; color: #24405f; }
.drop-sub { margin: 4px 0 14px; color: var(--muted); font-size: 0.92rem; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.select-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 180px;
  min-height: 44px;
  padding: 9px 18px;
  border-radius: 12px;
  color: #fff;
  background: var(--blue);
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(21, 101, 192, 0.22);
  cursor: pointer;
}
.select-label:hover { background: var(--blue-dark); }
.name-box {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  padding: 14px;
  border: 1px solid #a9cdf1;
  border-radius: 12px;
  outline: none;
  background: #fff;
}
.name-box:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(21, 101, 192, 0.11); }
.input-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin: 10px 0 14px;
}
.ghost-btn {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 14px;
  color: #24405f;
  background: #f8fbff;
  font-weight: 700;
}
.ghost-btn:hover { border-color: #9bc5ef; background: #fff; }
.count-text { margin-left: auto; color: var(--muted); font-weight: 700; }
.option-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.35fr) minmax(220px, 1fr);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.option-cell { padding: 14px; min-height: 140px; background: rgba(255,255,255,0.84); border-right: 1px solid var(--line); }
.option-cell:last-child { border-right: 0; }
.option-cell h3 { margin: 0 0 10px; font-size: 1rem; }
.option-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.text-input, .select-input, .number-input { min-height: 40px; padding: 8px 10px; border: 1px solid #cfddec; border-radius: 9px; background: #fff; }
.text-input { width: min(100%, 230px); }
.number-input { width: 94px; }
.select-input { width: 135px; }
.checkline { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 700; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 0.86rem; }
.list-count { color: #4e6883; font-size: 0.9rem; }
.empty-state {
  min-height: 212px;
  display: grid;
  place-items: center;
  color: #748498;
  text-align: center;
  border: 1px dashed #cadced;
  border-radius: 12px;
  background: rgba(255,255,255,0.75);
}
.name-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 10px;
  margin-bottom: 8px;
  border: 1px solid #e2ebf5;
  border-radius: 11px;
  background: #fff;
}
.name-row { grid-template-columns: 44px 28px minmax(0, 1fr) 32px; }
.name-row.is-ignored { opacity: 0.58; background: #f7f8fa; }
.row-num {
  width: 34px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #315579;
  background: #eaf4ff;
  font-weight: 800;
  font-size: 0.9rem;
}
.drag-handle { color: #6d8198; cursor: grab; user-select: none; font-weight: 900; }
.name-row:active .drag-handle { cursor: grabbing; }
.file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-edit {
  width: 100%;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 5px 8px;
  background: #f9fbfe;
}
.name-edit:focus { border-color: var(--blue); outline: none; background: #fff; box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.11); }
.remove-name { width: 28px; height: 28px; border: 0; border-radius: 50%; background: #f3f6fa; color: #6a7b8d; font-weight: 900; }
.remove-name:hover { color: #fff; background: var(--danger); }
.name-row.dragging { opacity: 0.4; }
.status-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid #ffe2a8;
  border-radius: 10px;
  color: var(--warning);
  background: #fff9e8;
  font-weight: 800;
}
.status-box.ready { color: #17623b; border-color: #bfe4cb; background: #effaf3; }
.execute-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 13px; }
.download-main {
  min-width: min(100%, 330px);
  min-height: 66px;
  border: 0;
  border-radius: 18px;
  padding: 12px 26px;
  color: #fff;
  background: linear-gradient(135deg, #168a45, #0e6e35);
  box-shadow: 0 13px 25px rgba(22,138,69,0.25);
  font-size: 1.2rem;
  font-weight: 900;
}
.download-main:hover { transform: translateY(-1px); background: linear-gradient(135deg, #1aa35a, #0e6e35); }
.download-main:disabled { opacity: 0.48; cursor: not-allowed; transform: none; }
.download-main .subtext { display: block; font-size: 0.78rem; font-weight: 700; opacity: 0.92; }
.notice { color: #4e6883; font-size: 0.94rem; }
.footer-note { margin-top: 10px; color: var(--muted); font-size: 0.9rem; }
footer { text-align: center; padding: 10px 0 20px; font-size: 0.95rem; color: #1565c0; }
footer a { color: #1565c0; text-decoration: none; font-weight: bold; }
footer a:hover { color: #0d47a1; }
.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(7, 24, 45, 0.38);
  z-index: 50;
}
.modal.is-open { display: grid; }
.modal-card { width: min(620px, 100%); max-height: min(80vh, 680px); overflow: auto; border-radius: 18px; background: #fff; box-shadow: 0 22px 60px rgba(0,0,0,0.22); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.close-btn { width: 36px; height: 36px; border: 0; border-radius: 50%; background: #eef3f8; font-size: 1.2rem; font-weight: 900; }
.modal-body { padding: 18px; }
.ad-panel { max-width: 1180px; margin: 12px 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-msg { font-size: 0.72rem; color: #4f6f91; line-height: 1; }
.ad-wait-msg { margin-left: auto; }
.ad-close-btn { display: none; 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.is-visible { display: inline-flex; }
.ad-close-btn:hover { background: #0d47a1; }
.ad-body { padding: 8px; background: #ffffff; }

@media (max-width: 860px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .header-actions { justify-content: flex-start; }
  .top-work-grid, .option-grid { grid-template-columns: 1fr; }
  .top-work-grid .drop-zone { min-height: 190px; }
  .option-cell { border-right: 0; border-bottom: 1px solid var(--line); }
  .option-cell:last-child { border-bottom: 0; }
}
@media (max-width: 560px) {
  .app-shell { width: min(100% - 14px, 1180px); margin-top: 10px; }
  .panel { padding: 13px; }
  .brand { align-items: flex-start; }
  .brand-icon { width: 48px; height: 38px; }
  .execute-box { align-items: stretch; flex-direction: column; }
  .download-main { width: 100%; }
  .count-text { margin-left: 0; }
}
