/* Themes. Every text/background pair below is checked for WCAG AA (4.5:1) by tests/test_web_chat.py. */
:root, [data-theme="light"] {
  color-scheme: light;
  --bg: #f2f3f6;
  --glass: rgba(255, 255, 255, .74);
  --panel: #ffffff;
  --line: #dcdfe6;
  --line-strong: #c3c8d4;
  --text: #171a21;
  --muted: #565e6e;
  --accent: #4549d0;
  --accent-ink: #ffffff;
  --accent-soft: rgba(69, 73, 208, .14);
  --glow: rgba(69, 73, 208, .30);
  --bubble: #ffffff;
  --me: #e8e9f9;
  --me-line: #c6c9f0;
  --field: #ffffff;
  --danger: #b8243a;
  --grid: rgba(40, 48, 80, .06);
  --haze: rgba(69, 73, 208, .10);
  --mark: hue-rotate(80deg) saturate(.8);
  --shade: rgba(242, 243, 246, .86);
}
[data-theme="graphite"] {
  color-scheme: dark;
  --bg: #121418;
  --glass: rgba(27, 30, 36, .72);
  --panel: #1b1e24;
  --line: #2a2e37;
  --line-strong: #3b414d;
  --text: #e8eaef;
  --muted: #9ea5b1;
  --accent: #e8b24a;
  --accent-ink: #1b1405;
  --accent-soft: rgba(232, 178, 74, .13);
  --glow: rgba(232, 178, 74, .32);
  --bubble: #1c1f26;
  --me: #2b2922;
  --me-line: #4a4232;
  --field: #15171c;
  --danger: #ff8a80;
  --grid: rgba(255, 255, 255, .045);
  --haze: rgba(232, 178, 74, .06);
  --mark: hue-rotate(-120deg) saturate(.9);
  --shade: rgba(18, 20, 24, .86);
}
[data-theme="blue"] {
  color-scheme: dark;
  --bg: #0b1424;
  --glass: rgba(17, 30, 52, .70);
  --panel: #13213a;
  --line: #1f3150;
  --line-strong: #2d4870;
  --text: #e3ebf7;
  --muted: #95a8c4;
  --accent: #6cb4ff;
  --accent-ink: #06162b;
  --accent-soft: rgba(108, 180, 255, .14);
  --glow: rgba(108, 180, 255, .32);
  --bubble: #12203a;
  --me: #173458;
  --me-line: #25507f;
  --field: #0d182b;
  --danger: #ff9494;
  --grid: rgba(108, 180, 255, .07);
  --haze: rgba(108, 180, 255, .09);
  --mark: hue-rotate(50deg);
  --shade: rgba(11, 20, 36, .86);
}
[data-theme="green"] {
  color-scheme: dark;
  --bg: #070d0c;
  --glass: rgba(14, 25, 23, .72);
  --panel: #0e1917;
  --line: #1d3430;
  --line-strong: #2a4a44;
  --text: #e6f3ef;
  --muted: #8aa39c;
  --accent: #1fe0a0;
  --accent-ink: #052019;
  --accent-soft: rgba(31, 224, 160, .13);
  --glow: rgba(31, 224, 160, .32);
  --bubble: #13221f;
  --me: #13362c;
  --me-line: #1f5243;
  --field: #070d0c;
  --danger: #ff7a7a;
  --grid: rgba(31, 224, 160, .06);
  --haze: rgba(31, 224, 160, .09);
  --mark: none;
  --shade: rgba(7, 13, 12, .86);
}

