* { box-sizing: border-box; }
:root {
  color-scheme: dark;
  font-family: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  color: #f8eadd;
  background: #1d1515;
  --header-height: 62px;
  --section-header-height: 51px;
  --line: #503834;
  --soft-line: #ffffff11;
  --panel: #251b1b;
  --muted: #c5aaa0;
  --accent: #ffb481;
  --accent-ink: #281711;
  --error: #ffc0b1;
}
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 2px solid #ffc296; outline-offset: 3px; }

.shell {
  display: grid;
  grid-template-rows: var(--header-height) minmax(0, 1fr);
  height: max(450px, 100dvh);
}
.app-header {
  position: relative;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 clamp(14px, 2vw, 30px);
  gap: 12px;
  background: #211817;
  border-bottom: 1px solid var(--line);
}
.header-start, .brand { display: flex; align-items: center; }
.header-start { gap: clamp(14px, 2.4vw, 36px); }
.brand { gap: 9px; font-size: 1rem; font-weight: 850; letter-spacing: -.035em; white-space: nowrap; }
.brand-icon { width: 32px; height: 32px; display: block; border-radius: 7px; }
.panel-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  white-space: nowrap;
  background: #211817;
  color: var(--muted);
  font-size: .83rem;
  font-weight: 710;
}
.panel-toggle:hover, .panel-toggle[aria-expanded="true"] { color: #ffdfc6; background: #352522; }
.panel-icon {
  position: relative;
  width: 15px;
  height: 12px;
  border: 1px solid currentColor;
  border-radius: 2px;
}
.panel-icon::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 4px;
  border-left: 1px solid currentColor;
}
.panel-icon-end::after { inset-inline: auto 4px; }

.layout {
  --sessions-width: clamp(210px, 17vw, 256px);
  --history-width: clamp(280px, 24vw, 400px);
  --sessions-track: 0px;
  --history-track: 0px;
  --panel-motion: 240ms cubic-bezier(.22, .72, .28, 1);
  display: grid;
  grid-template-columns: var(--sessions-track) minmax(0, 1fr) var(--history-track);
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  position: relative;
  overflow: clip;
  transition: grid-template-columns var(--panel-motion);
}
.layout.sessions-open { --sessions-track: var(--sessions-width); }
.layout.history-open { --history-track: var(--history-width); }
.layout.resizing { transition: none; cursor: col-resize; user-select: none; }
.panel-rail {
  position: relative;
  grid-row: 1;
  min-width: 0;
  overflow: clip;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--panel-motion), visibility var(--panel-motion) allow-discrete;
}
.sessions-rail { grid-column: 1; }
.history-rail { grid-column: 3; }
.sessions-open .sessions-rail, .history-open .history-rail { opacity: 1; visibility: visible; }
.sidebar {
  position: absolute;
  inset-block: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}
