/* ============================================================
 * AESTHSIA · TRPG 子站样式
 * 设计语言与 home / admin 同源：灰画布 + 白卡（hairline + 柔影）、
 * 胶囊按钮、micro-caps 标签、唯一红色 = 破坏性操作悬停。
 * ============================================================ */

@font-face {
  font-family: 'ReemKufiFun';
  src: url('../assets/fonts/ReemKufiFun-Bold.ttf') format('truetype');
}

:root {
  --ink: #111113;
  --paper: #ffffff;
  --canvas: #f6f6f7;
  --gray-100: #f1f1f3;
  --gray-200: #e4e4e7;
  --gray-300: #d5d5d9;
  --gray-500: #8b8b92;
  --gray-700: #55555c;
  --red: #c0392b;
  --radius: 20px;
}

* { box-sizing: border-box; }

/* hidden 属性兜底：下方 .view/#room/.avatar 等都有 display:flex，
   会压过 UA 的 [hidden]{display:none}（admin 同款坑），必须强制 */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
        'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--ink); }

/* ===================== 顶栏 ===================== */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: var(--paper);
  border-bottom: 1px solid var(--gray-100);
  z-index: 30;
}
.brand {
  text-decoration: none;
  color: var(--ink);
  font-family: 'ReemKufiFun', -apple-system, sans-serif;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 2.5px;
}
.head-right { display: flex; align-items: center; gap: 14px; }
.guest-login {
  border: 0;
  border-radius: 99px;
  padding: 8px 18px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  font-weight: 600;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--gray-700);
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  position: relative;
}
.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* 汉堡按钮（手机端展开抽屉侧栏；桌面隐藏） */
.side-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--ink);
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 2px;
}
.side-toggle:hover { background: var(--gray-100); }
.side-toggle svg { width: 20px; height: 20px; }

/* 抽屉遮罩：手机端 .side-open 时激活 */
.side-mask {
  display: none;
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(17, 17, 19, .32);
  opacity: 0;
  pointer-events: none;
  transition: opacity .32s ease;
  z-index: 40;
}

/* ===================== 布局 ===================== */
.layout {
  display: flex;
  align-items: stretch;
  height: 100vh;
  padding-top: 64px;
}
.side {
  width: 232px;
  flex-shrink: 0;
  background: var(--paper);
  border-right: 1px solid var(--gray-100);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.back-btn {
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px 0 10px;
  color: var(--ink);
  background: var(--gray-100);
  text-decoration: none;
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s ease, transform .15s ease;
}
.back-btn:hover { background: var(--gray-200); transform: translateX(-2px); }
.back-btn svg { width: 16px; height: 16px; }

.snav { display: flex; flex-direction: column; gap: 2px; }
.snav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: none;
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  text-align: left;
}
.snav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.snav-item:hover { background: var(--gray-100); color: var(--ink); }
.snav-item.active { background: var(--ink); color: var(--paper); }
.snav-item .chev {
  width: 14px;
  height: 14px;
  margin-left: auto;
  transition: transform .2s ease;
}
.snav-item.open .chev { transform: rotate(180deg); }

.ssub { display: flex; flex-direction: column; gap: 2px; padding: 2px 0 2px 14px; }
.ssub-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: none;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
  text-align: left;
  max-width: 100%;
}
.ssub-item svg { width: 14px; height: 14px; flex-shrink: 0; }
.ssub-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ssub-item:hover { background: var(--gray-100); color: var(--ink); }
.ssub-item.active { background: var(--gray-100); color: var(--ink); }
.ssub-item.add { color: var(--gray-500); }

.side-brand {
  margin: auto 8px 6px;
  font-family: 'ReemKufiFun', -apple-system, sans-serif;
  font-size: 11px;
  letter-spacing: 2.5px;
  color: var(--gray-300);
}

main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 24px 32px;
  overflow: hidden;
}
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#view-char { overflow-y: auto; }

