:root {
  color-scheme: light;
  --ink: #19202a;
  --muted: #667085;
  --line: #d8dee8;
  --panel: rgba(255, 255, 255, 0.88);
  --accent: #0f8b8d;
  --accent-2: #d64550;
  --bg: #f3f6f4;
  --shadow: 0 18px 50px rgba(22, 32, 42, 0.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 139, 141, 0.12), transparent 38%),
    linear-gradient(315deg, rgba(214, 69, 80, 0.12), transparent 34%),
    var(--bg);
}
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 12px 18px;
  font-weight: 700;
  cursor: pointer;
}
button:disabled { opacity: .55; cursor: wait; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 30px;
}
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}
.auth-card h1, .admin-header h1, .topbar h1 { margin: 8px 0 4px; letter-spacing: 0; }
.auth-card p { color: var(--muted); margin: 0 0 24px; }
.form-stack { display: grid; gap: 14px; }
.form-stack.compact { margin-top: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span-2 { grid-column: span 2; }
label { display: grid; gap: 7px; font-weight: 700; color: #344054; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.alert {
  border-radius: 8px;
  padding: 12px 14px;
  margin: 0 0 16px;
  font-weight: 700;
}
.alert.error { background: #ffe8e7; color: #9f1f2c; }
.alert.success { background: #e7f6ef; color: #116149; }

.chat-app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 42vw) 1fr;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: 18px 18px 104px;
}
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar nav, .admin-header nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.topbar a, .admin-header a {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.7);
  border-radius: 8px;
  padding: 9px 12px;
  font-weight: 700;
}
.eyebrow {
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.character-stage {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(260px, 1fr) auto;
  gap: 16px;
}
.portrait-frame {
  overflow: hidden;
  border-radius: 8px;
  background: #202631;
  box-shadow: var(--shadow);
}
.portrait-frame img {
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 210px);
  object-fit: cover;
  display: block;
}
.latest-line {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.75);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  font-size: clamp(20px, 2.5vw, 34px);
  line-height: 1.45;
  font-weight: 800;
}
.history-panel {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 4px 16px;
}
.message {
  max-width: 78%;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.86);
  padding: 12px 14px;
}
.message.user {
  align-self: flex-end;
  background: #e9f8f5;
  border-color: #b7e3dc;
}
.message.assistant { align-self: flex-start; }
.message.system {
  max-width: 100%;
  align-self: center;
  background: #fff3d7;
}
.message-role {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 5px;
}
.message-body { line-height: 1.65; overflow-wrap: anywhere; }
.composer {
  position: fixed;
  left: 18px;
  right: 18px;
  bottom: 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  background: rgba(255,255,255,.92);
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 10px;
}
.composer textarea {
  min-height: 48px;
  max-height: 132px;
  resize: none;
}

