:root {
  --page: #eef5ef;
  --surface: #ffffff;
  --soft: #f6faf6;
  --ink: #141713;
  --muted: #5d675c;
  --line: #d5dfd4;
  --teal: #008f84;
  --rose: #d94b66;
  --shadow: 0 16px 38px rgba(16, 30, 22, 0.12);
  --font-ui: Inter, "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    linear-gradient(90deg, rgba(0, 143, 132, 0.08) 0 1px, transparent 1px),
    linear-gradient(180deg, rgba(0, 143, 132, 0.08) 0 1px, transparent 1px),
    var(--page);
  background-size: 36px 36px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

img {
  display: block;
  max-width: 100%;
}

h1,
h2,
p,
ol {
  margin: 0;
}

ol {
  padding: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 330px minmax(440px, 1fr) 350px;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.library-panel,
.studio-panel {
  min-width: 0;
  min-height: 100vh;
  padding: 18px;
  overflow: auto;
  background: rgba(255, 255, 255, 0.88);
}

.library-panel {
  border-right: 1px solid var(--line);
  display: grid;
  align-content: start;
  gap: 14px;
}

.studio-panel {
  border-left: 1px solid var(--line);
  display: grid;
  align-content: start;
  gap: 14px;
}

.chat-panel {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: rgba(247, 251, 247, 0.78);
}

.brand-block,
.panel-section,
.stack-form,
.section-heading {
  display: grid;
  gap: 10px;
}

.brand-block h1 {
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0;
}

.brand-block p,
.panel-section p,
.note-list li,
.character-card span,
.character-card small,
.active-profile p,
.memory-strip p,
.bubble p {
  line-height: 1.52;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.brand-block p,
.panel-section p,
.note-list li,
.character-card span,
.character-card small,
.active-profile p,
.memory-strip p {
  color: var(--muted);
}

.eyebrow {
  color: var(--teal);
  font-size: 0.73rem;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.2;
  text-transform: uppercase;
}

.storage-pill,
.count-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 30px;
  border-radius: 8px;
  padding: 0 10px;
  color: #ffffff;
  background: var(--ink);
  font-size: 0.8rem;
  font-weight: 900;
}

.panel-section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(16, 30, 22, 0.05);
}

.section-heading h2 {
  font-size: 1.05rem;
  line-height: 1.2;
}

.row-heading {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.stack-form label {
  display: grid;
  gap: 7px;
}

.stack-form label span {
  font-size: 0.83rem;
  font-weight: 900;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--soft);
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 74px;
  padding: 11px 12px;
  line-height: 1.48;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(0, 143, 132, 0.22);
  outline-offset: 1px;
}

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

.primary-button,
.secondary-button,
.send-button {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 12px;
  font-weight: 900;
  transition: transform 160ms ease, background-color 160ms ease, color 160ms ease;
}

.primary-button,
.send-button {
  color: #ffffff;
  background: var(--teal);
}

.secondary-button {
  color: var(--ink);
  background: #edf4ed;
  border: 1px solid var(--line);
}

.danger-button {
  color: #8f2539;
  background: #fff1f3;
}

.compact-button {
  min-height: 34px;
}

.primary-button:hover,
.secondary-button:hover,
.send-button:hover {
  transform: translateY(-1px);
}

.character-list {
  display: grid;
  gap: 10px;
  max-height: 340px;
  overflow: auto;
  padding-right: 2px;
}

.character-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  min-height: 82px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  text-align: left;
}

.character-card.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(20, 23, 19, 0.1);
}

.character-card img {
  width: 58px;
  height: 66px;
  border-radius: 6px;
  object-fit: cover;
}

.character-card-body {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.character-card strong {
  font-size: 0.96rem;
  line-height: 1.25;
}

.character-card small {
  color: #6c570a;
  font-weight: 900;
}

.empty-note {
  padding: 12px;
  border-radius: 8px;
  background: var(--soft);
}

.chat-header,
.memory-strip,
.composer {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
}

.chat-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
}

.active-profile {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.active-profile img {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.active-profile h2 {
  margin-top: 4px;
  font-size: 1.45rem;
  line-height: 1.15;
}

.chat-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-content: flex-start;
  gap: 8px;
}

.memory-strip {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
}

.memory-strip p {
  margin-top: 5px;
}

.chat-log {
  display: grid;
  align-content: start;
  gap: 16px;
  overflow: auto;
  padding: 22px;
}

.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 11px;
  width: min(100%, 840px);
}

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

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

.message.user .bubble {
  grid-column: 1;
  grid-row: 1;
  color: #ffffff;
  background: var(--ink);
  border-color: var(--ink);
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.avatar-initial {
  display: grid;
  place-items: center;
  color: #ffffff;
  background: var(--teal);
  font-weight: 900;
}

.bubble {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.bubble-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.message.user .bubble-meta {
  color: rgba(255, 255, 255, 0.72);
}

.bubble p {
  white-space: pre-wrap;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--teal);
  animation: typing 900ms ease-in-out infinite;
}

.typing span:nth-child(2) {
  animation-delay: 120ms;
}

.typing span:nth-child(3) {
  animation-delay: 240ms;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.composer textarea {
  min-height: 48px;
  max-height: 150px;
  resize: none;
}

.send-button {
  min-width: 90px;
}

.style-studio {
  border-color: rgba(0, 143, 132, 0.35);
}

.prompt-preview-section {
  background: #fbfcfa;
}

.prompt-preview-section pre {
  max-height: 420px;
  overflow: auto;
  margin: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #f7fbf6;
  background: #141713;
  font-family: "Cascadia Mono", Consolas, "SFMono-Regular", monospace;
  font-size: 0.77rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.note-list {
  display: grid;
  gap: 9px;
}

.note-list li {
  list-style: none;
  padding: 10px 11px;
  border-radius: 8px;
  background: var(--soft);
}

.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;
}

@keyframes typing {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.42;
  }

  50% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@media (max-width: 1240px) {
  .app-shell {
    grid-template-columns: 320px minmax(0, 1fr);
    height: auto;
    overflow: visible;
  }

  .studio-panel {
    grid-column: 1 / -1;
    min-height: 0;
    border-left: 0;
    border-top: 1px solid var(--line);
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .library-panel,
  .studio-panel,
  .chat-panel {
    min-height: 0;
  }

  .library-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .studio-panel {
    grid-template-columns: 1fr;
  }

  .chat-header,
  .memory-strip {
    grid-template-columns: 1fr;
    display: grid;
  }

  .chat-actions {
    justify-content: flex-start;
  }

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

  .send-button {
    min-height: 46px;
  }
}

@media (max-width: 560px) {
  .library-panel,
  .studio-panel,
  .chat-header,
  .memory-strip,
  .chat-log,
  .composer {
    padding: 14px;
  }

  .button-grid {
    grid-template-columns: 1fr;
  }

  .brand-block h1 {
    font-size: 1.72rem;
  }

  .active-profile {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .active-profile img {
    width: 52px;
    height: 52px;
  }

  .message,
  .message.user {
    grid-template-columns: 1fr;
  }

  .message.user .avatar,
  .message.user .bubble {
    grid-column: 1;
    grid-row: auto;
  }

  .avatar {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