/* ===================== 通用组件 ===================== */
.panel {
  background: var(--paper);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius);
  padding: 22px 24px;
}
.panel-label {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--gray-500);
}
.chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 99px;
  background: var(--gray-100);
  color: var(--gray-700);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .3px;
  font-variant-numeric: tabular-nums;
}
.chip.live { background: var(--ink); color: var(--paper); }
.btn-ink {
  border: 0;
  border-radius: 99px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 20px;
}
.btn-ink:hover { opacity: .88; }
.btn-ink:disabled { opacity: .45; cursor: default; }
.btn-ink.sm { padding: 8px 16px; font-size: 13px; }
.btn-ghost {
  border: 1px solid var(--gray-300);
  border-radius: 99px;
  background: none;
  color: var(--gray-700);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
}
.btn-ghost:hover { border-color: var(--ink); color: var(--ink); }

.avatar.rainbow-avatar::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  z-index: -1;
  background: conic-gradient(#ff5e5e, #ffb44d, #ffe74d, #5eff8f, #5ec9ff, #b45eff, #ff5e5e);
  animation: trpg-halo 2s linear infinite;
}
@keyframes trpg-halo { to { transform: rotate(1turn); } }

/* ===================== 未登录 / 人物设定 ===================== */
.guest-card { max-width: 460px; margin: 12vh auto 0; text-align: center; }
.guest-title { font-size: 20px; font-weight: 700; margin: 14px 0 22px; }

.char-panel { max-width: 720px; }
.char-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.char-row { display: flex; align-items: center; gap: 14px; }
.char-avatar { width: 52px; height: 52px; font-size: 20px; }
.char-name { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.2px; }
.char-sub { margin: 0; font-size: 12.5px; color: var(--gray-500); }
.char-desc {
  margin: 14px 0 0;
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--gray-700);
  white-space: pre-wrap;
  word-break: break-word;
}
.char-desc.empty { color: var(--gray-300); }

.char-edit { margin-top: 18px; display: flex; flex-direction: column; gap: 6px; }
.char-edit label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .5px;
  color: var(--gray-500);
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.ce-count { font-weight: 500; color: var(--gray-300); font-variant-numeric: tabular-nums; }
.char-edit input,
.char-edit textarea {
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--canvas);
  outline: none;
  resize: none;
}
.char-edit input:focus,
.char-edit textarea:focus {
  background: var(--paper);
  border-color: var(--ink);
}
.char-edit-bar { display: flex; gap: 10px; margin-top: 14px; }

/* ===================== 故事推演：加入房间（无卡片，大字居中） ===================== */
.join-card { max-width: 460px; margin: 17vh auto 0; text-align: center; padding: 0 24px; }
.join-title {
  margin: 0 0 26px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.3px;
}
.join-row { display: flex; gap: 10px; justify-content: center; }
.join-row input {
  flex: 1;
  max-width: 300px;
  min-width: 0;
  border: 1px solid var(--gray-200);
  border-radius: 99px;
  padding: 11px 20px;
  background: var(--paper);
  outline: none;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 600;
  text-align: center;
}
.join-row input::placeholder {
  font-weight: 300;
  letter-spacing: 1.5px;
  color: var(--gray-300);
}
.join-row input:focus { border-color: var(--ink); }
.join-err { margin: 12px 0 0; font-size: 13px; color: var(--red); text-align: center; min-height: 1em; }

/* ===================== 故事推演：房间 ===================== */
#room { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.room-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.room-name { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.3; }

/* 手机端切换按钮（桌面隐藏）：两侧输入行左端圆形黑钮，切 推演/闲聊 */
.flip {
  display: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(17, 17, 19, .18);
  transition: transform .3s cubic-bezier(.22, 1.2, .36, 1);
}
.flip svg { width: 18px; height: 18px; transition: transform .35s cubic-bezier(.22, 1.2, .36, 1); }
.flip:active { transform: scale(.9); }
#room.chat-front .flip svg { transform: rotate(180deg); }

.split {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 14px;
}
.pane {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--gray-100);
  border-radius: var(--radius);
  overflow: hidden;
}
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--gray-100);
}
.pane-label {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: normal;
  color: var(--gray-700);
}
.pane-head .chip { flex-shrink: 0; }

.story-log, .chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
}