.sessions-panel { left: 0; width: var(--sessions-width); border-right: 1px solid var(--line); }
.history-panel { right: 0; width: var(--history-width); border-left: 1px solid var(--line); }
.history-resizer {
  position: absolute;
  inset: 0 auto 0 0;
  width: 12px;
  cursor: col-resize;
  touch-action: none;
}
.history-resizer::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 2px;
  background: var(--accent);
  opacity: 0;
}
.history-resizer::after {
  content: "";
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 2px;
  width: 4px;
  height: 35px;
  translate: 0 -50%;
  border-radius: 4px;
  background: #9b6a53;
}
.history-resizer:hover::before, .history-resizer:focus-visible::before, .resizing .history-resizer::before { opacity: 1; }
.history-resizer:focus-visible { outline-offset: -2px; }
.sidebar-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  min-height: var(--section-header-height);
  padding: 0 17px;
}
.sidebar-header h2 { margin: 0; font-size: 1rem; letter-spacing: -.045em; }
.history-panel .sidebar-header { border-bottom: 1px solid var(--soft-line); }
.new-chat {
  margin: 4px 15px 15px;
  min-height: 42px;
  padding: 0 12px;
  text-align: left;
  color: #ffdfc4;
  background: #3f2b25;
  border: 1px solid #755043;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 780;
}
.new-chat span { display: inline-block; margin-right: 4px; color: var(--accent); font-size: 1.05rem; }
.new-chat:hover { background: #50332a; border-color: #ac7558; }
.session-scroll, .messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #79584f transparent;
  overscroll-behavior: contain;
}
.session-scroll { padding: 0 12px 10px; }
.muted { color: var(--muted); font-size: .84rem; line-height: 1.55; }
p.muted { margin: 7px 4px; }
.panel-notice { padding: 0 5px; }
.panel-notice p { margin: 4px 0; font-size: .84rem; color: var(--error); }
.session-list { margin: 0; padding: 0; display: grid; gap: 5px; list-style: none; }
.session-item { min-width: 0; border: 1px solid transparent; border-radius: 8px; }
.session-item:has([aria-current]) { border-color: #6d4a3f; background: #3a2824; }
.session-select {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 9px 10px;
  text-align: left;
  background: transparent;
}
.session-select:hover { background: #ffffff0a; }
.session-title {
  width: 100%;
  overflow: hidden;
  color: #f4e2d4;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .88rem;
  font-weight: 690;
}
.session-date { color: var(--muted); font-size: .71rem; }
.session-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 7px 5px; }
.text-button {
  min-height: 30px;
  padding: 3px 6px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--accent);
  font-size: .8rem;
  font-weight: 700;
}
.text-button:hover { color: #ffdfc4; background: #ffffff0b; }
.session-actions [data-action="delete"] { color: #e2aca1; }
.report-recovery { margin-top: 12px; padding-top: 7px; border-top: 1px solid var(--soft-line); }
.report-recovery button {
  display: block;
  width: 100%;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.settings { padding: 7px 16px 12px; border-top: 1px solid var(--line); }
.settings summary { padding: 7px 3px; color: var(--muted); cursor: pointer; font-size: .86rem; font-weight: 730; }
.settings summary:hover { color: #ffdfc6; }
.sound {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 38px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #291f1e;
  font-size: .83rem;
}
.sound b { color: var(--muted); }
.sound:hover, .sound[aria-pressed="true"] { border-color: #a36a54; }
.sound[aria-pressed="true"] b { color: var(--accent); }

.office {
  container: office / inline-size;
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  position: relative;
  isolation: isolate;
  overflow: clip;
  background: radial-gradient(ellipse at 32% 64%, #5a3021, #35221d 43%, #221818 76%);
}
.office::before {
  content: "";
  position: absolute;
  grid-row: 2 / -1;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(180deg, #20161526, transparent 45%, #1c13123b),
    url("./assets/office-background.webp") center 57% / cover no-repeat;
}
.office-header {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: var(--section-header-height);
  border-bottom: 1px solid var(--soft-line);
  padding: 0 clamp(16px, 3.2vw, 44px);
}
.office-header h1 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .99rem;
  letter-spacing: -.025em;
  color: #e4c9b9;
}
.scene {
  --speech-offset: clamp(36px, 11dvh, 118px);
  min-width: 0;
  min-height: 0;
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1.38fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  padding-inline: clamp(12px, 2.5vw, 42px);
}
.stage {
  position: relative;
  display: grid;
  place-items: end center;
  min-height: 0;
  min-width: 0;
  container-type: size;
  --glow: #e2a16728;
}
.stage[data-reaction="hearts"] { --glow: #ff8c864b; }
.stage[data-reaction="growl"], .stage[data-reaction="roar"] { --glow: #f47a3a56; }
.scenery {
  position: absolute;
  inset: 6% -10% 0 -9%;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 56%, var(--glow), transparent 66%);
}
#boss, .boss-still {
  position: absolute;
  bottom: 0;
  left: 54%;
  translate: -50% 0;
  width: min(147%, 100cqh, 897px);
  height: auto;
  filter: drop-shadow(0 12px 16px #180e0ba6);
}
.boss-still { aspect-ratio: 1; object-fit: contain; }
.effects { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.fx-heart {
  position: absolute;
  left: var(--x);
  top: var(--y);
  color: #ffd4ce;
  text-shadow: 0 2px 1px #912d42;
  font-size: clamp(21px, 5vw, 54px);
  line-height: 1;
  opacity: 0;
  animation: rise 700ms var(--delay) ease-out both;
}
@keyframes rise {
  0% { opacity: 0; transform: translate(-50%, 8px) rotate(var(--angle)) scale(.18); }
  23%, 62% { opacity: 1; }
  26% { transform: translate(-50%, -6px) rotate(var(--angle)) scale(1.14); }
  100% { opacity: 0; transform: translate(-50%, -58px) rotate(var(--angle)) scale(.68); }
}
.fx-stroke {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 11%;
  height: clamp(3px, .6vw, 8px);
  background: #fff0c4;
  opacity: 0;
  transform-origin: left center;
  clip-path: polygon(0 42%, 100% 0, 100% 100%, 0 64%);
  animation: stroke 410ms var(--delay) ease-out both;
}
@keyframes stroke {
  0% { opacity: 0; transform: rotate(var(--angle)) scaleX(.2); }
  15% { opacity: .95; transform: rotate(var(--angle)) scaleX(1.1); }
  64% { opacity: .84; }
  100% { opacity: 0; transform: rotate(var(--angle)) translateX(18%) scaleX(.94); }
}
.exchange {
  align-self: start;
  min-width: 0;
  width: min(100%, 510px);
  max-height: calc(100% - var(--speech-offset) - 14px);
  margin-top: var(--speech-offset);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.pending-report {
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  align-self: flex-end;
  min-height: 0;
  max-height: min(18dvh, 148px);
  max-width: min(100%, 36em);
  padding: 9px 12px;
  color: #ffecdf;
  border: 1px solid #92624e;
  border-radius: 10px 10px 2px 10px;
  background: #493028;
  font-size: .86rem;
  line-height: 1.55;
}
.pending-report .author { flex-shrink: 0; color: #edd0bd; }
.pending-report p { min-height: 0; overflow: auto; scrollbar-width: thin; }
.speech {
  --bubble: #342421;
  --bubble-line: #895947;
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: clamp(14px, 1.65vw, 24px);
  border: 1px solid var(--bubble-line);
  border-radius: 13px;
  background: var(--bubble);
  box-shadow: 0 12px 28px #170d0b53;
}
.speech::before {
  content: "";
  position: absolute;
  top: 52px;
  right: 100%;
  width: 12px;
  height: 14px;
  background: var(--bubble-line);
  clip-path: polygon(0 94%, 100% 0, 100% 100%);
}
.speech::after {
  content: "";
  position: absolute;
  top: 53px;
  right: calc(100% - 1px);
  width: 12px;
  height: 12px;
  background: var(--bubble);
  clip-path: polygon(0 94%, 100% 0, 100% 100%);
}
.speech-header { display: flex; flex-shrink: 0; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px; }
.speaker { color: var(--accent); font-weight: 820; font-size: .88rem; }
.reaction { font-size: .75rem; color: var(--muted); }
.speech-content {
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #79584f transparent;
  color: #fff2e5;
  font-size: clamp(.89rem, 1.35vw, 1.12rem);
  font-weight: 580;
  line-height: 1.65;
}
.speech-content:focus-visible { outline-offset: -2px; }
.speech-content p, .pending-report p, .message p, .source blockquote { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.questions { margin: 10px 0 0; padding-inline-start: 1.25em; display: grid; gap: 5px; overflow-wrap: anywhere; }
.questions li::marker { color: var(--accent); }
.evidence-link {
  align-self: flex-start;
  flex-shrink: 0;
  min-height: 34px;
  padding: 0 9px;
  border: 1px solid #825746;
  border-radius: 6px;
  background: #422c25;
  color: #ffccaa;
  font-size: .8rem;
  font-weight: 750;
}
.evidence-link:hover { background: #52352a; border-color: #b87e5b; }
.evidence-link span { margin-left: 3px; }

.composer {
  padding: 12px clamp(14px, 3vw, 38px) clamp(13px, 2.4vh, 25px);
}
.composer > * { max-width: 830px; margin-inline: auto; }
.examples { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 9px; }
.examples button {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid #64443a;
  border-radius: 6px;
  background: #342522e8;
  color: #e8cabc;
  font-size: .76rem;
  font-weight: 670;
}
.examples button:not(:disabled):hover { color: #ffe6d0; border-color: #c38a69; background: #422c2b; }
.report { display: flex; gap: 8px; }
.report input, #conversation-title {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid #795247;
  border-radius: 8px;
  background: #1e1616;
  color: #fff1e1;
}
.report input { background: #1e1616db; }
.report input::placeholder { color: #c1a499; }
.report input, .report button { box-shadow: 0 8px 20px #190e0b52; }
.report button {
  min-width: 80px;
  padding: 0 9px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: .87rem;
  font-weight: 850;
}
.report button:not(:disabled):hover { background: #ffd0a8; }
.chat-notice:not([hidden]) { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
#chat-error, .chat-error { margin: 0; font-size: .84rem; color: var(--error); }

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: 1px solid var(--soft-line);
  padding: 15px 14px;
}
.messages:focus-visible { outline-offset: -3px; }
.turn { display: grid; flex: 0 0 auto; gap: 10px; min-width: 0; }
.turn + .turn { border-top: 1px solid var(--soft-line); padding-top: 13px; }
.message {
  min-width: 0;
  border: 1px solid #513936;
  border-radius: 8px;
  padding: 9px 10px;
  background: #302322;
  font-size: .83rem;
  line-height: 1.6;
}
.message.is-user { width: fit-content; max-width: 92%; margin-inline-start: auto; background: #3b2a24; border-color: #614639; }
.message small { display: block; margin-top: 4px; }
.author { display: block; margin-bottom: 3px; color: var(--accent); font-size: .74rem; font-weight: 760; }
.is-user .author { color: #dec0b2; }
.sources { width: 100%; min-width: 0; margin-top: 8px; }
.sources > summary {
  width: fit-content;
  padding: 3px 0;
  color: #ffbc97;
  cursor: pointer;
  font-weight: 740;
}
.finding { padding: 7px 0 3px; }
.finding + .finding { border-top: 1px solid var(--line); }
.finding .finding-text { margin-bottom: 7px; }
.source { margin-bottom: 6px; border-left: 2px solid #986650; background: #261c1c; overflow-wrap: anywhere; }
.source-heading { padding: 7px 9px; color: #ffc59f; cursor: pointer; }
.source-heading:hover { background: #ffffff0a; }
.source-heading:focus-visible { outline-offset: -2px; }
.source-excerpts { padding: 0 9px 8px; }
.source a { color: #ffc59f; text-underline-offset: 3px; }
.source small { display: block; margin-block: 3px; color: var(--muted); }
.source blockquote { color: #ecd5c9; }
.scrim { display: none; }

dialog {
  width: min(430px, calc(100% - 32px));
  padding: 20px;
  border: 1px solid #8b5d4d;
  border-radius: 12px;
  color: #fff1e5;
  background: #302220;
  box-shadow: 0 22px 70px #100b09b0;
}
dialog::backdrop { background: #130d0bc5; }
dialog h2 { margin: 0 0 14px; font-size: 1.12rem; }
dialog form > p:not(.chat-error) { margin: 0 0 14px; line-height: 1.55; overflow-wrap: anywhere; }
dialog label { display: block; margin-bottom: 5px; color: var(--muted); font-size: .83rem; }
dialog .chat-error { margin-top: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 15px; }
.dialog-actions button { min-height: 38px; padding: 0 12px; border: 1px solid #7b5447; border-radius: 7px; background: #362825; }
.dialog-actions button:not(:disabled):hover { border-color: #ffbc97; }
#manage-submit { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 780; }
#manage-submit.danger { background: #ffc0b1; border-color: #ffc0b1; }

@media (max-width: 1050px) {
  .layout { --history-width: min(520px, calc(100vw - 22px)); grid-template-columns: minmax(0, 1fr); }
  .office { grid-column: 1; }
  .panel-rail {
    position: absolute;
    inset-block: 0;
    z-index: 5;
    box-shadow: 0 0 36px #100b0baa;
    transition: transform var(--panel-motion), opacity var(--panel-motion), visibility var(--panel-motion) allow-discrete;
  }
  .sessions-rail { left: 0; width: min(340px, calc(100% - 32px)); transform: translateX(-100%); }
  .history-rail { right: 0; width: var(--history-width); transform: translateX(100%); }
  .sidebar { width: 100%; }
  .sessions-open .sessions-rail, .history-open .history-rail { transform: translateX(0); }
  .scrim {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 4;
    background: #0c0808a3;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--panel-motion);
  }
  .drawer-open .scrim { opacity: 1; pointer-events: auto; }
}
@media (max-width: 620px) {
  :root { --header-height: 54px; --section-header-height: 41px; }
  .header-start { display: contents; }
  .brand { gap: 5px; }
  .brand-icon { width: 25px; height: 25px; }
  .panel-toggle { min-height: 34px; gap: 5px; padding-inline: 7px; font-size: .75rem; }
  .office { background: radial-gradient(ellipse at 50% 45%, #603420, #35221d 48%, #221818 86%); }
  .office::before { background-position: center, 18% center; }
  .speech-content { font-size: .91rem; }
  .composer { padding: 9px 13px max(12px, env(safe-area-inset-bottom)); }
  .report input, #conversation-title { font-size: 1rem; }
}
@container office (max-width: 700px) {
  .scene {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    padding: 0 14px 12px;
  }
  #boss, .boss-still { left: 50%; width: min(106%, 102cqh); }
  .exchange { width: 100%; max-height: min(42dvh, 300px); margin: 0; gap: 9px; }
  .speech { gap: 7px; padding: 11px 13px; }
  .speech::before, .speech::after { display: none; }
}
@media (max-width: 335px) { .panel-icon { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .layout, .panel-rail, .scrim { transition: none; }
  .fx-heart, .fx-stroke { display: none; }
}
