/* Hallmark / app / ink, fog, and periwinkle / reading and writing */
/* Give the first input room, and let the sources sit with the answer. */
:root {
  color-scheme: light;
  --canvas: #f8f9fc;
  --surface: #ffffff;
  --ink: #191e2b;
  --muted: #525d74;
  --line: #d9dfea;
  --quiet-surface: #eef1f7;
  --reply-surface: #e9edf8;
  --accent: #3758cc;
  --accent-hover: #2a48b0;
  --accent-ink: #ffffff;
  --accent-link: #2b4aab;
  --focus: #3758cc;
  --shadow: 0 4px 20px #1825470d;
  --font: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --measure: 46rem;
  --tap-highlight: transparent;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #15171f;
  --surface: #1e222e;
  --ink: #f1f3f8;
  --muted: #aeb7cc;
  --line: #363e51;
  --quiet-surface: #252b3a;
  --reply-surface: #283145;
  --accent: #a5b6ff;
  --accent-hover: #c1cbff;
  --accent-ink: #13214e;
  --accent-link: #b9c7ff;
  --focus: #a5b6ff;
  --shadow: 0 6px 24px #090a0f50;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overflow-x: clip; }
body { background: var(--canvas); color: var(--ink); font: 1rem/1.7 var(--font); }
[hidden] { display: none !important; }
button, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, a { -webkit-tap-highlight-color: var(--tap-highlight); }
::selection { color: var(--ink); background: var(--reply-surface); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
a { color: var(--accent-link); text-underline-offset: .18em; }

.site-header {
  background: var(--canvas);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1;
}
.header-inner {
  min-height: 3.75rem;
  max-width: 65rem;
  width: calc(100% - 2rem);
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
}
.identity { display: flex; align-items: baseline; gap: .55rem; white-space: nowrap; }
.wordmark { font-size: 1.05rem; font-weight: 800; letter-spacing: -.035em; }
.service-name { font-size: .8rem; color: var(--muted); }
nav, .header-actions { display: flex; align-items: center; gap: .2rem; }
.header-actions { gap: .65rem; }
.chat-actions { margin-inline-start: auto; }
.text-button { border: 0; min-height: 2.75rem; padding: .45rem .55rem; border-radius: .45rem; font-size: .85rem; background: transparent; white-space: nowrap; }
.text-button:disabled { color: var(--muted); }
.text-button:hover:not(:disabled) { background: var(--quiet-surface); }

.theme-button {
  display: grid;
  place-items: center;
  width: 2.75rem;
  padding: 0;
  color: var(--accent-link);
}
.theme-icon { position: relative; display: block; width: 1.125rem; height: 1.125rem; }
.theme-icon::before, .theme-icon::after { position: absolute; content: ""; }
.theme-icon::before {
  inset: 0 .03rem .18rem .18rem;
  border-radius: 50%;
  box-shadow: -.21rem .16rem 0 currentColor;
}
.theme-button[aria-pressed="true"] .theme-icon::before {
  inset: 28%;
  border: 1.5px solid currentColor;
  box-shadow: none;
}
.theme-button[aria-pressed="true"] .theme-icon::after {
  inset: 0;
  background: linear-gradient(currentColor, currentColor) center top / 1.5px .21rem,
    linear-gradient(currentColor, currentColor) center bottom / 1.5px .21rem,
    linear-gradient(currentColor, currentColor) left center / .21rem 1.5px,
    linear-gradient(currentColor, currentColor) right center / .21rem 1.5px;
  background-repeat: no-repeat;
}


.entry, .workspace { width: min(calc(100% - 2rem), var(--measure)); margin-inline: auto; }
.entry { padding: clamp(4rem, 17vh, 8rem) 0 2rem; max-width: 27rem; }
.entry section { padding: clamp(1.5rem, 6vw, 2.25rem); border: 1px solid var(--line); border-radius: 1rem; background: var(--surface); }
.entry p, .chat-intro p { margin: .55rem 0 0; font-size: .95rem; color: var(--muted); }
.entry .button { margin-top: 1.25rem; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: .55rem .9rem;
  border: 0;
  border-radius: .55rem;
  text-decoration: none;
  font-weight: 700;
}
.button-primary, .send { background: var(--accent); color: var(--accent-ink); }
.button-primary:hover:not(:disabled), .send:hover:not(:disabled) { background: var(--accent-hover); }
.button-primary:disabled, .send:disabled { background: var(--quiet-surface); color: var(--muted); }

.workspace { display: flex; flex-direction: column; min-height: calc(100dvh - 3.75rem); gap: .75rem; }
.conversation { flex: 1; padding-top: 1.6rem; min-width: 0; }
.workspace:has(#empty:not([hidden])) {
  justify-content: flex-start;
  padding-top: clamp(4rem, 19vh, 11rem);
  gap: 1.35rem;
}
.workspace:has(#empty:not([hidden])) .conversation { flex: 0; padding: 0; }
.chat-intro { text-align: center; padding-inline: .35rem; word-break: keep-all; overflow-wrap: anywhere; }
h1 {
  margin: 0;
  font-size: clamp(1.65rem, 5.6vw, 2.45rem);
  font-weight: 760;
  letter-spacing: -.04em;
  line-height: 1.25;
}
#transcript { display: grid; gap: 1.55rem; }
.message { min-width: 0; word-break: keep-all; overflow-wrap: anywhere; scroll-margin-top: 4.4rem; }
.message.question {
  width: fit-content;
  max-width: min(86%, 31rem);
  justify-self: end;
  background: var(--reply-surface);
  border-radius: 1rem 1rem .35rem 1rem;
  padding: .7rem .95rem;
}
.message.question h2, .screen-reader {
  width: 1px;
  height: 1px;
  position: absolute;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}
.message.answer { padding: 0 .15rem 1.4rem; border-bottom: 1px solid var(--line); }
.message h2, .message h3 { margin: 0 0 .3rem; font-size: .9rem; font-weight: 750; line-height: 1.45; }
.message h3 { margin: 1.15rem 0 .3rem; color: var(--muted); }
.message-text { margin: 0; white-space: pre-wrap; }
.sources { list-style: none; margin: 0; padding: 0; font-size: .845rem; }
.sources li + li { margin-top: .3rem; }
.sources a {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  min-height: 2.75rem;
  padding: .4rem .65rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--surface);
  text-decoration: none;
}
.source-title { text-decoration: underline; }
.source-sections { display: block; color: var(--muted); font-size: .78rem; }
.sources a:hover { background: var(--quiet-surface); }
.sources a::before { content: ""; display: inline-block; width: .6rem; height: .8rem; border: 1px solid currentColor; border-radius: .1rem; flex: none; }

.composer { position: sticky; bottom: 0; background: var(--canvas); padding: .6rem 0 max(.85rem, env(safe-area-inset-bottom)); }
.workspace:has(#empty:not([hidden])) .composer { position: static; padding-top: 0; }
.input-row {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: .6rem;
  box-shadow: var(--shadow);
}
.input-row:focus-within { border-color: var(--focus); }
textarea {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 3.25rem;
  max-height: 11rem;
  padding: .45rem .45rem .35rem .55rem;
  resize: none;
  border: 0;
  border-radius: .5rem;
  background: transparent;
  caret-color: var(--focus);
}
textarea::placeholder { color: var(--muted); }
textarea:focus-visible { outline: none; }
.send {
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: .75rem;
  display: grid;
  place-items: center;
  flex: none;
}
.send-arrow { position: relative; display: block; width: 2px; height: 15px; background: currentColor; }
.send-arrow::before {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  border-left: 2px solid currentColor;
  border-top: 2px solid currentColor;
  transform: rotate(45deg);
  left: -3.5px;
  top: 0;
}
.notice { margin: 0 0 .45rem; font-size: .9rem; color: var(--muted); }
.notice:empty { display: none; }
.entry .notice { margin: .55rem 0 0; }

.history-panel, .usage-dialog {
  width: min(calc(100% - 1.5rem), 31rem);
  max-height: calc(100dvh - 1.5rem);
  padding: 1.1rem 1.25rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: var(--shadow);
}
.usage-dialog::backdrop { background: #090d1d77; }
.history-panel {
  position: fixed;
  inset: 4.05rem max(.75rem, calc((100vw - 65rem) / 2)) auto auto;
  margin: 0;
  width: min(calc(100% - 1.5rem), 22.5rem);
  max-height: min(calc(100dvh - 4.8rem), 31rem);
  padding: .65rem .9rem .85rem;
}
.history-panel .usage-header { margin-bottom: .35rem; }
.history-query, .usage-alert-controls input {
  min-height: 2.75rem;
  padding: .45rem .65rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  color: var(--ink);
  background: var(--surface);
  font: inherit;
}
.history-query { width: 100%; margin-bottom: .5rem; font-size: .875rem; }
.history-list { margin: 0; padding: 0; list-style: none; }
.history-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .25rem; align-items: center; }
.history-remove { color: var(--muted); }
.history-remove:hover:not(:disabled) { color: var(--ink); }
.history-list li + li { border-top: 1px solid var(--line); }
.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .1rem .65rem;
  align-items: center;
  width: 100%;
  min-height: 2.75rem;
  padding: .55rem .6rem;
  border: 0;
  border-radius: .45rem;
  background: transparent;
  text-align: start;
}
.history-row:hover, .history-row[aria-current="true"] { background: var(--quiet-surface); }
.history-row-title { font-size: .9rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-row time, .history-current { color: var(--muted); font-size: .75rem; }
.history-current { color: var(--accent-link); }
.usage-header { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.usage-header h2 { margin: 0; font-size: 1.18rem; }
#usage-scope { margin: .35rem 0 .9rem; color: var(--muted); font-size: .875rem; word-break: keep-all; }
.usage-periods { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11.5rem), 1fr)); gap: .65rem; }
.usage-periods section { padding: .7rem .8rem; background: var(--quiet-surface); border-radius: .6rem; }
.usage-periods h3 { margin: 0 0 .35rem; font-size: .86rem; color: var(--muted); }
.usage-periods dl { display: grid; grid-template-columns: 1fr auto; gap: .2rem .5rem; margin: 0; font-size: .875rem; }
.usage-periods dd { margin: 0; text-align: end; font-weight: 700; font-variant-numeric: tabular-nums; }
.usage-alert-form { margin-top: .95rem; padding-top: .75rem; border-top: 1px solid var(--line); }
.usage-alert-form label { display: block; margin-bottom: .25rem; font-size: .9rem; font-weight: 700; }
.usage-alert-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .35rem; align-items: center; }
.usage-alert-controls input { width: 100%; font-size: .875rem; font-variant-numeric: tabular-nums; }
.usage-alert-controls .text-button { border: 1px solid var(--line); }
.usage-link { display: inline-flex; align-items: center; min-height: 2.75rem; margin-top: .35rem; font-size: .875rem; }

@media (max-width: 25rem) {
  .header-inner, .workspace, .entry { width: calc(100% - 1.5rem); }
  .identity { gap: .35rem; }
  .service-name { font-size: .75rem; }
  .text-button { padding-inline: .4rem; }
  .workspace:has(#empty:not([hidden])) { padding-top: clamp(3.5rem, 16vh, 7.5rem); }
}

@media (max-width: 32rem) {
  .header-inner:has(.header-actions) { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 .4rem; }
  .header-actions { display: contents; }
  .chat-actions { grid-row: 2; grid-column: 1 / -1; margin-inline-start: -.4rem; }
  .account-actions { grid-row: 1; grid-column: 2; }
  .history-panel { top: 5.75rem; max-height: min(calc(100dvh - 6.5rem), 31rem); }
}

@media (max-width: 21rem) {
  .header-inner:has(.header-actions) .service-name { display: none; }
}