:root {
  --radius: 16px;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Cascadia Code", Consolas, "SF Mono", Menlo, "Roboto Mono", monospace;
  font-family: var(--sans);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { background: radial-gradient(1200px 640px at 85% -10%, var(--haze), transparent 62%), var(--bg); }
/* Faint static grid behind everything: painted once, never animated. */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-mask-image: radial-gradient(ellipse 90% 80% at 50% 30%, #000 30%, transparent 100%);
  mask-image: radial-gradient(ellipse 90% 80% at 50% 30%, #000 30%, transparent 100%); }
[hidden] { display: none !important; }
button, label { -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* glass surfaces */
.top, .composer, .card {
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .top, .composer, .card { background: var(--panel); }
}

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card { width: min(420px, 100%); border: 1px solid var(--line); border-radius: 22px; position: relative;
        padding: 32px 28px; box-shadow: 0 0 0 1px var(--accent-soft), 0 20px 60px var(--accent-soft);
        display: flex; flex-direction: column; gap: 10px; }
.card .mark { width: 56px; height: 56px; margin: 0 auto 4px; filter: var(--mark) drop-shadow(0 0 14px var(--glow)); }
.card h1 { margin: 0; text-align: center; font-weight: 600; letter-spacing: .5px; }
.card .sub { margin: 0 0 12px; text-align: center; color: var(--muted); font-family: var(--mono); font-size: 13px;
             letter-spacing: 1.5px; text-transform: uppercase; }
.card label { color: var(--muted); font-size: 14px; }
.card input { background: var(--field); color: var(--text); border: 1px solid var(--line-strong); border-radius: 12px;
              padding: 12px 14px; font-size: 18px; letter-spacing: 2px; font-family: var(--mono); }
.card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card button { margin-top: 6px; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px;
               padding: 12px; font-weight: 600; box-shadow: 0 0 18px var(--glow); }
.card button:disabled { opacity: .6; cursor: default; }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }

/* app */
.app { height: 100%; display: flex; flex-direction: column; max-width: 980px; margin: 0 auto;
       border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line);
       position: relative; z-index: 5; }
/* thin light edge in the theme colour */
.top::after, .composer::before { content: ""; position: absolute; left: 8%; right: 8%; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--accent), transparent); opacity: .55; }
.top::after { bottom: -1px; }
.composer::before { top: -1px; }
.avatar { width: 40px; height: 40px; border-radius: 12px; filter: var(--mark); box-shadow: 0 0 16px var(--glow); }
.who { flex: 1; min-width: 0; }
/* co-branded wordmark: LA LUNA × PARTNER */
.wm { display: inline-flex; align-items: center; gap: .5em; font-size: 16px; line-height: 1.15; white-space: nowrap;
      text-transform: uppercase; font-family: Bahnschrift, "DIN Alternate", "DIN Condensed", var(--sans); }
.wm-a { font-weight: 700; letter-spacing: .32em; margin-right: -.32em;
        background: linear-gradient(90deg, var(--text) 35%, var(--accent)); -webkit-background-clip: text; background-clip: text;
        color: transparent; }
.wm-x { font-family: var(--sans); font-weight: 200; font-size: 1.3em; line-height: 1; color: var(--accent);
        text-shadow: 0 0 10px var(--glow); }
.wm-tail { display: inline-flex; align-items: center; gap: .5em; }
.wm-b { font-weight: 500; letter-spacing: .26em; margin-right: -.26em; color: var(--text); }
.name { font-weight: 600; letter-spacing: .3px; }
.state { color: var(--muted); font-size: 12px; font-family: var(--mono); letter-spacing: .5px; display: flex; align-items: center; gap: 6px; }
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--glow); }
.state.offline { color: var(--danger); }
.state.offline::before { background: var(--danger); box-shadow: none; }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 10px; padding: 6px 12px;
         transition: color .15s, border-color .15s, box-shadow .15s; }
.ghost:hover, .ghost[aria-expanded="true"] { color: var(--text); border-color: var(--accent); box-shadow: 0 0 12px var(--accent-soft); }
.ghost.icon { width: 36px; height: 34px; padding: 0; display: grid; place-items: center; }
.ghost.icon svg { width: 20px; height: 20px; }

/* appearance panel */
.look { position: relative; }
/* opaque on purpose: it lies over message text, and a nested backdrop-filter would not blur it */
.look-panel { position: absolute; top: calc(100% + 10px); right: 0; width: 270px; z-index: 20; padding: 14px; background: var(--panel);
              border: 1px solid var(--line-strong); border-radius: 16px;
              box-shadow: 0 18px 50px rgba(0, 0, 0, .28), 0 0 0 1px var(--accent-soft); }
.look-title { font-family: var(--mono); font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); margin: 0 2px 10px; }
.swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.swatch { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 12px; text-align: left;
          background: var(--field); color: var(--text); border: 1px solid var(--line); font-size: 14px;
          transition: border-color .15s, box-shadow .15s; }
