* {
  box-sizing: border-box;
}

.scene-card {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #bfd1ca;
  border-radius: 8px;
  background: #f7fbf9;
  white-space: normal;
}

.scene-intro,
.scene-interpretation {
  margin: 0;
  color: #243936;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.scene-image-link {
  display: block;
  overflow: hidden;
  border: 1px solid #bfd1ca;
  border-radius: 8px;
  background: #ffffff;
}

.scene-image-link img {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: cover;
}

.scene-caption {
  color: #5d716b;
  font-size: 12px;
  font-weight: 700;
}

.scene-loading,
.scene-error {
  color: #9a3f32;
  font-size: 13px;
}

.message-scene-actions {
  margin-top: 8px;
}

.message-action-menu {
  display: flex;
  align-items: flex-start;
}

.action-menu-details {
  position: relative;
  width: 100%;
}

.action-menu-summary {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border: 1px solid #6d9b91;
  border-radius: 8px;
  background: #3f6f68;
  color: #f4fbf8;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  list-style: none;
}

.action-menu-summary::-webkit-details-marker {
  display: none;
}

.action-menu-summary::after {
  content: "▾";
  color: #d8f2eb;
  font-size: 11px;
}

.action-menu-details[open] .action-menu-summary::after {
  content: "▴";
}

.action-menu-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.action-config-panel {
  gap: 12px;
}

.action-config-controls,
.action-config-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
}

.action-config-controls .action-config-field {
  flex: 1 1 180px;
}

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

.action-participant-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr)) minmax(180px, 2fr) auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid #bfd8d1;
  border-radius: 8px;
  background: #f4fbf8;
}

.action-config-field {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: #315e56;
  font-size: 12px;
  font-weight: 700;
}

.action-config-field input,
.action-config-field select,
.action-config-field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #98bcb3;
  border-radius: 8px;
  background: #ffffff;
  color: #18211f;
  font: inherit;
}

.action-config-field input,
.action-config-field select {
  min-height: 34px;
  padding: 0 8px;
}

.action-config-field textarea {
  min-height: 60px;
  padding: 8px;
  resize: vertical;
}

.action-config-remove {
  background: #9a3f32 !important;
}

.action-branch-list {
  display: grid;
  gap: 8px;
}

.action-branch-item {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid #bfd8d1;
  border-radius: 8px;
  background: #f4fbf8;
}

.action-branch-item p {
  margin: 0;
  color: #315e56;
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 760px) {
  .action-participant-row {
    grid-template-columns: 1fr;
  }
}

.message-scene-actions button {
  min-height: 30px;
  padding: 0 12px;
  background: #3f6f68;
  color: #f4fbf8;
}

.message-admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.message-edit-panel textarea {
  width: 100%;
  min-height: 140px;
  padding: 10px;
  border: 1px solid #98bcb3;
  border-radius: 8px;
  background: #ffffff;
  color: #18211f;
  font: inherit;
  resize: vertical;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef4f1;
  color: #18211f;
  overflow: hidden;
}

.chat-shell {
  height: 100dvh;
  min-height: 100dvh;
  width: min(100%, 880px);
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  gap: 8px;
  padding: 14px;
}

.chat-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(220px, auto) auto;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid #bfd1ca;
  padding: 6px 0 14px;
}

.chat-header a {
  color: #31675f;
  text-decoration: none;
}

h1 {
  margin: 0;
  font-size: 20px;
}

#modelBadge {
  font-size: 12px;
  color: #5d716b;
}

