:root {
  --page-bg: #0e171e;
  --chat-bg: #b8c7d4;
  --header-bg: #111b22;
  --header-line: #263640;
  --text: #f4f7f8;
  --muted: #9fb0ba;
  --incoming: #ffffff;
  --outgoing: #fee84d;
  --system: rgba(46, 61, 70, 0.72);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  background: var(--page-bg);
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

.chat-app {
  width: min(980px, 100vw);
  max-width: 100vw;
  height: var(--app-height, 100dvh);
  min-height: var(--app-height, 100dvh);
  margin: 0 auto;
  padding: 0;
  background: #0b141a;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-left: 1px solid #23333d;
  border-right: 1px solid #23333d;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  min-height: 64px;
  padding: 10px 14px 10px 16px;
  border-bottom: 1px solid var(--header-line);
  background: var(--header-bg);
}

.room-info {
  min-width: 0;
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: 19px;
  line-height: 1.25;
  font-weight: 850;
  letter-spacing: 0;
}

.chat-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  color: #dce8ed;
  background: transparent;
  cursor: pointer;
  font-size: 22px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 0;
}

.model-select {
  width: 150px;
  max-width: 38vw;
  height: 30px;
  padding: 0 26px 0 10px;
  border: 1px solid #334550;
  border-radius: 8px;
  background-color: #19262e;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23899caa' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  -webkit-appearance: none;
  appearance: none;
  color: #c8d8df;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s;
}

.model-select:hover {
  border-color: #4a6070;
  background-color: #1f3040;
}

.model-select:focus {
  border-color: #efcf32;
}

.model-select option {
  background: #19262e;
  color: #c8d8df;
}

.icon-btn:hover {
  background: #263640;
}

.chat-log {
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 16px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  scroll-behavior: smooth;
  background:
    linear-gradient(rgba(18, 31, 39, 0.12), rgba(18, 31, 39, 0.12)),
    var(--chat-bg);
}

.message {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 7px;
  max-width: 78%;
  min-width: 0;
  align-self: flex-start;
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 40px;
  align-self: flex-end;
}

.message.user .bubble-wrap {
  grid-column: 1;
  grid-row: 1;
}

.message.user .avatar {
  grid-column: 2;
}

.avatar {
  width: 40px;
  height: 40px;
  border: 1px solid #dce9ef;
  border-radius: 14px;
  object-fit: cover;
  object-position: center 18%;
  background: #edf4f7;
}

.avatar--seoan {
  object-position: center 9%;
  transform: scale(1.12);
}

.bubble-wrap {
  min-width: 0;
}

.author {
  margin: 0 0 3px 2px;
  color: #234250;
  font-size: 11px;
  font-weight: 850;
}

.message.user .author {
  text-align: right;
  color: #5f4b00;
}

.bubble {
  width: fit-content;
  max-width: 100%;
  padding: 9px 12px;
  border-radius: 17px 17px 17px 5px;
  color: #172126;
  background: var(--incoming);
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 2px 6px #00000018;
}

.message.user .bubble {
  margin-left: auto;
  border-radius: 17px 17px 5px 17px;
  color: #1d210c;
  background: var(--outgoing);
}

.system-message {
  align-self: center;
  max-width: min(88%, 460px);
  padding: 6px 11px;
  border-radius: 999px;
  color: #eef5f7;
  background: var(--system);
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 8px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  border-top: 1px solid #d2d9dc;
  background: #f3f4ef;
}

textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  max-height: 118px;
  resize: none;
  border: 1px solid #d7dddc;
  border-radius: 18px;
  padding: 11px 13px;
  color: #172126;
  background: #ffffff;
  outline: none;
  line-height: 1.35;
}

textarea:focus {
  border-color: #efcf32;
}

.composer button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 44px;
  border: 0;
  border-radius: 16px;
  color: #1d210c;
  background: var(--outgoing);
  cursor: pointer;
}

.composer button svg {
  width: 24px;
  height: 24px;
  transform: translateX(1px) rotate(-8deg);
  fill: currentColor;
}

.composer button:disabled {
  cursor: wait;
  filter: grayscale(0.8);
  opacity: 0.7;
}

@media (max-width: 720px) {
  .chat-app {
    width: 100vw;
  }

  .chat-panel {
    border: 0;
  }

  .message {
    max-width: 88%;
  }

  .chat-log {
    padding: 12px 10px 14px;
  }
}

@media (max-width: 420px) {
  .chat-header {
    gap: 8px;
    padding: 9px 8px 9px 12px;
  }

  h1 {
    font-size: 17px;
  }

  .chat-header p {
    max-width: 46vw;
  }

  .header-actions {
    gap: 4px;
  }

  .model-select {
    width: 104px;
    max-width: 30vw;
    padding-left: 7px;
    padding-right: 20px;
    background-position: right 6px center;
    font-size: 10px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
  }
}
