:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --line: #d8dee8;
  --line-strong: #bcc7d6;
  --text: #1d2735;
  --muted: #657184;
  --blue: #315f91;
  --blue-dark: #244b76;
  --blue-soft: #eaf2fa;
  --danger: #9a3e48;
  --shadow: 0 4px 16px rgba(30, 48, 70, 0.08);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
}

.header-main {
  width: min(1500px, 100%);
  min-height: 64px;
  margin: 0 auto;
  padding: 10px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand-block, .header-tools, .model-field, .intro-row, .output-head, .prompt-label-row,
.category-title-row, .option-controls, .direct-controls { display: flex; align-items: center; }

.brand-block { min-width: 0; gap: 12px; }
.brand { color: var(--blue-dark); font-weight: 750; letter-spacing: .06em; text-decoration: none; white-space: nowrap; }
.brand-divider { width: 1px; height: 24px; background: var(--line-strong); }
h1 { margin: 0; font-size: 18px; line-height: 1.3; white-space: nowrap; }
.header-tools { gap: 20px; }
.back-link { color: var(--blue); font-size: 13px; white-space: nowrap; }
.model-field { gap: 8px; font-weight: 650; white-space: nowrap; }

select, input[type="search"], input[type="text"], textarea {
  max-width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}

select:focus, input:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(49, 95, 145, .14); }
select, input { min-height: 36px; padding: 6px 9px; }

.workspace {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 20px 22px 44px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 430px);
  align-items: start;
  gap: 22px;
}