.thread-controls {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

.thread-controls select {
  width: 100%;
  min-width: 0;
}

.thread-controls button {
  min-height: 34px;
  white-space: nowrap;
  padding: 0 12px;
}

.messages {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 12px 0;
}

.message {
  flex: 0 0 auto;
  max-width: 84%;
  padding: 10px 12px;
  border-radius: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.message.unsaved {
  opacity: 0.72;
}

.message.unsaved::after {
  content: "저장되지 않음";
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: #b4533c;
}

.user {
  align-self: flex-end;
  background: #214b5b;
  color: #f5fbff;
}

.assistant {
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid #cddbd6;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: end;
  border-top: 1px solid #bfd1ca;
  padding-top: 10px;
}

.composer-label,
.settings-grid label,
.panel-title,
.prompt-note,
.status-line {
  color: #5d716b;
  font-size: 13px;
  font-weight: 700;
}

.composer-label {
  grid-column: 1 / -1;
}

.attachment-preview {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  min-height: 58px;
  padding: 4px 0;
}

.attachment-preview[hidden] {
  display: none;
}

.attachment-chip {
  position: relative;
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  border: 1px solid #bfd1ca;
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
}

.attachment-chip img,
.message-attachment img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attachment-chip button {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 999px;
  background: rgba(24, 33, 31, 0.82);
  color: #ffffff;
}

.message-attachment {
  display: block;
  width: min(280px, 100%);
  max-height: 320px;
  margin-top: 8px;
  overflow: hidden;
  border: 1px solid #bfd1ca;
  border-radius: 8px;
  background: #ffffff;
}

.message-attachment img {
  height: auto;
  max-height: 320px;
}

.attach-button {
  background: #5d716b;
  color: #ffffff;
}

textarea,
select {
  border: 1px solid #b7cbc4;
  border-radius: 8px;
  background: #ffffff;
  color: #18211f;
  font: inherit;
}

textarea {
  resize: vertical;
  min-width: 0;
  padding: 10px;
}

select {
  min-height: 36px;
  padding: 0 8px;
}

select option {
  background: #ffffff;
  color: #18211f;
}

button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: #3f6f68;
  color: #f4fbf8;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:disabled,
.composer.sending button[type="submit"] {
  opacity: 0.58;
  cursor: default;
}

.settings-panel {
  display: block;
  margin-top: 0;
  padding: 14px;
  border: 1px solid #bfd1ca;
  border-radius: 8px;
  background: #f8fbfa;
}

.settings-panel > summary {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #315e56;
  cursor: pointer;
  font-size: 15px;
  font-weight: 800;
  list-style: none;
}

.settings-panel > summary::-webkit-details-marker {
  display: none;
}

.settings-panel > summary::before {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid #3f6f68;
  border-bottom: 2px solid #3f6f68;
  transform: rotate(45deg);
}

.settings-panel[open] > summary::before {
  transform: rotate(225deg);
  margin-top: 4px;
}

.style-test-panel {
  display: block;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #bfd1ca;
  border-radius: 8px;
  background: #f8fbfa;
}

.style-test-panel summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: #315e56;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  list-style: none;
}

.style-test-panel summary::-webkit-details-marker {
  display: none;
}

.style-test-panel summary::before {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid #3f6f68;
  border-bottom: 2px solid #3f6f68;
  transform: rotate(45deg);
}

.style-test-panel[open] summary::before {
  transform: rotate(225deg);
  margin-top: 4px;
}

.style-test-grid {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(100px, 120px) minmax(110px, 130px) minmax(150px, 180px) auto;
  gap: 8px;
  align-items: end;
  margin-top: 8px;
}

.style-test-grid label,
.style-extra-field {
  display: grid;
  gap: 4px;
  color: #5d716b;
  font-size: 12px;
  font-weight: 700;
}

.style-test-grid select,
.style-extra-field textarea {
  width: 100%;
}

.style-extra-field {
  margin-top: 8px;
}

.style-mode-note {
  margin: 8px 0 0;
  color: #5d716b;
  font-size: 12px;
  line-height: 1.45;
}

.style-extra-field textarea {
  min-height: 68px;
  max-height: 160px;
  line-height: 1.45;
  resize: vertical;
}

.style-test-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.style-test-buttons button,
.style-test-grid button {
  min-height: 32px;
  padding: 0 10px;
  white-space: nowrap;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding-top: 4px;
}

.settings-grid select {
  width: 100%;
}

.settings-grid button {
  white-space: nowrap;
}

.status-line {
  min-height: 18px;
  margin: 8px 0 0;
  color: #7d4d34;
}

.status-line.error {
  color: #b4533c;
}

.settings-sections {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #d6e3df;
}

.prompt-panel,
.scene-trigger-panel {
  display: grid;
  gap: 10px;
}

.panel-title {
  color: #315e56;
  font-size: 14px;
}

.prompt-input {
  width: 100%;
  min-height: clamp(240px, 32vh, 420px);
  line-height: 1.55;
  resize: vertical;
}

.prompt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.prompt-note {
  margin: 0;
  color: #5d716b;
  font-weight: 600;
  line-height: 1.45;
}

.trigger-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.trigger-form input {
  width: 100%;
  min-height: 36px;
  min-width: 0;
  border: 1px solid #b7cbc4;
  border-radius: 8px;
  background: #ffffff;
  color: #18211f;
  padding: 0 10px;
  font: inherit;
}

.trigger-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.trigger-empty {
  margin: 0;
  color: #5d716b;
  font-size: 13px;
}

.trigger-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 6px 8px;
  border: 1px solid #d6e3df;
  border-radius: 8px;
  background: #ffffff;
}

