/* Таверна — тёплая свечная тема, mobile-first */
:root {
  --bg: #171210;
  --bg2: #1f1915;
  --panel: #251e18;
  --panel2: #2d241d;
  --line: #3a2f25;
  --ink: #e8ddcb;
  --ink-dim: #a4947d;
  --amber: #e0a43c;
  --amber-soft: #c9a227;
  --ember: #c96f3b;
  --ai: #9d7bff;
  --ok: #7cb971;
  --bad: #d4695f;
  --radius: 14px;
  --serif: Georgia, 'Times New Roman', serif;
  --sans: -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
#app { height: 100dvh; display: flex; flex-direction: column; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select {
  font: inherit; color: var(--ink);
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--amber-soft); }
a { color: var(--amber); }

/* ---------- верхняя панель ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: linear-gradient(180deg, #201813, var(--bg2));
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 {
  font-family: var(--serif); font-size: 19px; font-weight: 600;
  letter-spacing: .4px; color: var(--amber);
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar .back { font-size: 22px; padding: 2px 8px; color: var(--ink-dim); }
.iconbtn { font-size: 19px; padding: 4px 8px; border-radius: 8px; }
.iconbtn:active { background: var(--panel2); }

/* ---------- экраны ---------- */
.screen { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: env(safe-area-inset-bottom); }
.pad { padding: 16px 14px; }

/* ---------- логин ---------- */
.login-wrap {
  min-height: 100dvh; display: flex; flex-direction: column;
  justify-content: center; align-items: center; padding: 24px; gap: 8px;
  background: radial-gradient(ellipse at 50% 0%, #2a1f14 0%, var(--bg) 70%);
}
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 10px; }
.login-card .logo { font-size: 52px; text-align: center; }
.login-card h1 { font-family: var(--serif); text-align: center; color: var(--amber); font-size: 28px; margin-bottom: 8px; }
.tabs { display: flex; gap: 6px; margin-bottom: 6px; }
.tabs button { flex: 1; padding: 9px; border-radius: 10px; background: var(--panel); color: var(--ink-dim); }
.tabs button.on { background: var(--amber-soft); color: #241b0c; font-weight: 600; }

.btn {
  background: var(--amber-soft); color: #241b0c; font-weight: 600;
  padding: 11px 16px; border-radius: 10px; text-align: center;
}
.btn:disabled { opacity: .5; }
.btn.ghost { background: var(--panel2); color: var(--ink); font-weight: 500; }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn.danger { background: #4a2a26; color: #e8b1aa; }

.msg-err { color: var(--bad); font-size: 14px; min-height: 18px; text-align: center; }

/* ---------- список комнат ---------- */
.cat-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--ink-dim); margin: 18px 2px 8px;
}
.room-card {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px; margin-bottom: 8px; text-align: left;
}
.room-card:active { background: var(--panel2); }
.room-card .ric { font-size: 24px; }
.room-card .rt { font-family: var(--serif); font-size: 17px; color: var(--ink); }
.room-card .rd { font-size: 13px; color: var(--ink-dim); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.room-card .rmeta { margin-left: auto; text-align: right; font-size: 12px; color: var(--ink-dim); white-space: nowrap; }

/* ---------- лента постов ---------- */
.feed { padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 12px; }
.post {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
  position: relative;
}
.post.ai { border-color: #46386b; background: #231d2e; }
.post.ooc { border-style: dashed; opacity: .85; }
.post-head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.ava {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; background: var(--bg2); border: 2px solid var(--line);
}
.post-head .who { font-weight: 600; font-size: 15px; }
.post-head .sub { font-size: 12px; color: var(--ink-dim); }
.post-head .menu { margin-left: auto; color: var(--ink-dim); font-size: 18px; padding: 4px 6px; }
.post-body { font-family: var(--serif); font-size: 16.5px; line-height: 1.62; white-space: pre-wrap; word-wrap: break-word; }
.post-body em { color: var(--amber); font-style: italic; }

/* чат-режим — компактнее, без книжного шрифта */
.chatmode .post { padding: 9px 12px; border-radius: 12px; }
.chatmode .post-body { font-family: var(--sans); font-size: 15.5px; line-height: 1.45; }
.chatmode .post-head { margin-bottom: 4px; }
.chatmode .ava { width: 26px; height: 26px; font-size: 14px; }
.chatmode .feed { gap: 7px; }

.typing { color: var(--ai); font-size: 14px; padding: 4px 16px 10px; font-style: italic; }
.loadmore { align-self: center; color: var(--ink-dim); font-size: 14px; padding: 8px 14px; }

/* ---------- композер ---------- */
.composer {
  border-top: 1px solid var(--line); background: var(--bg2);
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
  display: flex; flex-direction: column; gap: 7px;
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 38dvh; min-height: 42px;
  border-radius: 12px; line-height: 1.45;
}
.composer .send {
  background: var(--amber-soft); color: #241b0c; border-radius: 50%;
  width: 42px; height: 42px; font-size: 19px; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.composer-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chip {
  font-size: 13px; padding: 5px 11px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--ink-dim);
  white-space: nowrap;
}
.chip.on { border-color: var(--amber-soft); color: var(--amber); }
.chip.ai-chip { border-color: #46386b; color: var(--ai); }

/* ---------- модалки ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.sheet {
  background: var(--panel); border-radius: 18px 18px 0 0;
  width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  display: flex; flex-direction: column; gap: 10px;
}
.sheet h2 { font-family: var(--serif); color: var(--amber); font-size: 20px; }
.sheet label { font-size: 13px; color: var(--ink-dim); margin-bottom: -5px; }
.row2 { display: flex; gap: 8px; }
.row2 > * { flex: 1; }

/* ---------- таблички / списки ---------- */
.list-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 13px; margin-bottom: 8px;
}
.list-item .grow { flex: 1; min-width: 0; }
.list-item .t { font-weight: 600; }
.list-item .s { font-size: 13px; color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; }
.usage-bar { height: 6px; border-radius: 3px; background: var(--bg2); overflow: hidden; margin-top: 6px; }
.usage-bar > div { height: 100%; background: linear-gradient(90deg, var(--amber-soft), var(--ember)); }
.big-num { font-size: 26px; font-family: var(--serif); color: var(--amber); }

.chronicle-box {
  margin: 12px; padding: 13px 15px; border-radius: var(--radius);
  background: #241d14; border: 1px solid #4a3a22;
  font-size: 14px; line-height: 1.55; color: #d6c7a8; white-space: pre-wrap;
}
.chronicle-box .ch-title { font-family: var(--serif); color: var(--amber); font-size: 15px; margin-bottom: 6px; }

.hint { font-size: 13px; color: var(--ink-dim); line-height: 1.4; }
.sect { margin-top: 22px; }
.sect h3 { font-family: var(--serif); color: var(--amber); font-size: 17px; margin-bottom: 10px; }

@media (min-width: 760px) {
  .screen, .topbar { padding-left: max(14px, calc(50vw - 360px)); padding-right: max(14px, calc(50vw - 360px)); }
  .composer { padding-left: max(10px, calc(50vw - 360px)); padding-right: max(10px, calc(50vw - 360px)); }
  .overlay { align-items: center; }
  .sheet { border-radius: 18px; }
}
