* {
  box-sizing: border-box;
}

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

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

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

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

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

.scene-loading,
.scene-error {
  color: #9a5c37;
  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 #d8c7af;
  border-radius: 8px;
  background: #8b6f54;
  color: #fffaf2;
  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: #fff2df;
  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 #e2d2bd;
  border-radius: 8px;
  background: #fffaf2;
}

.action-config-field {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: #7d6750;
  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 #d8c7af;
  border-radius: 8px;
  background: #fffdf8;
  color: #2b2925;
  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: #9a5c37 !important;
}

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

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

.action-branch-item p {
  margin: 0;
  color: #4c4033;
  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: #8b6f54;
  color: #fffaf2;
}

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

.chat-shell {
  height: 100dvh;
  min-height: 100dvh;
  width: min(100%, 840px);
  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 1fr auto;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid #decfba;
  padding: 6px 0 14px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.diary-toggle-button,
.daily-close-button {
  min-height: 30px;
  padding: 0 10px;
  background: #d9c9b2;
  color: #44382c;
  font-size: 13px;
}

.settings-panel {
  border-top: 1px solid #decfba;
  margin-top: 0;
  padding-top: 8px;
}

.daily-entry-panel {
  position: fixed;
  z-index: 30;
  top: 78px;
  left: 50%;
  width: min(92vw, 840px);
  max-height: min(72dvh, 620px);
  overflow-y: auto;
  transform: translateX(-50%);
  border: 1px solid #e2d2bd;
  border-radius: 10px;
  background: #fffaf2;
  padding: 10px;
  box-shadow: 0 18px 50px rgba(68, 56, 44, 0.18);
}

.daily-entry-panel[hidden] {
  display: none;
}

.daily-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.daily-panel-title {
  min-height: 30px;
  display: flex;
  align-items: center;
  color: #856640;
  font-size: 14px;
  font-weight: 800;
}

.daily-entry-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(260px, 0.9fr);
  gap: 10px;
}

.daily-card,
.starter-card {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.daily-card label,
.starter-card label {
  color: #7d6750;
  font-size: 13px;
  font-weight: 800;
}

#diaryInput,
#starterPreview {
  width: 100%;
  min-width: 0;
  border: 1px solid #d8c7af;
  border-radius: 8px;
  background: #fffdf8;
  color: #2b2925;
  line-height: 1.5;
}

#starterPreview {
  min-height: 92px;
  color: #4c4033;
}

.daily-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.daily-actions button {
  min-height: 32px;
  padding: 0 11px;
  background: #8b6f54;
  color: #fffaf2;
  font-size: 13px;
}

.daily-actions button:nth-child(n + 2) {
  background: #d9c9b2;
  color: #44382c;
}

.settings-panel summary {
  width: max-content;
  min-height: 34px;
  display: flex;
  align-items: center;
  border-radius: 8px;
  color: #856640;
  cursor: pointer;
  font-weight: 700;
}

.settings-grid {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 0 0;
}

.settings-grid label,
.cost-hint {
  color: #7d6750;
  font-size: 13px;
}

select {
  min-height: 36px;
  border: 1px solid #d8c7af;
  border-radius: 8px;
  background: #fffaf2;
  color: #2b2925;
  padding: 0 8px;
}

select option {
  background: #fffaf2;
  color: #2b2925;
}

.settings-grid button {
  min-height: 36px;
  background: #8b6f54;
  color: #fffaf2;
}

.cost-hint {
  min-height: 18px;
  margin: 6px 0 0;
}

.trigger-panel {
  display: grid;
  gap: 8px;
  padding: 10px 0 0;
}

.trigger-title,
.mode-guide,
.trigger-empty {
  color: #7d6750;
  font-size: 13px;
}

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

.trigger-form input {
  min-height: 36px;
  min-width: 0;
  border: 1px solid #d8c7af;
  border-radius: 8px;
  background: #fffaf2;
  color: #2b2925;
  padding: 0 8px;
  font: inherit;
}