.trigger-item span {
  min-width: 0;
  color: #243936;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.trigger-item button {
  min-height: 30px;
  padding: 0 10px;
  background: #7d4d42;
}

.status {
  min-height: 20px;
  margin: 10px 0 0;
  color: #7d4d34;
  font-size: 13px;
  font-weight: 700;
}

@media (min-width: 1040px) {
  .chat-shell {
    width: min(100%, 1040px);
  }
}

@media (min-width: 860px) {
  .settings-sections {
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.85fr);
    align-items: start;
  }

  .scene-trigger-panel .trigger-list {
    grid-template-columns: 1fr;
  }
}

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

  .chat-header {
    grid-template-columns: auto minmax(0, 1fr);
    padding: 2px 0 8px;
  }

  .thread-controls {
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 6px;
  }

  #modelBadge {
    display: none;
  }

  h1 {
    font-size: 18px;
  }

  .messages {
    padding: 8px 0;
  }

  .style-test-panel {
    padding: 8px 10px;
  }

  .style-test-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .style-extra-field textarea {
    min-height: 58px;
    max-height: 108px;
  }

  .composer,
  .settings-grid,
  .trigger-form {
    grid-template-columns: 1fr;
  }

  .composer button,
  .settings-grid button,
  .trigger-form button {
    width: 100%;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 68px 54px;
    gap: 6px;
    padding-top: 6px;
  }

  .composer-label {
    display: none;
  }

  .composer textarea {
    min-height: 48px;
    max-height: 128px;
  }

  .composer .attach-button,
  .composer button[type="submit"] {
    width: auto;
    min-height: 38px;
    padding: 0 8px;
  }

  .settings-panel {
    max-height: 46dvh;
    overflow-y: auto;
    padding: 12px;
  }

  .settings-panel > summary {
    min-height: 28px;
    font-size: 14px;
  }

  .prompt-input {
    min-height: 220px;
  }

  .status {
    min-height: 16px;
    margin: 0;
  }
}

/* 2026-07-02 rebuild pass: keep answer actions out of the reading flow. */
.message {
  position: relative;
}

.message > .message-scene-actions,
.message > .message-admin-actions {
  max-height: 0;
  margin-top: 0;
  opacity: 0;
  overflow: visible;
  pointer-events: none;
  transform: translateY(-2px);
  transition: opacity 0.15s ease, transform 0.15s ease, max-height 0.15s ease, margin-top 0.15s ease;
}

.message:hover > .message-scene-actions,
.message:hover > .message-admin-actions,
.message:focus-within > .message-scene-actions,
.message:focus-within > .message-admin-actions,
.message.actions-open > .message-scene-actions,
.message.actions-open > .message-admin-actions {
  max-height: 260px;
  margin-top: 8px;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.action-menu-details {
  width: auto;
}

.action-menu-summary {
  min-width: 34px;
  width: 34px;
  min-height: 30px;
  justify-content: center;
  padding: 0;
  border-radius: 999px;
  font-size: 0;
}

.action-menu-summary::before {
  content: "...";
  color: #fff;
  font-size: 16px;
  line-height: 1;
}

.action-menu-summary::after,
.action-menu-details[open] .action-menu-summary::after {
  content: "";
}

.action-menu-list {
  position: absolute;
  z-index: 20;
  left: 0;
  bottom: calc(100% + 6px);
  width: min(360px, 82vw);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 0;
  padding: 8px;
  border: 1px solid #d3ddd8;
  border-radius: 8px;
  background: #fbfffc;
  box-shadow: 0 16px 40px rgba(23, 33, 31, 0.16);
}

@media (max-width: 520px) {
  .action-menu-list {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    grid-template-columns: 1fr 1fr;
  }
}