.admin-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px;
}
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.panel {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.75);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 20px; }
.wide { grid-column: 1 / -1; }
.kv {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 8px 12px;
  margin: 0;
}
.kv dt { color: var(--muted); font-weight: 800; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.image-tile {
  margin: 0;
  display: grid;
  gap: 8px;
}
.image-tile img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

@media (max-width: 768px) {
  .chat-app {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 12px 98px;
  }
  .topbar { align-items: flex-start; }
  .topbar h1 { font-size: 24px; }
  .character-stage {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .portrait-frame img {
    max-height: 40vh;
    min-height: 240px;
  }
  .latest-line {
    font-size: 22px;
    padding: 14px;
  }
  .history-panel {
    overflow: visible;
    padding-bottom: 0;
  }
  .message { max-width: 92%; }
  .composer {
    left: 10px;
    right: 10px;
    bottom: 10px;
    grid-template-columns: 1fr 76px;
  }
  .admin-shell { padding: 14px; }
  .admin-header { align-items: flex-start; }
  .admin-grid, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .kv { grid-template-columns: 112px 1fr; }
}
.member-bar,.points-badge{display:inline-block;border:1px solid var(--line);background:rgba(255,255,255,.76);border-radius:8px;padding:9px 12px;font-weight:800;margin-bottom:16px}
.cast-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:16px}
.cast-card{display:grid;gap:10px;background:var(--panel);border:1px solid rgba(255,255,255,.75);border-radius:8px;box-shadow:var(--shadow);overflow:hidden}
.cast-card img{width:100%;aspect-ratio:4/5;object-fit:cover;background:#202631}
.cast-card div{padding:0 14px 14px}.cast-card h2{margin:0 0 6px}.cast-card p{margin:0;color:var(--muted);line-height:1.55}
.member-list{display:grid;gap:8px}.member-row{display:flex;align-items:center;justify-content:space-between;gap:12px;border:1px solid var(--line);border-radius:8px;background:#fff;padding:10px 12px}
.performer-form{border-top:1px solid var(--line);padding-top:14px;margin-top:14px}.point-empty{font-weight:800;color:#9f1f2c}
hr{border:0;border-top:1px solid var(--line);margin:16px 0}
.chat-app{height:100dvh;overflow:hidden;padding-bottom:154px}
.chat-app .character-stage{position:sticky;top:86px;align-self:start;height:calc(100dvh - 250px);min-height:0}
.chat-app .portrait-frame{min-height:0}
.chat-app .portrait-frame img{max-height:none;height:100%;min-height:0}
.chat-app .history-panel{height:calc(100dvh - 198px);overflow:auto;padding-bottom:180px;overscroll-behavior:contain}
.chat-app .latest-line{position:fixed;left:18px;right:18px;bottom:88px;z-index:20;max-height:24vh;overflow:auto;font-size:clamp(18px,2vw,26px)}
.chat-app .composer{z-index:30}
@media(max-width:768px){
  .cast-grid{grid-template-columns:1fr}.member-row{align-items:flex-start}
  .chat-app{height:100dvh;overflow:hidden;padding:10px 10px 150px}
  .chat-app .topbar{flex:0 0 auto}
  .chat-app .character-stage{position:relative;top:auto;height:auto;flex:0 0 auto}
  .chat-app .portrait-frame img{height:auto;max-height:30vh;min-height:150px}
  .chat-app .history-panel{flex:1 1 auto;min-height:0;height:auto;overflow:auto;padding-bottom:180px}
  .chat-app .latest-line{left:10px;right:10px;bottom:84px;max-height:22vh;font-size:18px;padding:12px}
}
.member-bar,.points-badge{display:inline-block;border:1px solid var(--line);background:rgba(255,255,255,.76);border-radius:8px;padding:9px 12px;font-weight:800;margin-bottom:16px}
.cast-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:16px}
.cast-card{display:grid;gap:10px;background:var(--panel);border:1px solid rgba(255,255,255,.75);border-radius:8px;box-shadow:var(--shadow);overflow:hidden}
.cast-card img{width:100%;aspect-ratio:4/5;object-fit:cover;background:#202631}
.cast-card div{padding:0 14px 14px}.cast-card h2{margin:0 0 6px}.cast-card p{margin:0;color:var(--muted);line-height:1.55}
.member-list{display:grid;gap:8px}.member-row{display:flex;align-items:center;justify-content:space-between;gap:12px;border:1px solid var(--line);border-radius:8px;background:#fff;padding:10px 12px}
.performer-form{border-top:1px solid var(--line);padding-top:14px;margin-top:14px}.point-empty{font-weight:800;color:#9f1f2c}
hr{border:0;border-top:1px solid var(--line);margin:16px 0}
.chat-app{height:100dvh;overflow:hidden;padding-bottom:154px}
.chat-app .character-stage{position:sticky;top:86px;align-self:start;height:calc(100dvh - 250px);min-height:0}
.chat-app .portrait-frame{min-height:0}
.chat-app .portrait-frame img{max-height:none;height:100%;min-height:0}
.chat-app .history-panel{height:calc(100dvh - 198px);overflow:auto;padding-bottom:180px;overscroll-behavior:contain}
.chat-app .latest-line{position:fixed;left:18px;right:18px;bottom:88px;z-index:20;max-height:24vh;overflow:auto;font-size:clamp(18px,2vw,26px)}
.chat-app .composer{z-index:30}
@media(max-width:768px){
  .cast-grid{grid-template-columns:1fr}.member-row{align-items:flex-start}
  .chat-app{height:100dvh;overflow:hidden;padding:10px 10px 150px}
  .chat-app .topbar{flex:0 0 auto}
  .chat-app .character-stage{position:relative;top:auto;height:auto;flex:0 0 auto}
  .chat-app .portrait-frame img{height:auto;max-height:30vh;min-height:150px}
  .chat-app .history-panel{flex:1 1 auto;min-height:0;height:auto;overflow:auto;padding-bottom:180px}
  .chat-app .latest-line{left:10px;right:10px;bottom:84px;max-height:22vh;font-size:18px;padding:12px}
}

/* CHAT_LAYOUT_V3_START */
.classic-chat.chat-app {
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(320px, 48vh) minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  gap: 0;
  padding: 0;
  background: #eef2f0;
}
.classic-chat .cast-hero {
  grid-row: 1 / 3;
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 100dvh;
  align-self: start;
  overflow: hidden;
  background: #111820;
  border-right: 1px solid #cbd5df;
}
.classic-chat .cast-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.classic-chat .cast-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  color: #fff;
  background: linear-gradient(180deg, rgba(0,0,0,.62), rgba(0,0,0,.18) 38%, transparent 72%);
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.classic-chat .cast-overlay h1 {
  margin: 1px 0 0;
  font-size: 24px;
  line-height: 1.1;
}
.classic-chat .cast-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}
.classic-chat .cast-actions a,
.classic-chat .points-badge {
  border: 1px solid rgba(255,255,255,.5);
  background: rgba(0,0,0,.42);
  color: #fff;
  border-radius: 6px;
  padding: 6px 8px;
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  text-shadow: none;
}
.classic-chat .history-panel {
  grid-column: 2;
  grid-row: 1;
  height: auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  display: block;
  padding: 8px 10px 10px;
  background: #f8fafc;
  border-bottom: 1px solid #d8dee8;
}
.classic-chat .message {
  max-width: none;
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 4px 0;
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  border-bottom: 1px solid #e6ebf0;
}
.classic-chat .message.user,
.classic-chat .message.assistant,
.classic-chat .message.system {
  align-self: auto;
  background: transparent;
  border-color: #e6ebf0;
}
.classic-chat .message-role {
  display: inline;
  min-width: 0;
  margin: 0 8px 0 0;
  color: #475467;
  font-size: 12px;
  font-weight: 900;
}
.classic-chat .message-role::after {
  content: ":";
}
.classic-chat .message-body {
  display: inline;
  line-height: inherit;
}
.classic-chat .message.user .message-role {
  color: #0f766e;
}
.classic-chat .message.assistant .message-role {
  color: #b42318;
}
.classic-chat .composer {
  grid-column: 2;
  grid-row: 2;
  position: static;
  left: auto;
  right: auto;
  bottom: auto;
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
  align-items: end;
  margin: 0;
  padding: 8px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #e9eef3;
}
.classic-chat .composer textarea {
  min-height: 42px;
  max-height: 96px;
  padding: 9px 10px;
  border-radius: 6px;
}
.classic-chat .composer button {
  min-height: 42px;
  border-radius: 6px;
  padding: 9px 10px;
}
@media (max-width: 768px) {
  .classic-chat.chat-app {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100dvh;
    padding: 0;
  }
  .classic-chat .cast-hero {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    aspect-ratio: 3 / 4;
    max-height: min(52dvh, 520px);
    border-right: 0;
    border-bottom: 1px solid #cbd5df;
  }
  .classic-chat .cast-overlay {
    padding: 8px;
  }
  .classic-chat .cast-overlay h1 {
    font-size: 22px;
  }
  .classic-chat .cast-actions a,
  .classic-chat .points-badge {
    font-size: 11px;
    padding: 5px 7px;
  }
  .classic-chat .history-panel {
    grid-column: 1;
    grid-row: 2;
    height: auto;
    padding: 7px 9px;
  }
  .classic-chat .message {
    font-size: 13px;
    padding: 3px 0;
  }
  .classic-chat .composer {
    grid-column: 1;
    grid-row: 3;
    grid-template-columns: 1fr 66px;
  }
}
/* CHAT_LAYOUT_V3_END */
