/* debAIte.live – one stylesheet, light and dark, phone first. */

:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #f9f6ef;
  --ink: #191813;
  --muted: #6b675f;
  --line: #e2ddd2;
  --accent: #d43b12;
  --accent-ink: #ffffff;
  --accent-soft: #fbe6de;
  --ok: #1f7a4d;
  --shadow: 0 1px 2px rgba(25, 24, 19, .06), 0 8px 24px rgba(25, 24, 19, .06);
  --radius: 14px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --surface: #1d1c19;
    --surface-2: #232220;
    --ink: #f1eee7;
    --muted: #a29d93;
    --line: #302e2a;
    --accent: #ff7a4d;
    --accent-ink: #1a0d07;
    --accent-soft: #3a2118;
    --ok: #5fd19a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, p, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.ai { color: var(--accent); font-weight: 800; }

/* ---------- Layout ---------- */

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  grid-template-areas: "bar" "topic" "cast" "chat" "foot";
  gap: 10px;
  padding: 0 12px calc(72px + env(safe-area-inset-bottom));
  max-width: 1180px;
  margin: 0 auto;
}
.bar { grid-area: bar; }
.topic { grid-area: topic; }
.side { display: contents; }
.cast { grid-area: cast; }
.chat { grid-area: chat; }
.foot { grid-area: foot; }

/* ---------- Top bar ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 2px 2px;
}
.logo {
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -.02em;
  text-decoration: none;
}
.logo .tld { color: var(--muted); font-weight: 600; }
.bar-right { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.live {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 11px;
}
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on { color: var(--accent); }
.live.on i { background: var(--accent); animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.8); } }

.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.lang button {
  border: 0; background: none; cursor: pointer; padding: 4px 10px;
  font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--muted);
}
.lang button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.lang button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (max-width: 400px) { .watching { display: none; } }

/* ---------- Topic ---------- */

