/* Chat page in the FlowCoder themes (dark and light). Loads nothing (system font stacks only); the CSP allows this
   origin only. Layout and components follow the house page for attendees; colours follow the brand tokens. */

/* ---- Themes ----
   Dark is the default and the fallback. The light theme applies when the device prefers light and the page has no
   data-theme="dark", or when data-theme="light" (the 화면 밝기 button, for this page view only). The two light blocks
   below are the same (test/node/ui.test.ts checks it). Text pairs are at least 4.5:1, field edges and rings 3:1. */

:root {
  color-scheme: dark;
  --bg: #0b0c0e; /* Void */
  --surface: #17191d; /* Graphite */
  --border: #24262b; /* hairlines */
  --text: #f2f3f4; /* Fog */
  --muted: #9aa0a8; /* Steel */
  --accent: #00e5a0; /* Mint 500: fills (primary button) */
  --accent-hover: #33eab3;
  --accent-text: #00e5a0; /* Mint-coloured text */
  --accent-graphic: #00e5a0; /* rules and the grounded answer's edge */
  --on-accent: #0b0c0e;
  --control-line: #666c75; /* field edges: at least 3:1 on bg and surface */
  --focus: #00e5a0;
  --fill-quiet: #24262b; /* the student's own messages, disabled buttons */
  --warning-edge: #f5a623;
  --warning-text: #f5a623;
  --danger-edge: #f0483e;
  --danger-text: #f0483e;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #ffffff;
    --surface: #fafaf9;
    --border: #e4e5e4;
    --text: #131417;
    --muted: #5f646b;
    --accent: #00e5a0;
    --accent-hover: #00b37d;
    --accent-text: #00754f;
    --accent-graphic: #00b37d;
    --on-accent: #0b0c0e;
    --control-line: #7e838b;
    --focus: #131417;
    --fill-quiet: #f1f2f1;
    --warning-edge: #f5a623;
    --warning-text: #9a5b00;
    --danger-edge: #f0483e;
    --danger-text: #c2271c;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #fafaf9;
  --border: #e4e5e4;
  --text: #131417;
  --muted: #5f646b;
  --accent: #00e5a0;
  --accent-hover: #00b37d;
  --accent-text: #00754f;
  --accent-graphic: #00b37d;
  --on-accent: #0b0c0e;
  --control-line: #7e838b;
  --focus: #131417;
  --fill-quiet: #f1f2f1;
  --warning-edge: #f5a623;
  --warning-text: #9a5b00;
  --danger-edge: #f0483e;
  --danger-text: #c2271c;
}

/* Each logo is in the page twice; only the variant for the theme on screen is shown (and announced). */
.on-dark {
  display: block;
}

.on-light {
  display: none;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .on-dark {
    display: none;
  }

  :root:not([data-theme="dark"]) .on-light {
    display: block;
  }
}

:root[data-theme="light"] .on-dark {
  display: none;
}

:root[data-theme="light"] .on-light {
  display: block;
}

/* ---- Base ---- */

:root {
  --font-text: "Geist", "Pretendard", "Pretendard Variable", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic",
    "Noto Sans KR", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius-card: 14px;
  --radius-control: 12px;
  --gutter: 24px;
  --page: 912px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Screens are toggled with the hidden attribute; a display rule below must never override it. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  /* Korean lines break between words, not inside them; overflow-wrap below still breaks an overlong word. */
  word-break: keep-all;
}

/* Mint on dark, Ink on light; on the Mint buttons the text colour, so the ring never disappears into the fill. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* A heading focused by app.js to move the reading position (the notice) is not a control: no ring around it. */
[tabindex="-1"]:focus {
  outline: none;
}

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

/* ---- Frame ---- */