/* 故事条目：轮次眉标 + 正文 */
.story-item { margin-bottom: 22px; }
.story-item:last-child { margin-bottom: 0; }
.story-round {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--gray-300);
  margin-bottom: 6px;
}
.story-text { margin: 0; font-size: 15px; line-height: 1.8; white-space: pre-wrap; word-break: break-word; }
.gm-typing {
  margin: 0;
  color: var(--gray-500);
  font-size: 14px;
}
.gm-typing .dots::after {
  content: '…';
  animation: trpg-dots 1.2s steps(4, end) infinite;
}
@keyframes trpg-dots { 0% { content: ''; } 25% { content: '·'; } 50% { content: '··'; } 75% { content: '···'; } }

/* 聊天气泡：QQ 式气泡 + Discord 连发分组（同一人连续消息只画一次头像/名字） */
.chat-item { display: flex; gap: 10px; margin-bottom: 16px; }
.chat-item:last-child { margin-bottom: 0; }
.chat-item.grouped { margin-bottom: 2px; }
.chat-gutter { width: 30px; flex-shrink: 0; }
.chat-ava {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gray-200);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-700);
  overflow: hidden;
  position: relative;
}
.chat-ava img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.chat-body { min-width: 0; max-width: calc(100% - 40px); }
.chat-nick {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .2px;
  color: var(--gray-500);
}
.chat-content {
  margin: 0;
  display: inline-block;
  padding: 8px 13px;
  border-radius: 4px 16px 16px 16px;
  background: var(--gray-100);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-item.mine .chat-content { background: var(--ink); color: var(--paper); }
/* 入场动画：小幅上浮（幅度已收敛）；只给新消息加 .in（JS 控制），轮询不重播 */
@keyframes chat-in {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: none; }
}
.chat-item.in { animation: chat-in .32s cubic-bezier(.25, .7, .35, 1) both; }
.chat-empty { color: var(--gray-300); font-size: 13.5px; text-align: center; margin-top: 30px; }

/* 输入区 */
.composer {
  border-top: 1px solid var(--gray-100);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.composer input {
  width: 100%;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 9px 13px;
  background: var(--canvas);
  outline: none;
  resize: none;
}
.composer input:focus { background: var(--paper); border-color: var(--ink); }
.composer input { border-radius: 99px; }
.composer > input { flex: 1; min-width: 0; }
#chat-form, #story-form { flex-direction: row; align-items: center; gap: 10px; }
#chat-form input, #story-form input { flex: 1; }

/* ===================== Toast ===================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%) translateY(16px);
  background: var(--ink);
  color: var(--paper);
  font-size: 13.5px;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 99px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 50;
  max-width: calc(100vw - 40px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===================== 手机端（≤900）：侧栏横排 + 双全屏面板切换 ===================== */
@media (max-width: 900px) {
  header { height: 56px; padding: 0 16px; }
  .side-toggle { display: flex; }
  .side-mask { display: block; }

  /* 侧栏改为左侧抽屉：收起在屏幕外，汉堡展开（不挪到顶部） */
  .layout {
    height: calc(100dvh - 56px);
    padding-top: 0;
    margin-top: 56px;
    flex-direction: column;
  }
  .side {
    position: fixed;
    top: 56px;
    bottom: 0;
    left: 0;
    width: 250px;
    z-index: 45;
    transform: translateX(-105%);
    transition: transform .38s cubic-bezier(.22, .61, .36, 1);
  }
  .side-open .side { transform: none; box-shadow: 24px 0 48px rgba(17, 17, 19, .12); }
  .side-open .side-mask { opacity: 1; pointer-events: auto; }
  .side-brand { display: none; }

  main { padding: 12px; }

  /* 双面板：各自独立占满，切换 = 遮罩面积变化（不动排版） */
  .split { display: block; position: relative; }
  .pane {
    position: absolute;
    inset: 0;
    transition: transform .3s cubic-bezier(.22, .61, .36, 1), opacity .3s ease;
  }
  .pane[data-m='back'] {
    transform: translateX(24px);
    opacity: 0;
    pointer-events: none;
  }
  #pane-chat[data-m='back'] { transform: translateX(-24px); }

  .flip { display: flex; }

  .guest-card, .char-panel { margin-top: 4vh; }
  .join-card { margin-top: 13vh; }
}
