:root {
  color-scheme: light;
  --bg: #f4f1eb;
  --panel: #fbfaf7;
  --surface: #ffffff;
  --surface-alt: #f8f6f1;
  --text: #241d18;
  --muted: #6f6258;
  --line: rgba(78, 62, 48, 0.18);
  --accent: #7f6a58;
  --accent-dark: #5f4d3e;
  --danger: #b42318;
  --shadow: 0 12px 32px rgba(69, 55, 42, 0.08);
  --message-font-size: 15px;
  --display-font: "Sandoll Myeongjo", "SandollMyungjo", "Nanum Myeongjo",
    "NanumMyeongjo", "Batang", "Malgun Gothic", serif;
  --prompt-font: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html {
  scrollbar-gutter: stable both-edges;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--display-font);
  font-size: 16px;
}

body.night-mode {
  --bg: #161412;
  --panel: #1f1b18;
  --surface: #29231f;
  --surface-alt: #211d1a;
  --text: #f0e8dc;
  --muted: #b9aa9b;
  --line: rgba(232, 219, 202, 0.18);
  --accent: #b98f7e;
  --accent-dark: #cba493;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  width: min(902px, calc(100vw - 40px));
  min-height: calc(100vh - 72px);
  margin: 0 auto;
  padding: 20px 0 12px;
}

.chat,
.composer-inner,
.bubble,
.feedback-dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.new-chat {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-alt);
  padding: 0 14px;
  color: var(--text);
  font-weight: 700;
}

.new-chat:hover {
  background: #f0ebe3;
}

.chat {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  overflow: hidden;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 22px;
  background: var(--bg);
}

.message {
  display: grid;
  grid-template-columns: minmax(0, 820px);
  justify-content: center;
}

.message.user {
  justify-content: end;
  padding-left: 54px;
}

.message.assistant {
  justify-content: start;
  padding-right: 54px;
}

.bubble-wrap {
  display: grid;
  min-width: 0;
  gap: 8px;
}

.bubble {
  min-width: 0;
  padding: 15px 17px;
  color: var(--text);
  font-family: var(--prompt-font);
  font-size: var(--message-font-size);
  line-height: 1.72;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  background: var(--surface-alt);
  color: var(--text);
}

body.night-mode .message.user .bubble {
  background: #342d28;
  color: #f7efe4;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-self: start;
}

.message-action-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  justify-self: start;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 5px 2px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.copy-button::before {
  content: "";
  position: relative;
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 1.8px solid var(--muted);
  border-radius: 4px;
  box-shadow: -4px 4px 0 -1.8px var(--surface), -4px 4px 0 0 var(--muted);
  opacity: 0.9;
}

.improve-button {
  color: var(--accent-dark);
}

.intro-controls,
.footer-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.footer-controls {
  flex: 0 1 auto;
}

.footer-view-controls,
.footer-log-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.footer-log-controls {
  margin-top: 0;
}

.footer-log-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.footer-stats {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  min-width: 34px;
  text-align: right;
  white-space: nowrap;
}

.intro-controls {
  justify-self: start;
  margin-bottom: 2px;
}

.intro-control-button {
  display: inline-grid;
  min-width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-alt);
  color: var(--muted);
  font-family: var(--prompt-font);
  font-size: 15px;
  font-weight: 800;
  padding: 0 7px;
  text-decoration: none;
}

.intro-control-button:hover {
  color: var(--text);
  background: #eee8df;
}

body.night-mode .intro-control-button:hover {
  background: #342d28;
}

body.night-mode .new-chat:hover,
body.night-mode .composer .secondary-action:hover,
body.night-mode .feedback-actions .secondary-action:hover {
  background: #342d28;
  color: #f7efe4;
}

body.night-mode .composer button:hover,
body.night-mode .feedback-actions button:hover {
  background: #9d7667;
  color: #fff8ef;
}

.message-action-button:hover {
  color: var(--text);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 820px);
  justify-content: center;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 16px 22px 20px;
}