.trigger-list {
  display: grid;
  gap: 6px;
}

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

.trigger-item span {
  overflow-wrap: anywhere;
}

.trigger-item button {
  min-height: 28px;
  padding: 0 10px;
  background: #8b6f54;
  color: #fffaf2;
}

.mode-guide {
  margin: 0;
}

.memory-panel {
  display: grid;
  gap: 10px;
  padding: 10px 0 0;
}

.context-row {
  display: grid;
  grid-template-columns: auto 72px auto auto;
  gap: 8px;
  align-items: center;
}

.context-row label,
.context-row span,
.memory-note,
.memory-title,
.memory-subtitle,
.memory-empty {
  color: #7d6750;
  font-size: 13px;
}

.memory-title {
  font-weight: 700;
}

.context-row input,
.memory-form input,
.candidate-edit {
  min-height: 36px;
  min-width: 0;
  border: 1px solid #d8c7af;
  border-radius: 8px;
  background: #fffaf2;
  color: #2b2925;
  padding: 0 8px;
  font: inherit;
}

.memory-note {
  margin: 0;
}

.memory-section {
  display: grid;
  gap: 8px;
}

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

.memory-list,
.candidate-list {
  display: grid;
  gap: 6px;
}

.memory-item,
.candidate-item {
  display: grid;
  gap: 8px;
  min-height: 34px;
  padding: 8px;
  border: 1px solid #e2d2bd;
  border-radius: 8px;
  background: #fffaf2;
}

.memory-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.memory-item span,
.candidate-item span {
  overflow-wrap: anywhere;
}

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

.context-row button,
.memory-item button,
.candidate-item button {
  min-height: 28px;
  padding: 0 10px;
  background: #8b6f54;
  color: #fffaf2;
}

.prompt-panel {
  display: grid;
  gap: 8px;
  padding: 10px 0 0;
}

.prompt-title,
.prompt-note {
  color: #7d6750;
  font-size: 13px;
}

.prompt-title {
  font-weight: 700;
}

.prompt-input {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  line-height: 1.5;
}

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

.prompt-note {
  margin: 0;
  line-height: 1.45;
}

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

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

#modelBadge {
  font-size: 12px;
  color: #7d6750;
}

.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: #9a5c37;
}

.user {
  align-self: flex-end;
  background: #8b6f54;
  color: #fffaf2;
}

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

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

.composer-label {
  grid-column: 1 / -1;
  color: #7d6750;
  font-size: 13px;
  font-weight: 700;
}

.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 #e2d2bd;
  border-radius: 8px;
  overflow: hidden;
  background: #fffaf2;
}

.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(43, 41, 37, 0.82);
  color: #fffaf2;
}

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

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

.attach-button {
  background: #8b6f54;
  color: #fffaf2;
}

textarea,
select {
  border: 1px solid #d8c7af;
  border-radius: 8px;
  background: #fffaf2;
  color: #2b2925;
  font: inherit;
}

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

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

button:disabled,
.composer.sending button[type="submit"] {
  cursor: not-allowed;
  opacity: 0.62;
}

.status {
  min-height: 20px;
  margin: 8px 0 0;
  color: #9a5c37;
  font-size: 13px;
}