.builder, .output-panel { min-width: 0; }
.intro-row { justify-content: space-between; gap: 20px; margin: 0 0 11px; }
.builder-toolbar { display: flex; align-items: flex-end; flex-direction: column; gap: 5px; }
.convenience-actions, .draft-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.draft-status-line { min-height: 18px; display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 4px 10px; font-size: 11px; text-align: right; }
.draft-state { color: var(--muted); }
.draft-notice { color: var(--blue-dark); }
.draft-notice.error { color: var(--danger); font-weight: 650; }
h2 { margin: 0; font-size: 17px; }
.intro-copy { min-width: 0; }
.intro-row > .intro-copy > p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.intro-row > .intro-copy > .option-count-summary { color: var(--text); font-weight: 600; }
.usage-details { max-width: 760px; margin-top: 7px; color: #4e5d70; font-size: 12px; overflow-wrap: anywhere; }
.usage-details summary { width: fit-content; max-width: 100%; color: var(--blue-dark); font-weight: 700; cursor: pointer; }
.usage-details summary::marker { color: var(--blue); }
.usage-content { margin-top: 7px; padding: 7px 0 2px 14px; border-left: 2px solid #c8d7e7; }
.usage-content ol, .usage-notes { margin: 0; padding-left: 22px; }
.usage-content li + li { margin-top: 2px; }
.usage-notes { margin-top: 8px; }
.usage-caution { margin-top: 10px; padding: 7px 9px; border-left: 3px solid #b99555; color: #65563e; background: #faf8f3; }
.usage-caution h3 { margin: 0 0 4px; color: #745c31; font-size: 12px; }
.usage-caution h3 span { margin-right: 3px; color: #a77b2d; }
.usage-caution p { margin: 0; color: inherit; font-size: 12px; }
.usage-caution p + p { margin-top: 5px; }
.load-status { color: var(--muted); font-size: 12px; white-space: nowrap; }
.load-status.error { color: var(--danger); font-weight: 650; }

.global-search-bar {
  margin-bottom: 10px;
  padding: 9px 10px;
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.global-search-bar label { color: #43566c; font-size: 12px; font-weight: 750; white-space: nowrap; }
.global-search-bar input { width: 100%; }
.global-search-status { min-width: 120px; color: var(--blue-dark); font-size: 12px; text-align: right; white-space: nowrap; }

.category-list { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.category-section { padding: 14px 15px; border-bottom: 1px solid var(--line); }
.category-section:last-child { border-bottom: 0; }
.category-section.global-match { background: #f2f7fc; box-shadow: inset 4px 0 0 var(--blue); }
.category-title-row { justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.category-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.category-number { color: var(--blue); font-size: 12px; font-weight: 750; }
.category-title h3 { margin: 0; font-size: 14px; }
.category-match-count { padding: 1px 6px; border-radius: 8px; color: #fff; background: var(--blue); font-size: 10px; font-weight: 750; white-space: nowrap; }
.category-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.random-skip { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 11px; white-space: nowrap; cursor: pointer; }
.random-skip input { width: 14px; height: 14px; min-height: 0; margin: 0; padding: 0; accent-color: var(--blue); }

.option-grid { display: grid; grid-template-columns: minmax(110px, .55fr) minmax(180px, 1fr); gap: 8px; }
.category-search { width: 100%; }
.option-controls { min-width: 0; gap: 7px; }
.option-select { flex: 1; min-width: 0; }
.button {
  min-height: 34px;
  padding: 5px 11px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: var(--blue);
  color: #fff;
  font-weight: 650;
  white-space: nowrap;
}
.button:hover { background: var(--blue-dark); }
.button:disabled { cursor: not-allowed; opacity: .55; }
.button-small { min-height: 28px; padding: 3px 8px; font-size: 12px; }
.button-secondary { border-color: var(--line-strong); color: var(--blue-dark); background: #fff; }
.button-secondary:hover { background: var(--blue-soft); }
.button-clear { min-height: auto; padding: 2px 4px; border: 0; color: var(--muted); background: transparent; font-size: 12px; }
.button-clear:hover { color: var(--danger); background: transparent; }
.button-danger { border-color: #d9b9bd; color: var(--danger); background: #fff; }
.button-danger:hover { background: #fff3f4; }

.option-detail {
  min-height: 34px;
  margin-top: 7px;
  padding: 7px 9px;
  display: grid;
  grid-template-columns: 5em minmax(0, 1fr);
  gap: 4px 12px;
  border-left: 3px solid #b8cee4;
  color: var(--muted);
  background: #f6f8fb;
  font-size: 12px;
  overflow-wrap: anywhere;
}
.detail-empty { grid-column: 1 / -1; }
.detail-label { color: #43566c; font-weight: 700; }
.detail-description { color: #4e5d70; }
.detail-status { color: #526981; }
.option-detail code { color: #315f91; font-family: Consolas, Monaco, monospace; }
.chips { min-height: 25px; margin-top: 7px; display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 5px 2px 8px;
  border: 1px solid #c7d8ea;
  border-radius: 8px;
  color: #294e75;
  background: var(--blue-soft);
  font-size: 12px;
}
.chip-label { min-width: 0; overflow-wrap: anywhere; }
.chip-remove { width: 19px; height: 19px; padding: 0; border: 0; color: #61758b; background: transparent; font-size: 16px; line-height: 1; }
.chip-remove:hover { color: var(--danger); }
.chips-empty { color: #8a94a2; font-size: 12px; }

.direct-tag-box { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--line); }
.direct-tag-box label { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 650; }
.direct-controls { gap: 7px; }
.direct-controls input { flex: 1; min-width: 0; }
.direct-help { margin: 3px 0 0; color: var(--muted); font-size: 11px; }

.output-panel {
  position: sticky;
  top: 84px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.output-head { justify-content: space-between; gap: 14px; padding-bottom: 11px; border-bottom: 1px solid var(--line); }
.output-kicker { margin: 0 0 1px; color: var(--blue); font-size: 10px; font-weight: 800; letter-spacing: .14em; }
.prompt-box { padding-top: 14px; }
.negative-box { margin-top: 14px; border-top: 1px solid var(--line); }
.prompt-label-row { justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.prompt-label-row label { font-weight: 700; }
.prompt-label-row label span { color: var(--muted); font-size: 12px; font-weight: 400; }
textarea { width: 100%; padding: 10px; resize: vertical; font-family: Consolas, Monaco, monospace; font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; }
textarea[readonly] { background: #f9fafc; }
.field-note { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.copy-notice { min-height: 20px; padding-top: 7px; color: var(--blue); font-size: 12px; text-align: right; }
.noscript { margin: 20px; color: var(--danger); }

.option-select option:disabled { color: #866c3b; }
body.modal-open { overflow: hidden; }
.batch-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: 24px;
  display: grid;
  place-items: center;
}
.batch-modal[hidden] { display: none; }
.batch-modal-backdrop { position: absolute; inset: 0; background: rgba(20, 31, 45, .58); }
.batch-modal-panel {
  position: relative;
  width: min(1180px, 100%);
  height: min(86vh, 820px);
  min-height: 460px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(20, 36, 54, .24);
  overflow: hidden;
  outline: none;
}
.batch-modal-header {
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}
.batch-modal-header > div { display: flex; align-items: center; gap: 8px; min-width: 0; }
.batch-modal-header h2 { min-width: 0; overflow-wrap: anywhere; }
.batch-modal-close { color: var(--blue); }
.batch-modal-search {
  padding: 10px 16px;
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.batch-modal-search label { color: #43566c; font-size: 12px; font-weight: 700; white-space: nowrap; }
.batch-modal-search input { width: 100%; }
.batch-modal-search span { min-width: 72px; color: var(--muted); font-size: 11px; text-align: right; white-space: nowrap; }
.batch-option-list {
  min-height: 0;
  padding: 13px 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  gap: 8px;
  overflow: auto;
  overscroll-behavior: contain;
}
.batch-option {
  position: relative;
  min-width: 0;
  min-height: 66px;
  padding: 9px 11px;
  display: grid;
  align-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
  text-align: left;
  overflow: hidden;
}
.batch-option:hover { border-color: #9eb9d4; background: #f7fbff; }
.batch-option:focus-visible { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(49, 95, 145, .16); outline: none; }
.batch-option.selected { border-color: var(--blue); background: var(--blue-soft); box-shadow: inset 3px 0 0 var(--blue); }
.batch-option.selected::after {
  content: "✓";
  position: absolute;
  top: 6px;
  right: 8px;
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 800;
}
.batch-option.added { border-color: #ddd4ba; background: #fbfaf6; cursor: default; opacity: .72; }
.batch-option-label { padding-right: 18px; font-size: 13px; font-weight: 700; overflow-wrap: anywhere; }
.batch-option-tags { color: var(--blue); font-family: Consolas, Monaco, monospace; font-size: 11px; overflow-wrap: anywhere; }
.batch-option-added { color: #79652f; font-size: 10px; font-weight: 750; }
.batch-option-empty { grid-column: 1 / -1; margin: 24px 0; color: var(--muted); text-align: center; }
.batch-modal-footer {
  padding: 11px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}
.batch-selection-info { min-width: 0; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; }
.batch-selection-info strong { color: var(--blue-dark); font-size: 13px; white-space: nowrap; }
.batch-selection-info span { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.batch-selection-info span.error { color: var(--danger); font-weight: 650; }
.batch-modal-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }

@media (max-width: 900px) {
  .batch-option-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-header { position: static; }
  .header-main { align-items: flex-start; flex-direction: column; gap: 8px; }
  .header-tools { width: 100%; justify-content: space-between; }
  .workspace { grid-template-columns: 1fr; }
  .output-panel { position: static; }
}

@media (max-width: 600px) {
  .header-main, .workspace { padding-left: 12px; padding-right: 12px; }
  .brand-block { width: 100%; align-items: flex-start; flex-direction: column; gap: 1px; }
  .brand-divider { display: none; }
  h1 { white-space: normal; }
  .header-tools { align-items: stretch; flex-direction: column-reverse; gap: 7px; }
  .model-field { justify-content: space-between; }
  .model-field select { flex: 1; }
  .back-link { align-self: flex-end; }
  .workspace { padding-top: 13px; gap: 14px; }
  .intro-row { align-items: flex-start; flex-direction: column; gap: 7px; }
  .builder-toolbar { width: 100%; align-items: stretch; }
  .usage-content { padding-left: 10px; }
  .usage-content ol, .usage-notes { padding-left: 19px; }
  .usage-caution { padding: 7px 8px; }
  .convenience-actions, .draft-actions { display: grid; grid-template-columns: 1fr; }
  .convenience-actions .button, .draft-actions .button { width: 100%; }
  .draft-status-line { justify-content: flex-start; text-align: left; }
  .load-status { white-space: normal; }
  .global-search-bar { grid-template-columns: 1fr; }
  .global-search-status { min-width: 0; text-align: left; white-space: normal; }
  .category-section { padding: 12px 10px; }
  .option-grid { grid-template-columns: 1fr; }
  .option-controls, .direct-controls { align-items: stretch; flex-direction: column; }
  .option-controls .button, .direct-controls .button { width: 100%; }
  .output-panel { padding: 12px 10px; }
  .batch-modal { padding: 8px; }
  .batch-modal-panel { width: 100%; height: calc(100vh - 16px); min-height: 0; }
  .batch-modal-header, .batch-modal-search, .batch-option-list, .batch-modal-footer { padding-left: 10px; padding-right: 10px; }
  .batch-modal-search { grid-template-columns: 1fr; gap: 4px; }
  .batch-modal-search span { min-width: 0; text-align: left; white-space: normal; }
  .batch-option-list { grid-template-columns: 1fr; padding-top: 9px; padding-bottom: 9px; }
  .batch-modal-footer { align-items: stretch; flex-direction: column; }
  .batch-modal-actions { display: grid; grid-template-columns: 1fr; }
  .batch-modal-actions .button { width: 100%; }
}