/* Content keeps one column of --page; header, footer and hairlines run edge to edge. */
.app {
  --inline: max(var(--gutter), calc((100% - var(--page)) / 2));
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* While chatting the page is exactly one screen tall and only the message log scrolls. */
.app.is-chat {
  height: 100vh;
  height: 100dvh;
}

.app-header {
  --logo-h: 32px;
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  min-height: 68px;
  padding: 0 var(--inline);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.logo img {
  width: auto;
}

/* The logo files are used as supplied. The negative margin only lines the drawn F up with the text edge below (the
   files keep empty space left of the stroke: 14.5 of 64 units). */
.logo-lockup img {
  height: var(--logo-h);
  margin-left: calc(var(--logo-h) * -0.226);
}

.logo-symbol {
  display: none;
}

.logo-symbol img {
  height: 28px;
  margin-left: -6px;
}

.app-name {
  display: none;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.header-pills {
  display: flex;
  flex: none;
  gap: 8px;
  margin-left: auto;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 18px;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}

.pill:hover {
  color: var(--text);
  border-color: var(--muted);
}

.pill-contact {
  display: none;
}

.app.is-chat .app-header {
  min-height: 60px;
}

.app.is-chat .logo-lockup,
.app.is-chat .pill-about {
  display: none;
}

.app.is-chat .logo-symbol {
  display: block;
}

.app.is-chat .app-name {
  display: block;
}

.app.is-chat .pill-contact {
  display: inline-flex;
}

.app-main {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
  padding: 0 var(--inline) 96px;
}

.app.is-chat .app-main {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0;
}

/* ---- Shared pieces ---- */

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
}

.rule {
  width: 56px;
  height: 3px;
  background: var(--accent-graphic);
}

.button {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 28px;
  color: var(--on-accent);
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, transform 80ms ease;
}

.button:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button:focus-visible {
  outline-color: var(--text);
}

/* Also the waiting state: the code button is disabled while the code is checked, the send button while answering. */
.button:disabled {
  color: var(--muted);
  background: var(--fill-quiet);
  border-color: var(--fill-quiet);
  cursor: not-allowed;
}

.button-secondary {
  min-height: 44px;
  padding: 0 18px;
  color: var(--text);
  font-weight: 600;
  background: transparent;
  border-color: var(--control-line);
}

.button-secondary:hover:not(:disabled) {
  background: var(--fill-quiet);
  border-color: var(--control-line);
}

.button-secondary:focus-visible {
  outline-color: var(--focus);
}

.message {
  margin: 12px 0 0;
  color: var(--muted);
}

/* An empty message line takes no room; it stays rendered so that screen readers still announce what appears in it. */
.message:empty {
  margin: 0;
}

.message.is-error {
  color: var(--danger-text);
  font-weight: 600;
}

/* ---- Entry ---- */

.hero {
  padding: 64px 0 40px;
}

.hero-title {
  margin: 14px 0 0;
  font-size: clamp(36px, 7vw, 60px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.hero-sub {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 19px;
  line-height: 1.5;
}

.hero .rule {
  margin: 28px 0 22px;
}

.hero-lead {
  max-width: 560px;
  margin: 0;
  line-height: 1.8;
}

.hero-lead span,
.footer-lead span {
  display: block;
}

.hero-sub,
.hero-lead span {
  text-wrap: balance;
}

.code-form {
  max-width: 720px;
}

.field-label {
  display: block;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
}

.code-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.code-box {
  flex: 1 1 auto;
  min-width: 0;
  container-type: inline-size;
}

/* After the title, the boldest thing on the page: the code as it was handed out, in mono, grouped in fours. Sized to
   its own width, so a full XXXX-XXXX-XXXX-XXXX always fits (19 characters of 0.6em plus 0.12em tracking). */
.code-field {
  display: block;
  width: 100%;
  height: 68px;
  margin: 0;
  padding: 0 20px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 20px;
  font-size: clamp(17px, calc(7cqi - 3px), 34px);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
  background: var(--surface);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-control);
  caret-color: var(--accent-text);
  transition: border-color 120ms ease;
}

.code-field::placeholder {
  color: var(--muted);
  opacity: 1;
}

/* Centred on the 68px field (the counter under the field is not part of the alignment). */
.code-row .button {
  min-height: 56px;
  margin-top: 6px;
  padding: 0 32px;
}

.code-count {
  margin: 8px 0 0;
  color: var(--accent-text);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.entry-note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 14px;
}

/* Focused fields: one 2px ring in the focus colour, 2px outside the border (Mint on dark, Ink on light). */
.code-field:focus-visible,
textarea:focus-visible {
  outline-width: 2px;
}

/* ---- Notice ---- */

.screen-consent {
  padding-top: 64px;
}

.section-title {
  margin: 14px 0 0;
  padding-bottom: 14px;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -0.02em;
  border-bottom: 2px solid var(--text);
}

.notice {
  max-width: 40em;
  margin: 28px 0 32px;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---- Footer band (entry and notice) ---- */

.site-footer {
  flex: none;
  padding: 72px var(--inline) 56px;
  text-align: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.app.is-chat .site-footer {
  display: none;
}

.footer-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 32px;
}

.footer-logo img {
  height: 29px;
}

.footer-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.footer-lead,
.footer-perk,
.footer-tag,
.footer-legal p {
  text-wrap: balance;
}

.footer-lead {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.8;
}

.site-footer .rule {
  margin: 34px auto;
}

.footer-label {
  margin: 0;
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 700;
}

.footer-perk {
  margin: 8px 0 0;
  line-height: 1.8;
}

.footer-email {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 20px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 19px;
  text-underline-offset: 4px;
}

.footer-email:hover {
  color: var(--accent-text);
}

.footer-tag {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.footer-legal {
  margin-top: 44px;
  padding-top: 24px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
  border-top: 1px solid var(--border);
}

.footer-legal p {
  margin: 0;
}

/* ---- Chat ---- */

.screen-chat {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.log {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 16px;
  min-height: 160px;
  padding: 24px var(--inline);
  overflow-y: auto;
}

.log:empty::before {
  content: "교안에서 궁금한 내용을 물어보세요. 예: 오늘 배운 개념을 다시 설명해 달라고 하기";
  max-width: 30em;
  color: var(--muted);
}

.msg {
  max-width: min(100%, 42em);
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.msg p {
  margin: 0;
}

.msg-text {
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg .msg-label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.msg-user {
  align-self: flex-end;
  max-width: min(88%, 36em);
  background: var(--fill-quiet);
  border-color: var(--fill-quiet);
}

/* The answer kind: its label and a left edge in the kind's colour. */
.msg-bot {
  align-self: flex-start;
  border-left: 3px solid var(--muted);
  border-radius: 4px var(--radius-card) var(--radius-card) 4px;
}

.kind-grounded {
  border-left-color: var(--accent-graphic);
}

.kind-grounded .msg-label {
  color: var(--accent-text);
}

.kind-general {
  border-left-color: var(--warning-edge);
}

.kind-general .msg-label {
  color: var(--warning-text);
}

.kind-refusal {
  border-left-color: var(--muted);
}

.msg .msg-dated {
  margin-top: 12px;
  padding-top: 10px;
  color: var(--muted);
  font-size: 14px;
  border-top: 1px solid var(--border);
}

.msg .msg-meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.msg-system {
  align-self: stretch;
  max-width: none;
}

.msg-system.is-error {
  border-left: 3px solid var(--danger-edge);
  border-radius: 4px var(--radius-card) var(--radius-card) 4px;
}

.msg-actions {
  margin-top: 12px;
}

.composer {
  flex: none;
  padding: 12px var(--inline) 8px;
  border-top: 1px solid var(--border);
}

.disclaimer {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.disclaimer strong {
  color: var(--text);
  font-weight: 600;
}

.composer-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.composer-head label {
  font-size: 14px;
  font-weight: 600;
}

.char-count {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.char-count.is-over {
  color: var(--danger-text);
  font-weight: 700;
}

textarea {
  display: block;
  width: 100%;
  min-height: 4.8em;
  max-height: 35vh;
  padding: 10px 14px;
  color: var(--text);
  font: inherit;
  line-height: 1.6;
  background: var(--surface);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-control);
  resize: vertical;
  caret-color: var(--accent-text);
  transition: border-color 120ms ease;
}

.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 10px;
}

.composer-row .button {
  min-height: 48px;
  padding: 0 24px;
}

.key-hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.status {
  min-height: 1.5em;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---- Widths ---- */

@media (max-width: 720px) {
  :root {
    --gutter: 20px;
  }

  .app-header {
    --logo-h: 26px;
  }

  .pill {
    padding: 0 12px;
  }

  .hero {
    padding: 44px 0 30px;
  }

  .hero-sub {
    font-size: 17px;
  }

  .section-title {
    font-size: 22px;
  }

  .screen-consent {
    padding-top: 44px;
  }

  .app-main {
    padding-bottom: 72px;
  }

  .site-footer {
    padding-top: 56px;
    padding-bottom: 44px;
  }

  .footer-title {
    font-size: 22px;
  }

  /* Phones: the button goes under the field. */
  .code-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .code-box {
    width: 100%;
  }

  .code-field {
    height: 64px;
  }

  .code-row .button {
    min-height: 52px;
    margin-top: 4px;
  }

  /* Phones: the question box starts two lines tall, so the log keeps more room; it can still be resized. */
  textarea {
    min-height: calc(3.2em + 22px);
    height: calc(3.2em + 22px);
  }
}

@media (max-width: 379px) {
  /* The chat header keeps the symbol and both pills on one line; the product name stays for screen readers. */
  .app.is-chat .app-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

@media (max-width: 360px) {
  :root {
    --gutter: 16px;
  }

  .app-header {
    --logo-h: 24px;
  }

  .header-pills {
    gap: 6px;
  }

  .pill {
    padding: 0 11px;
  }

  .code-field {
    padding: 0 14px;
    font-size: clamp(16px, calc(7cqi - 1px), 34px);
    letter-spacing: 0.1em;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }

  .button:active:not(:disabled) {
    transform: none;
  }
}
