/* Базовые переменные и каркас. Дизайн пока черновой — красоту наводим позже,
   поэтому все цвета собраны здесь: поменять палитру = поменять переменные.
   Внутри Telegram подхватываются цвета темы игрока (--tg-theme-*). */

:root {
  /* Формат «только телефон»: ВСЁ приложение (шапка, экран, нижнее меню)
     живёт в колонке шириной с телефон. На широком мониторе — «телефон»
     по центру, по бокам пусто. Отдельного десктоп-дизайна нет (ПЛАН §6). */
  --app-max-w: 430px;
  /* «Таверна»: тёмные доски, бумажные панели с пиксельными углами, цвета сняты
     со спрайтов комнат. Своя палитра вместо цветов темы Telegram. */
  --wood: #331b11;          /* фон-доски */
  --ink: #2e1a14;           /* контур, как у спрайтов */
  --on-wood: #f6e3c0;       /* текст на дереве */
  --on-wood-dim: rgba(246, 227, 192, .68);
  --gold: #f2c35a;
  --bg: #331b11;
  --bg-card: #f6ead3;       /* бумага панелей */
  --paper-hi: #fff8e8;
  --paper-lo: #dcc6a0;
  --sunk: #ebdcbf;
  --line: #dcc6a0;
  --text: #2e1a14;          /* текст внутри панелей */
  --text-dim: #7a5d4c;
  --text-faint: #9a7f6c;
  --accent: #b9553f;        /* кирпич */
  --accent-hi: #d4705a;
  --accent-deep: #7e3426;
  --accent-text: #fff3e3;
  --accent-ink: #9c4430;
  --action-bg: #b9553f;
  --cream: #ebdcbf;
  --honey: #efc057;
  --honey-soft: #f8e6b8;
  --honey-ink: #6e4a10;
  --sage: #6f8f4f;
  --sage-soft: #dfe7cf;
  --sage-ink: #43592f;
  --danger: #b9553f;
  --ok: #6f8f4f;
  --radius: 0px;
  --control-gap: 12px;
  --control-border: #dcc6a0;
  --shadow: none;
  --header-h: 60px;
  --nav-h: 96px;
  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: var(--app-max-w);
  margin: 0 auto;
  background: var(--bg);
}

/* В широком окне (комп) вокруг «телефона» — тёмное поле и рамка */
@media (min-width: 480px) {
  body { background: #0b0806; }
  #app {
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 70px rgba(0, 0, 0, 0.6);
  }
}

.hidden { display: none !important; }

/* Невидимый, но место в сетке занимает (для кнопки «назад» в шапке,
   иначе аватар съезжает из центра в освободившуюся колонку). */
.invisible { visibility: hidden !important; }

/* ── Шапка ─────────────────────────────────────────── */

#header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.header-btn {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border: none;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.avatar-btn {
  border: none;
  background: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  justify-self: center;
}

.avatar-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.25);
}

.avatar-circle img { width: 100%; height: 100%; object-fit: cover; }

.header-cafe-name {
  font-size: 11px;
  color: var(--text-dim);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Экран ─────────────────────────────────────────── */

#screen {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  width: 100%;
}

/* ── Нижняя навигация ──────────────────────────────── */

#zone-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-max-w);
  z-index: 10;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.nav-item {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  position: relative;
  margin: 5px 4px;
  border-radius: 13px;
  transition: background-color .15s ease, color .15s ease;
}

.nav-item .nav-emoji { font-size: 22px; }

.nav-item.active {
  color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent) 14%, var(--bg));
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 65%, transparent);
  font-weight: 700;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  top: 0;
  width: 24px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}

.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.cafe-activity {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 10px);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: calc(var(--app-max-w) - 32px);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--text) 16%, transparent);
  border-radius: 13px;
  background: var(--bg-card);
  box-shadow: 0 3px 16px #0002;
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
}
.cafe-activity[hidden] { display: none; }
.cafe-activity-label { flex-shrink: 0; color: var(--text-dim); font-size: 10px; }
.cafe-activity-text { min-width: 0; overflow-wrap: anywhere; }
.cafe-activity.is-milestone { border-color: var(--accent); }
.cafe-activity.is-milestone .cafe-activity-label { color: var(--accent-ink); font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  .nav-item, .nav-item.active .nav-emoji { transition: none !important; }
}

.nav-item.active .nav-emoji {
  transform: translateY(-2px) scale(1.12);
  transition: transform 0.15s ease;
}

/* ── Общие блоки ───────────────────────────────────── */

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.muted { color: var(--text-dim); }

.btn {
  min-height: 44px;
  display: inline-block;
  border: 1px solid color-mix(in srgb, var(--accent-text) 42%, var(--action-bg));
  border-radius: var(--radius);
  background: var(--action-bg);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 18px;
  cursor: pointer;
}

.btn.secondary, .btn.btn-secondary { background: var(--bg-card); color: var(--text); border-color: var(--control-border); }

.button-stack { display: flex; flex-direction: column; gap: var(--control-gap); margin-bottom: 16px; }
.button-stack > .btn { width: 100%; margin: 0; }
.admin-btn + .admin-btn { margin-top: var(--control-gap); }

/* ── Тосты и загрузка ──────────────────────────────── */

#toast-holder {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-max-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.2s ease;
}

.toast.error { border-left: 3px solid var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--bg-card) 40%, rgba(255, 255, 255, 0.06) 50%, var(--bg-card) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}

@keyframes shimmer {
  from { background-position: 130% 0; }
  to { background-position: -30% 0; }
}

/* В шапке центральное место принадлежит кафе, личный профиль — справа. */
.cafe-header-btn { border:0; background:none; color:var(--text); display:flex; flex-direction:column; align-items:center; justify-content:center; justify-self:center; min-width:0; max-width:100%; min-height:48px; padding:3px 6px; cursor:pointer; }
.cafe-header-icon { font-size:25px; line-height:28px; }
.cafe-header-btn .header-cafe-name { max-width:min(230px, calc(100vw - 132px)); color:var(--text); font-weight:600; font-size:12px; }
.user-header-btn { position:relative; display:flex; align-items:center; justify-content:center; }
.user-header-btn .avatar-circle { width:34px; height:34px; font-size:13px; }
.user-header-gear { position:absolute; right:0; bottom:1px; background:var(--bg-card); border-radius:50%; width:19px; height:19px; font-size:13px; line-height:19px; }
