* {
  box-sizing: border-box;
}

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

.app-shell {
  height: 100vh;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  background: #111820;
}

.thread-sidebar {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
  gap: 10px;
  border-right: 1px solid #263540;
  background: #0b1118;
  padding: 12px;
}

.sidebar-brand {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 42px;
}

.home-link {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid #263540;
  border-radius: 8px;
  color: #dce8ef;
  text-decoration: none;
  background: #111820;
}

.sidebar-kicker {
  color: #7890a2;
  font-size: 11px;
  font-weight: 700;
}

.sidebar-brand h1 {
  margin: 1px 0 0;
  font-size: 18px;
  line-height: 1.2;
}

.new-chat-button {
  min-height: 38px;
  width: 100%;
  border: 1px solid #33414d;
  border-radius: 8px;
  background: #d9e5ec;
  color: #111820;
  text-align: left;
}

.sidebar-section-title {
  color: #7890a2;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 4px 0;
}

.thread-list {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 4px;
  overflow-y: auto;
  padding-right: 2px;
}

.thread-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #dce8ef;
  text-align: left;
}

.thread-item:hover {
  background: #151f29;
  border-color: #263540;
}

.thread-item.active {
  background: #1f2a35;
  border-color: #425566;
}

.thread-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 700;
}

.thread-item-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #8fa8ba;
  font-size: 12px;
  font-weight: 600;
}

.sidebar-delete {
  min-height: 34px;
  width: 100%;
}

.mobile-thread-toggle,
.mobile-sidebar-scrim {
  display: none;
}

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

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #33414d;
  padding: 4px 0 10px;
}

.chat-header h2 {
  flex: 1;
}

.tool-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto minmax(110px, 150px);
  gap: 8px;
  align-items: center;
  padding: 0;
}

.tool-label,
.cost-hint {
  color: #9bb6c9;
  font-size: 13px;
}

.model-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.model-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #425566;
  border-radius: 4px;
  background: #17212b;
  color: #e8eef2;
  font: inherit;
  font-weight: 700;
}

.model-button.selected {
  border-color: #6aa6c9;
  background: #d9e5ec;
  color: #111820;
}

.length-select {
  width: 100%;
  min-height: 30px;
}

select {
  min-height: 32px;
  border: 1px solid #425566;
  border-radius: 4px;
  background: #17212b;
  color: #e8eef2;
  padding: 0 8px;
}

select option {
  background: #17212b;
  color: #e8eef2;
}

.danger-button {
  background: #4b3438 !important;
  color: #ffd9df !important;
}

.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: #9bb6c9;
  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 #425566;
  border-radius: 4px;
  background: #17212b;
  color: #e8eef2;
  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 #33414d;
  border-radius: 4px;
}

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

.trigger-item button {
  min-height: 28px;
  padding: 0 10px;
  background: #3d4650;
  color: #e8eef2;
}

.mode-guide {
  margin: 0;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(6, 11, 16, 0.72);
}

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

.settings-panel {
  width: min(760px, 100%);
  max-height: min(760px, calc(100vh - 32px));
  overflow-y: auto;
  border: 1px solid #33414d;
  border-radius: 8px;
  background: #111820;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.42);
  padding: 16px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #33414d;
  padding-bottom: 10px;
}

.settings-header h2 {
  margin: 0;
  font-size: 18px;
}

.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: #9bb6c9;
  font-size: 13px;
}

.context-row input,
.memory-form input,
.candidate-edit {
  min-height: 36px;
  min-width: 0;
  border: 1px solid #425566;
  border-radius: 4px;
  background: #17212b;
  color: #e8eef2;
  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;
}

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

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

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

.prompt-input {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid #425566;
  border-radius: 4px;
  background: #17212b;
  color: #e8eef2;
  padding: 10px;
  font: inherit;
  line-height: 1.5;
}

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

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

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

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

.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: #3d4650;
  color: #e8eef2;
}

