:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --surface: #eef3f6;
  --surface-strong: #e3ebef;
  --text: #182025;
  --muted: #60717d;
  --line: #d8e0e6;
  --accent: #1f6f8b;
  --accent-strong: #155a72;
  --accent-soft: #dcecf1;
  --copper: #a94f35;
  --copper-soft: #f7e5df;
  --gold: #b87916;
  --blue: #3157b8;
  --danger: #a83232;
  --shadow: 0 18px 40px rgba(29, 43, 52, 0.08);
  font-family:
    "Segoe UI",
    "Noto Sans JP",
    system-ui,
    -apple-system,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(31, 111, 139, 0.12), rgba(31, 111, 139, 0) 260px),
    var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(31, 111, 139, 0.18);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  min-height: 100vh;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1500px;
  margin: 0 auto 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--text);
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 900;
  letter-spacing: 0;
}

.brand-copy {
  min-width: 0;
}

h1 {
  font-size: 1.38rem;
  line-height: 1.15;
}

h2 {
  font-size: 1rem;
  line-height: 1.25;
}

.brand p,
.panel-head p,
.score-copy p {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.top-actions,
.panel-head,
.item-tools,
.segmented,
.toggle-grid {
  display: flex;
  align-items: center;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.segmented {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.segment {
  min-width: 58px;
  min-height: 44px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment:last-child {
  border-right: 0;
}

.segment.is-active {
  background: var(--accent);
  color: #ffffff;
}

.icon-button,
.tool-button {
  display: inline-grid;
  place-items: center;
  min-width: 48px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 900;
}

.icon-button {
  padding: 0 10px;
  text-decoration: none;
}

.icon-button:hover,
.tool-button:hover,
.secondary-action:hover,
.drag-handle:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.icon-button.danger:hover,
.tool-button.remove:hover {
  border-color: rgba(168, 50, 50, 0.48);
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(390px, 0.94fr);
  align-items: start;
  gap: 18px;
  max-width: 1500px;
  margin: 0 auto;
}

.editor-panel,
.preview-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.editor-panel {
  padding: 16px;
}

.preview-panel {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 16px;
  padding: 16px;
}

.panel-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.primary-action,
.secondary-action {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 13px;
  font-weight: 900;
  white-space: nowrap;
}

.primary-action {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary-action:hover {
  background: var(--accent-strong);
}

.secondary-action {
  border: 1px solid var(--blue);
  background: #ffffff;
  color: var(--blue);
}

.project-fields,
.reference-fields,
.control-grid {
  display: grid;
  gap: 12px;
}

.project-fields {
  grid-template-columns: minmax(0, 1fr) minmax(180px, 0.45fr);
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.reference-fields {
  grid-template-columns: 1fr 1fr;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.field-span-2 {
  grid-column: 1 / -1;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

label b {
  color: var(--text);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 16px;
  outline: none;
}

input,
select {
  min-height: 44px;
  padding: 8px 10px;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

textarea {
  resize: vertical;
  padding: 10px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(49, 87, 184, 0.14);
}

.item-list {
  display: grid;
  gap: 10px;
}

.prompt-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.prompt-item.is-dragging {
  opacity: 0.45;
}

.prompt-item.is-over-before,
.prompt-item.is-over-after {
  border-color: var(--gold);
}

.prompt-item.is-over-before::before,
.prompt-item.is-over-after::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  height: 3px;
  border-radius: 999px;
  background: var(--gold);
}

.prompt-item.is-over-before::before {
  top: -2px;
}

.prompt-item.is-over-after::after {
  bottom: -2px;
}

.item-main {
  display: grid;
  grid-template-columns: 46px 46px minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
}

.drag-handle {
  width: 46px;
  height: 44px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.is-reordering {
  overscroll-behavior: contain;
  cursor: grabbing;
  user-select: none;
  -webkit-user-select: none;
}

.priority-badge {
  display: grid;
  place-items: center;
  width: 46px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.84rem;
  font-weight: 900;
}

.item-fields {
  min-width: 0;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.include-toggle,
.toggle-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 900;
  white-space: nowrap;
}

.include-toggle {
  min-height: 44px;
  padding: 0 10px;
}

.include-toggle span,
.toggle-pill span {
  margin: 0;
  color: inherit;
  font-size: 0.82rem;
}

.include-toggle input,
.toggle-pill input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.content-field {
  display: block;
  margin-top: 10px;
}

.item-tools {
  align-content: start;
  flex-wrap: wrap;
  justify-content: flex-end;
  width: 110px;
  gap: 6px;
}

.tool-button {
  width: 52px;
  min-width: 52px;
  font-size: 1rem;
}

.tuning-panel,
.output-panel,
.share-panel {
  min-width: 0;
}

.control-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.toggle-grid {
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.toggle-pill {
  min-height: 44px;
  padding: 0 11px;
  background: var(--copper-soft);
}

.score-panel {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.score-ring {
  --score: 0%;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #ffffff 57%, transparent 58%),
    conic-gradient(var(--accent) var(--score), var(--surface-strong) 0);
  color: var(--accent-strong);
  font-weight: 900;
}

.score-copy {
  min-width: 0;
}

.markdown-head {
  margin-bottom: 10px;
}

#promptOutput {
  min-height: calc(100vh - 610px);
  max-height: calc(100vh - 430px);
  resize: vertical;
  font-family:
    "Cascadia Code",
    Consolas,
    "Courier New",
    monospace;
  font-size: 0.88rem;
  white-space: pre-wrap;
}

.qr-layout {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

#qrCanvas {
  width: 180px;
  height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

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

  .preview-panel {
    position: static;
  }

  #promptOutput {
    min-height: 360px;
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

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

  .top-actions {
    justify-content: flex-start;
  }

  .segmented {
    flex: 1 1 100%;
  }

  .segment {
    flex: 1 1 25%;
    min-width: 0;
  }

  h1 {
    font-size: 1.18rem;
  }

  .project-fields,
  .reference-fields,
  .control-grid,
  .qr-layout,
  .prompt-item,
  .item-main,
  .item-row {
    grid-template-columns: 1fr;
  }

  .field-span-2 {
    grid-column: auto;
  }

  .drag-handle,
  .priority-badge {
    width: 100%;
  }

  .item-tools {
    width: 100%;
    justify-content: flex-start;
  }

  .tool-button {
    width: 58px;
    min-width: 58px;
  }

  #qrCanvas {
    justify-self: center;
  }
}
