:root {
  color-scheme: light;
  --chat-bg: #b7c9dc;
  --header-bg: #a8bbcf;
  --page-bg-spot: rgba(254, 229, 0, 0.22);
  --page-bg-start: #eef5f7;
  --page-bg-end: #d9e4ed;
  --ink: #1f2329;
  --muted: #66717f;
  --bubble-user: #fee500;
  --bubble-ai: #ffffff;
  --composer-bg: #ffffff;
  --header-caption: rgba(31, 35, 41, 0.62);
  --clear-bg: rgba(255, 255, 255, 0.42);
  --time: rgba(31, 35, 41, 0.48);
  --button: #2c2f35;
  --line: rgba(31, 35, 41, 0.12);
  --shadow: rgba(24, 32, 43, 0.22);
}

[data-theme="dark"] {
  color-scheme: dark;
  --chat-bg: #293644;
  --header-bg: #1f2b37;
  --page-bg-spot: rgba(255, 179, 44, 0.18);
  --page-bg-start: #0f1218;
  --page-bg-end: #18202a;
  --ink: #f4f7fb;
  --muted: #a9b2c3;
  --bubble-user: #5068f2;
  --bubble-ai: #151b24;
  --composer-bg: #111720;
  --header-caption: rgba(244, 247, 251, 0.62);
  --clear-bg: rgba(255, 255, 255, 0.1);
  --time: rgba(244, 247, 251, 0.48);
  --button: #fee500;
  --line: rgba(255, 255, 255, 0.13);
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: "Inter", "Noto Sans KR", system-ui, sans-serif;
  background:
    radial-gradient(circle at 18% 16%, var(--page-bg-spot), transparent 30%),
    linear-gradient(135deg, var(--page-bg-start), var(--page-bg-end));
  color: var(--ink);
  transition:
    background-color 0.25s ease,
    color 0.25s ease;
}

button,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.chat-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 28px;
}

.chat-phone {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(430px, 100%);
  height: min(780px, calc(100vh - 56px));
  height: min(780px, calc(100dvh - 56px));
  min-height: 620px;
  overflow: hidden;
  border: 10px solid #11131a;
  border-radius: 42px;
  background: var(--chat-bg);
  box-shadow: 0 42px 100px var(--shadow);
}

.chat-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
}

.back-link {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 34px;
  line-height: 1;
}

.chat-header h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.chat-header p {
  margin: 3px 0 0;
  color: var(--header-caption);
  font-size: 12px;
  font-weight: 700;
}

.clear-chat {
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: var(--clear-bg);
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 18px 16px;
  overflow-y: auto;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 86%;
}

.message-row.ai {
  align-self: flex-start;
}

.message-row.user {
  align-self: flex-end;
  justify-content: flex-end;
}

.avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 14px;
  background: #fee500;
  color: #271f1f;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(31, 35, 41, 0.12);
}

.bubble {
  position: relative;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: 16px;
  line-height: 1.48;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
  box-shadow: 0 6px 14px rgba(31, 35, 41, 0.08);
}

.ai .bubble {
  border-top-left-radius: 4px;
  background: var(--bubble-ai);
}

.user .bubble {
  border-top-right-radius: 4px;
  background: var(--bubble-user);
}

.message-time {
  align-self: flex-end;
  color: var(--time);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.typing .bubble {
  color: var(--muted);
}

.chat-composer {
  position: sticky;
  bottom: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  align-items: center;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: var(--composer-bg);
  border-top: 1px solid var(--line);
}

.chat-composer textarea {
  min-width: 0;
  width: 100%;
  max-height: 110px;
  min-height: 40px;
  height: 40px;
  resize: none;
  overflow-y: auto;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  outline: none;
  background: var(--bubble-ai);
  color: var(--ink);
  line-height: 20px;
}

.chat-composer textarea:focus {
  border-color: rgba(44, 47, 53, 0.34);
  box-shadow: 0 0 0 3px rgba(254, 229, 0, 0.24);
}

.chat-composer button {
  min-width: 58px;
  min-height: 40px;
  border: 0;
  border-radius: 18px;
  background: var(--button);
  color: var(--composer-bg);
  cursor: pointer;
  font-weight: 900;
}

.chat-composer button:disabled,
.clear-chat:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

@media (max-width: 520px) {
  .chat-page {
    height: var(--mango-viewport-height, 100dvh);
    min-height: 0;
    padding: 0;
    overflow: hidden;
  }

  .chat-phone {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    height: var(--mango-viewport-height, 100dvh);
    min-height: 0;
    border: 0;
    border-radius: 0;
  }

  .mango-keyboard-open .chat-phone {
    grid-template-rows: 0 1fr auto;
  }

  .mango-keyboard-open .chat-header {
    min-height: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    border-bottom: 0;
  }
}