@media (max-width: 520px) {
  .settings-grid,
  .trigger-form,
  .context-row,
  .memory-form {
    grid-template-columns: 1fr;
  }

  .daily-entry-grid {
    grid-template-columns: 1fr;
  }

  .chat-shell {
    padding: 10px;
    gap: 6px;
  }

  .chat-header {
    padding: 2px 0 8px;
  }

  .title-row {
    gap: 6px;
  }

  .diary-toggle-button,
  .daily-close-button {
    min-height: 28px;
    padding: 0 9px;
    font-size: 12px;
  }

  .daily-entry-panel {
    top: 56px;
    width: calc(100vw - 20px);
    max-height: 78dvh;
    padding: 8px;
  }

  .daily-panel-title {
    min-height: 28px;
    font-size: 14px;
  }

  #diaryInput {
    min-height: 104px;
    max-height: 28dvh;
  }

  #starterPreview {
    min-height: 76px;
  }

  .daily-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .daily-actions button:first-child {
    grid-column: 1 / -1;
  }

  h1 {
    font-size: 18px;
  }

  .messages {
    padding: 8px 0;
  }

  .message {
    max-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 button {
    min-height: 38px;
    padding: 0 8px;
  }

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

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

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

/* 2026-07-02 rebuild pass: wider surface, hidden message actions, proxy controls. */
body {
  background:
    linear-gradient(135deg, rgba(48, 118, 110, 0.14), transparent 36%),
    linear-gradient(315deg, rgba(183, 95, 75, 0.12), transparent 42%),
    #edf4f0;
}

.chat-shell {
  width: min(100%, 1040px);
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
}

.chat-header {
  border-bottom-color: rgba(48, 118, 110, 0.24);
}

.chat-header a,
#modelBadge,
.settings-panel summary,
.composer-label,
.trigger-title,
.memory-title,
.memory-subtitle,
.prompt-title {
  color: #2f6f67;
}

.message {
  position: relative;
  transition: box-shadow 0.16s ease, transform 0.16s ease;
}

.user {
  background: #2f6f67;
}

.assistant {
  border-color: #d7e3dc;
  background: rgba(255, 255, 255, 0.96);
}

.message > .message-scene-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:focus-within > .message-scene-actions,
.message.actions-open > .message-scene-actions {
  max-height: 220px;
  margin-top: 8px;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.message-action-menu {
  justify-content: flex-start;
}

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

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

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

.action-menu-summary::after {
  content: "";
}

.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 #d7e3dc;
  border-radius: 8px;
  background: #fbfffc;
  box-shadow: 0 16px 40px rgba(23, 33, 31, 0.16);
}

.message-scene-actions button {
  min-height: 30px;
  padding: 0 10px;
  background: #2f6f67;
  color: #fff;
  font-size: 12px;
}

.proxy-toolbar,
.feedback-toolbar,
.response-mode-toolbar {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.proxy-toolbar button,
.feedback-toolbar button,
.response-mode-toolbar button {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #c8d8d0;
  background: rgba(255, 255, 255, 0.78);
  color: #234a46;
  font-size: 12px;
}

.proxy-toolbar button:first-child {
  background: #b75f4b;
  color: #fff8f1;
}

.feedback-toolbar {
  opacity: 0.92;
}

.feedback-toolbar button[data-feedback-score^="-"] {
  color: #8a3f34;
}

.response-mode-toolbar button.active {
  border-color: #2f6f67;
  background: #2f6f67;
  color: #fff;
}

.conversation-state-strip {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
  align-items: center;
}

.conversation-state-strip span {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #c8d8d0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.64);
  color: #325752;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
}

#proxyScoreBadge[data-state="complete"] {
  background: #2f6f67;
  color: #fff;
}

#proxyScoreBadge[data-state="discard"] {
  background: #b75f4b;
  color: #fff8f1;
}

.composer {
  border-top-color: rgba(48, 118, 110, 0.22);
  background: rgba(237, 244, 240, 0.92);
}

@media (max-width: 520px) {
  .chat-shell {
    width: 100%;
  }

  .action-menu-list {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    grid-template-columns: 1fr 1fr;
  }

  .proxy-toolbar,
  .feedback-toolbar,
  .response-mode-toolbar {
    scrollbar-width: none;
  }

  .proxy-toolbar::-webkit-scrollbar,
  .feedback-toolbar::-webkit-scrollbar,
  .response-mode-toolbar::-webkit-scrollbar {
    display: none;
  }
}