.swatch:hover { border-color: var(--line-strong); }
.swatch[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 14px var(--accent-soft); }
.dot { width: 18px; height: 18px; border-radius: 50%; flex: none; border: 1px solid rgba(128, 128, 128, .45); }
.dot-light { background: linear-gradient(135deg, #f2f3f6 50%, #4549d0 50%); }
.dot-graphite { background: linear-gradient(135deg, #1c1f26 50%, #e8b24a 50%); }
.dot-blue { background: linear-gradient(135deg, #0b1424 50%, #6cb4ff 50%); }
.dot-green { background: linear-gradient(135deg, #070d0c 50%, #1fe0a0 50%); }
.calm-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 10px 4px 2px; border-top: 1px solid var(--line);
            cursor: pointer; position: relative; }
.calm-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { width: 36px; height: 20px; border-radius: 999px; background: var(--line-strong); position: relative; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--panel);
                 transition: transform .15s; }
.calm-row input:checked + .switch { background: var(--accent); }
.calm-row input:checked + .switch::after { transform: translateX(16px); background: var(--accent-ink); }
.calm-row input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.calm-name { display: block; font-size: 14px; }
.calm-note { display: block; font-size: 12px; color: var(--muted); }

/* messages */
.scroll { flex: 1; overflow-y: auto; padding: 18px 18px 8px; }
.older { display: block; margin: 0 auto 12px; background: var(--panel); color: var(--muted); border: 1px solid var(--line);
         border-radius: 999px; padding: 6px 14px; font-size: 12px; font-family: var(--mono); }
.list { display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; color: var(--muted); font-size: 11px; margin: 12px 0 4px; padding: 3px 12px; font-family: var(--mono);
       letter-spacing: 1px; text-transform: uppercase; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); }
.msg { max-width: min(78%, 680px); padding: 9px 13px 6px; border-radius: var(--radius); background: var(--bubble);
       border: 1px solid var(--line); align-self: flex-start; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--me); border-color: var(--me-line); box-shadow: 0 0 18px var(--accent-soft); }
.msg.system { align-self: center; background: var(--bg); color: var(--muted); font-size: 14px; text-align: center; border-style: dashed; box-shadow: none; }
.msg.fresh { animation: rise .24s ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg .body { white-space: pre-wrap; line-height: 1.5; }
.msg .body a { color: var(--accent); }
.msg .meta { display: flex; gap: 8px; justify-content: flex-end; color: var(--muted); font-size: 11px; margin-top: 4px;
             font-family: var(--mono); letter-spacing: .3px; }
.msg .via { color: var(--accent); }
.msg.failed { border-color: var(--danger); }
.msg .note { color: var(--muted); font-size: 12px; margin-top: 4px; }
.msg .again { background: transparent; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--accent);
              font: inherit; font-size: 11px; padding: 0 6px; }
.files { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.file { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); background: var(--field);
        border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.file:hover { border-color: var(--accent); }
.file .ext { min-width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-size: 11px; font-weight: 700;
             font-family: var(--mono); background: var(--accent-soft); color: var(--text); text-transform: uppercase;
             border: 1px solid var(--line); }
.file .fname { font-size: 14px; }
.file .fsize { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.thumb { max-width: 100%; max-height: 320px; border-radius: 12px; display: block; margin-top: 6px; }

/* typing: three bars, animated only while visible (display:none stops it) */
.typing { color: var(--muted); font-size: 11px; padding: 10px 2px; display: flex; align-items: center; gap: 10px;
          font-family: var(--mono); letter-spacing: 1.5px; text-transform: uppercase; }
.pulse { display: inline-flex; align-items: center; gap: 3px; height: 14px; padding: 3px 8px; border-radius: 999px;
         border: 1px solid var(--line-strong); box-sizing: content-box; }
.pulse i { width: 3px; height: 12px; border-radius: 2px; background: var(--accent); box-shadow: 0 0 6px var(--glow);
           transform: scaleY(.35); animation: bar 1s ease-in-out infinite; }
.pulse i:nth-child(2) { animation-delay: .15s; } .pulse i:nth-child(3) { animation-delay: .3s; }
@keyframes bar { 50% { transform: scaleY(1); } }

/* composer */
.composer { border-top: 1px solid var(--line); padding: 10px 12px; position: relative;
            padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; resize: none; max-height: 220px; min-height: 44px; background: var(--field); color: var(--text);
                     border: 1px solid var(--line-strong); border-radius: 14px; padding: 11px 14px; font: inherit; line-height: 1.4;
                     transition: border-color .15s, box-shadow .15s; }
.composer textarea::placeholder { color: var(--muted); opacity: 1; }
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.attach, .send { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; flex: none; }
.attach { color: var(--muted); border: 1px solid var(--line-strong); cursor: pointer; transition: color .15s, border-color .15s; }
.attach:hover { color: var(--accent); border-color: var(--accent); }
.attach svg, .send svg { width: 22px; height: 22px; }
.send { background: var(--accent); color: var(--accent-ink); border: 0; box-shadow: 0 0 16px var(--glow); transition: box-shadow .15s; }
.send:hover { box-shadow: 0 0 22px var(--glow); }
.send:disabled { opacity: .5; cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chips:empty { display: none; }
.chip { display: flex; align-items: center; gap: 6px; background: var(--field); border: 1px solid var(--line); border-radius: 999px;
        padding: 4px 6px 4px 12px; font-size: 13px; }
.chip button { background: transparent; border: 0; color: var(--muted); font-size: 16px; line-height: 1; padding: 0 4px; }
.progress { height: 3px; background: var(--line); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); box-shadow: 0 0 8px var(--glow); transition: width .2s; }
.drop { position: fixed; inset: 0; display: grid; place-items: center; background: var(--shade); color: var(--text);
        font-size: 22px; border: 2px dashed var(--accent); z-index: 30; }

/* calm mode: flat, solid, still */
[data-calm="1"] body { background: var(--bg); }
[data-calm="1"] body::before,
[data-calm="1"] .top::after,
[data-calm="1"] .composer::before { display: none; }
[data-calm="1"] .top, [data-calm="1"] .composer, [data-calm="1"] .card {
  background: var(--panel); -webkit-backdrop-filter: none; backdrop-filter: none; }
[data-calm="1"] .card, [data-calm="1"] .card button, [data-calm="1"] .avatar, [data-calm="1"] .msg.me,
[data-calm="1"] .send, [data-calm="1"] .send:hover, [data-calm="1"] .ghost:hover, [data-calm="1"] .ghost[aria-expanded="true"],
[data-calm="1"] .state::before, [data-calm="1"] .progress div, [data-calm="1"] .pulse i { box-shadow: none; }
[data-calm="1"] .swatch[aria-checked="true"] { box-shadow: 0 0 0 1px var(--accent); }
[data-calm="1"] .look-panel { box-shadow: 0 12px 30px rgba(0, 0, 0, .22); }
[data-calm="1"] .card .mark { filter: var(--mark); }
[data-calm="1"] *, [data-calm="1"] *::before, [data-calm="1"] *::after { animation: none !important; transition: none !important; }
[data-calm="1"] .wm-a { background: none; color: var(--text); }
[data-calm="1"] .wm-x { text-shadow: none; }
[data-calm="1"] .pulse i { transform: none; opacity: .45; }
[data-calm="1"] .pulse i:nth-child(2) { opacity: .7; }
[data-calm="1"] .pulse i:nth-child(3) { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .pulse i { transform: none; opacity: .45; }
  .pulse i:nth-child(2) { opacity: .7; }
  .pulse i:nth-child(3) { opacity: 1; }
}

@media (max-width: 640px) {
  .app { border: 0; }
  .top { padding: 10px 12px; gap: 10px; }
  .msg { max-width: 90%; }
  .look { position: static; }
  .look-panel { position: fixed; top: 62px; left: 10px; right: 10px; width: auto; }
  .wm { font-size: 13px; gap: 0 .4em; flex-wrap: wrap; }
  .wm-tail { gap: .35em; }
  .wm-a { letter-spacing: .2em; margin-right: -.2em; }
  .wm-b { letter-spacing: .14em; margin-right: -.14em; }
}