@media (max-width: 520px) {
  .tool-row {
    grid-template-columns: 1fr;
    align-items: center;
  }

  .tool-label {
    grid-column: 1;
  }

  .model-buttons {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .model-button {
    min-height: 40px;
    padding: 0 6px;
    font-size: 14px;
  }

  .context-row,
  .memory-form {
    grid-template-columns: 1fr;
  }

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

  .composer {
    grid-template-columns: 1fr auto;
  }

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

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

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

.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;
  border-bottom: 1px solid #263540;
}

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

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

.message.unsaved {
  opacity: 0.7;
}

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

.user {
  align-self: flex-end;
  background: #d9e5ec;
  color: #111820;
}

.assistant {
  align-self: flex-start;
  background: #1f2a35;
  border: 1px solid #33414d;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: end;
  padding-top: 2px;
}

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

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

.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(6, 11, 16, 0.82);
  color: #e8eef2;
}

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

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

.attach-button {
  background: #3d4650;
  color: #e8eef2;
}

textarea {
  resize: none;
  border: 1px solid #425566;
  border-radius: 4px;
  padding: 10px;
  background: #17212b;
  color: #e8eef2;
  font: inherit;
}

button {
  border: 0;
  border-radius: 4px;
  padding: 0 18px;
  background: #6aa6c9;
  color: #071018;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.icon-button {
  min-height: 32px;
  padding: 0 12px;
  background: #263540;
  color: #dce8ef;
}

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

.status {
  min-height: 20px;
  margin: 8px 0 0;
  color: #f3b37c;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

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

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

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

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

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

.scene-loading,
.scene-error {
  color: #f3b37c;
  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 #4b5c68;
  border-radius: 8px;
  background: #26323d;
  color: #e8eef2;
  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: #9bb6c9;
  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 #33414d;
  border-radius: 8px;
  background: #111820;
}

.action-config-field {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: #9bb6c9;
  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 #4b5c68;
  border-radius: 8px;
  background: #17212b;
  color: #e8eef2;
  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: #4c3030 !important;
}

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

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

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

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

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    min-height: 100dvh;
    height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }

  .thread-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(320px, 86vw);
    height: 100dvh;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    gap: 8px;
    border-right: 1px solid #263540;
    border-bottom: 0;
    transform: translateX(-104%);
    transition: transform 160ms ease;
    box-shadow: 18px 0 42px rgba(0, 0, 0, 0.34);
  }

  body.sidebar-open .thread-sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .mobile-sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    background: rgba(3, 8, 13, 0.58);
  }

  .mobile-thread-toggle {
    display: inline-grid;
    min-height: 32px;
    place-items: center;
    padding: 0 12px;
    background: #263540;
    color: #dce8ef;
  }

  .thread-list {
    display: grid;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0 2px 0 0;
  }

  .thread-item {
    min-height: 44px;
    padding: 7px 9px;
  }

  .sidebar-delete {
    width: 100%;
  }

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

  .chat-header {
    padding: 0 0 7px;
  }

  .chat-header h2 {
    font-size: 18px;
  }

  .tool-row {
    grid-template-columns: minmax(0, 1fr) 94px;
    gap: 6px;
  }

  .tool-label {
    display: none;
  }

  .tool-row > .model-buttons {
    grid-column: 1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .model-button {
    min-height: 30px;
    padding: 0 4px;
    font-size: 13px;
  }

  .tool-row > .length-select {
    grid-column: 2;
    min-height: 30px;
    font-size: 13px;
    padding: 0 6px;
  }

  .cost-hint {
    display: none;
  }

  .messages {
    padding: 8px 0;
    border-bottom: 0;
  }

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

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

  .composer button {
    min-height: 38px;
    padding: 0 8px;
  }

  .status {
    min-height: 16px;
    margin: 2px 0 0;
    font-size: 12px;
  }
}

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

/* 2026-07-02 rebuild pass: hide answer actions until hover/focus/long-press state. */
.message {
  position: relative;
}

.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: 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 rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #151c24;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.24);
}

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