.composer-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px;
}

.composer-status {
  color: var(--muted);
  font-family: var(--prompt-font);
  font-size: 12px;
}

.composer-status.loading::before {
  content: "◷";
  display: inline-block;
  margin-right: 5px;
  animation: blink 0.8s steps(2, start) infinite;
}

.composer-status.error {
  color: var(--danger);
}

@keyframes blink {
  50% {
    opacity: 0.2;
  }
}

.composer textarea,
.feedback-form textarea {
  font-family: var(--prompt-font);
}

.composer textarea {
  max-height: min(52dvh, 520px);
  min-height: 74px;
  resize: none;
  border: 0;
  border-radius: 12px;
  padding: 9px 10px;
  color: var(--text);
  background: transparent;
  font-size: 15px;
  line-height: 1.65;
  outline: none;
}

.composer-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-self: end;
  gap: 7px;
}

.composer button,
.feedback-actions button {
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #ffffff;
  padding: 0 13px;
  font-weight: 800;
  font-size: 14px;
  line-height: 1.15;
}

.composer button span {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.78;
}

.composer button:hover,
.feedback-actions button:hover {
  background: var(--accent-dark);
}

.composer .secondary-action,
.feedback-actions .secondary-action {
  border: 1px solid var(--line);
  background: var(--surface-alt);
  color: var(--text);
}

.composer .secondary-action:hover,
.feedback-actions .secondary-action:hover {
  background: #eee8df;
}

.composer button:disabled,
.feedback-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.site-footer {
  display: flex;
  width: min(1180px, calc(100vw - 40px));
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex-wrap: nowrap;
  margin: 0 auto;
  padding: 0 0 16px;
  color: var(--muted);
  font-family: "Nanum Myeongjo", "NanumMyeongjo", "Batang", serif;
  font-size: 12px;
  white-space: nowrap;
}

.footer-controls {
  align-items: center;
  justify-content: center;
}

.site-footer button {
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  padding: 2px;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.session-select {
  max-width: 150px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-alt);
  color: var(--muted);
  font-family: var(--prompt-font);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
  outline: none;
}

.session-select:hover,
.session-select:focus {
  background: #eee8df;
  color: var(--text);
}

body.night-mode .session-select:hover,
body.night-mode .session-select:focus {
  background: #342d28;
  color: #f7efe4;
}

.feedback-dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
}

.feedback-dialog::backdrop {
  background: rgba(37, 29, 23, 0.24);
}

.feedback-form {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.feedback-form h2 {
  margin: 0;
  font-size: 22px;
}

.feedback-form textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  line-height: 1.6;
}

.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 760px) {
  body {
    font-size: 15px;
  }

  .app {
    grid-template-columns: 1fr;
    width: 100%;
    min-height: calc(100dvh - 52px);
    padding: 0;
  }

  .chat {
    min-height: calc(100dvh - 52px);
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .message {
    grid-template-columns: minmax(0, 1fr);
    justify-content: stretch;
  }

  .message.user {
    padding-left: 22px;
  }

  .message.assistant {
    padding-right: 22px;
  }

  .composer {
    position: sticky;
    bottom: 0;
    grid-template-columns: 1fr;
    padding: 10px 10px 12px;
  }

  .composer-inner {
    grid-template-columns: 1fr;
    border-radius: 16px;
    padding: 10px;
  }

  .messages {
    padding: 14px 12px;
  }

  .bubble {
    padding: 13px 14px;
    line-height: 1.68;
  }

  .composer textarea {
    min-height: 96px;
    max-height: 48dvh;
    font-size: 16px;
  }

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

  .composer button,
  .feedback-actions button {
    min-height: 44px;
    font-size: 14px;
  }

  .site-footer {
    width: 100%;
    gap: 6px;
    flex-wrap: wrap;
    padding: 8px 0 10px;
  }

  .footer-controls {
    width: auto;
  }

  .session-select {
    max-width: 140px;
  }
}