.topic {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.kicker { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.cat {
  font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--accent);
}
.next { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.topic h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(19px, 2.6vw, 28px);
  line-height: 1.22;
  letter-spacing: -.01em;
  text-wrap: balance;
}
.topic h1.quoted::before { content: "\201C"; }
.topic h1.quoted::after { content: "\201D"; }
.sum {
  margin-top: 6px; color: var(--muted); font-size: 14px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.src {
  display: inline-block; margin-top: 8px; font-size: 13px; font-weight: 600;
  text-decoration: none; border-bottom: 1px solid var(--line);
}
.src:hover { border-color: var(--ink); }

/* ---------- Cast: the row of faces above the chat ---------- */

.label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  margin-bottom: 8px;
}
.cast { min-width: 0; }
.cast-list {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 4px;
  scrollbar-width: none;
}
.cast-list::-webkit-scrollbar { display: none; }
.seat {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  flex: 1 0 70px; max-width: 110px; min-width: 0; text-align: center;
}
.seat .txt { width: 100%; min-width: 0; }
.seat .who { font-size: 11.5px; line-height: 1.25; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .meta, .seat .left { font-size: 11px; line-height: 1.25; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .left { font-variant-numeric: tabular-nums; }
.seat.empty .ring-wrap { border: 1.5px dashed var(--line); border-radius: 50%; }
.seat.empty .who { color: var(--muted); font-weight: 500; }
.seat.mine .who::after { content: " \2605"; color: var(--accent); }

.ring-wrap { position: relative; width: 52px; height: 52px; flex: 0 0 auto; }
.ring-wrap svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring-wrap circle { fill: none; stroke-width: 3; }
.ring-wrap .track { stroke: var(--line); }
.ring-wrap .bar-arc { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.ring-wrap .av { position: absolute; inset: 5px; width: auto; height: auto; }

.av {
  width: 40px; height: 40px; border-radius: 50%; overflow: hidden; flex: 0 0 auto;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 800; color: #fff; background: var(--muted);
  user-select: none;
}
.av img { width: 100%; height: 100%; object-fit: cover; display: block; }

.rooms { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.rooms button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 4px 12px; font-size: 13px; cursor: pointer;
}
.rooms button[aria-current="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

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

.chat {
  position: relative;
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.disclaimer {
  font-size: 12px; color: var(--muted); text-align: center;
  padding: 7px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.disclaimer strong { color: var(--ink); }
.log { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 14px 6px; outline: none; overscroll-behavior: contain; }

.msg { display: flex; gap: 10px; padding: 7px 0; animation: rise .28s ease-out both; }
.msg .body { min-width: 0; flex: 1; }
.msg header { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.msg .who { font-weight: 700; font-size: 14.5px; }
.msg .mood { font-size: 11.5px; color: var(--muted); }
.msg time { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.msg p { font-size: 15.5px; line-height: 1.45; overflow-wrap: anywhere; }
.msg.mine .who::after { content: " \2605"; color: var(--accent); font-weight: 400; }
.flag {
  margin-left: auto; border: 0; background: none; cursor: pointer; padding: 0 2px;
  font-size: 12px; color: var(--muted); opacity: 0; transition: opacity .15s;
}
.msg:hover .flag, .flag:focus-visible, .flag.done { opacity: 1; }
@media (hover: none) { .flag { opacity: .55; } }
.flag.done { color: var(--ok); cursor: default; }

.sys {
  text-align: center; font-size: 12.5px; color: var(--muted); padding: 8px 0;
  animation: rise .28s ease-out both;
}
.sys span { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; display: inline-block; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.empty { height: 100%; display: grid; place-content: center; text-align: center; gap: 6px; padding: 24px; color: var(--muted); }
.empty b { color: var(--ink); font-family: var(--serif); font-size: 20px; }

.typing { padding: 4px 14px 10px; font-size: 13px; color: var(--muted); min-height: 28px; }
.typing .dots i {
  display: inline-block; width: 4px; height: 4px; margin-left: 3px; border-radius: 50%; background: currentColor;
  animation: blink 1.2s infinite;
}
.typing .dots i:nth-child(2) { animation-delay: .2s; }
.typing .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.jump {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  border: 0; border-radius: 999px; padding: 7px 14px; cursor: pointer;
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 600; box-shadow: var(--shadow);
}

/* ---------- Panel (bottom sheet on phones) ---------- */

.panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--line); border-bottom: 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .25);
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow-y: auto;
  transform: translateY(105%); transition: transform .25s ease;
  visibility: hidden;
}
.panel.open { transform: none; visibility: visible; }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
.sheet-close {
  position: absolute; right: 12px; top: 10px; border: 0; background: none; font-size: 24px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 4px 8px;
}
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 20; }

.panel-title { font-family: var(--serif); font-size: 21px; line-height: 1.2; }
.panel-sub { color: var(--muted); font-size: 13.5px; margin: 4px 0 14px; }

form { display: grid; gap: 6px; }
form label { font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--muted); margin-top: 6px; display: flex; justify-content: space-between; }
form output { color: var(--ink); font-variant-numeric: tabular-nums; }
input[type="text"] {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); outline: none;
  font-size: 16px;
}
input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0; }
input:disabled { opacity: .55; }

.btn {
  margin-top: 10px; border: 0; border-radius: 10px; padding: 12px 16px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px;
  transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; filter: none; }

.status { min-height: 20px; margin-top: 10px; font-size: 14px; }
.status.err { color: var(--accent); }
.status.ok { color: var(--ok); }
.status.info { color: var(--muted); }

.queue { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.queue li { font-size: 14px; padding: 3px 0; display: flex; gap: 8px; }
.queue li .n { color: var(--muted); font-variant-numeric: tabular-nums; width: 18px; }
.queue li .m { color: var(--muted); font-size: 12.5px; }
.queue li.mine { font-weight: 700; }

.fab {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 10;
  border: 0; border-radius: 12px; padding: 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px;
  box-shadow: 0 8px 24px rgba(212, 59, 18, .3);
}

.foot { display: none; }

/* ---------- Desktop ---------- */

@media (min-width: 900px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 330px;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    grid-template-areas: "bar bar" "topic side" "cast side" "chat side" "foot foot";
    gap: 14px 18px;
    padding: 0 20px 10px;
  }
  .side { grid-area: side; display: block; min-height: 0; overflow-y: auto; scrollbar-width: thin; }
  .topic { padding: 18px 22px; }
  .sum { -webkit-line-clamp: 3; font-size: 15px; }

  .cast-list {
    display: grid; grid-template-columns: repeat(var(--seats, 10), minmax(0, 1fr));
    gap: 4px; padding: 0 4px; overflow: visible;
  }
  .seat { max-width: none; }
  .seat .who {
    font-size: 12.5px; white-space: normal; text-wrap: balance; overflow-wrap: break-word;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  }
  .ring-wrap { width: 58px; height: 58px; }

  .panel {
    position: static; transform: none; visibility: visible; max-height: none; overflow: visible;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 18px 20px 20px;
  }
  .sheet-handle, .sheet-close, .fab, .backdrop { display: none !important; }

  .log { padding: 16px 20px 6px; }
  .typing { padding: 4px 20px 12px; }

  .foot {
    display: flex; gap: 18px; justify-content: center; font-size: 12.5px; color: var(--muted); padding-bottom: 4px;
  }
  .foot a { text-decoration: none; }
  .foot a:hover { text-decoration: underline; }
}

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

/* ---------- About page ---------- */

.doc { max-width: 720px; margin: 0 auto; padding: 16px 20px 60px; }
.doc .bar { padding: 12px 0 24px; }
.doc h1 { font-family: var(--serif); font-size: 32px; line-height: 1.15; margin-bottom: 12px; }
.doc h2 { font-family: var(--serif); font-size: 22px; margin: 34px 0 8px; scroll-margin-top: 16px; }
.doc p, .doc li { margin-bottom: 10px; color: var(--ink); }
.doc ul { list-style: disc; padding-left: 20px; }
.doc .todo { background: var(--accent-soft); border-radius: 8px; padding: 2px 6px; font-weight: 600; }
.doc .back { font-size: 14px; color: var(--muted); }
.doc .bar-right .back { text-decoration: none; }
