:root {
  --bg: #151316; --paper: #f5f0ed; --overlay: #151316;
  --accent: #d73562; --accent-soft: #342129; --muted: #aeacb1;
  --surface: #211e22; --surface-soft: #1c1a1e; --border: #403b42;
  --border-soft: #333438; --nav-h: 64px; --header-h: 64px;
}
:root[data-theme="light"] {
  --bg: #fafafa; --paper: #202125; --overlay: #fafafa;
  --accent: #b9204c; --accent-soft: #f9e8ee; --muted: #636168;
  --surface: #eeeeef; --surface-soft: #f3f3f4; --border: #c7c6ca; --border-soft: #dedde0;
}
* { letter-spacing: 0; }
button, input, textarea, select { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button:disabled { opacity: .45; cursor: default; }
.hidden { display: none !important; }
.brand-header { position: fixed; top: var(--sat); left: 0; right: 0; height: var(--header-h); display: flex; align-items: center; padding: 0 24px; border-bottom: 1px solid var(--border-soft); background: var(--bg); z-index: 61; }
.brand { display: inline-flex; align-items: center; height: 100%; color: var(--paper); text-decoration: none; white-space: nowrap; }
.brand-logo { display: block; width: 58px; height: 64px; object-fit: contain; filter: brightness(0) invert(1); opacity: .92; }
:root[data-theme="light"] .brand-logo { filter: brightness(0); }
.brand-mark { font-size: 13px; color: var(--muted); margin-left: 24px; }
.qr-btn, .more-btn, body.has-master-bar .qr-btn, body.has-master-bar .more-btn { width: 44px; height: 44px; top: calc(14px + var(--sat)); background: transparent; border: 0; border-radius: 8px; z-index: 62; }
.more-btn, body.has-master-bar .more-btn { right: 16px; }
.qr-btn, body.has-master-bar .qr-btn { right: 64px; }
.qr-btn::after, .more-btn::after, .day-btn::after { display: none; }
.app { height: 100dvh; padding: calc(var(--header-h) + var(--sat)) 16px calc(var(--nav-h) + var(--sab)); max-width: 680px; margin: auto; }
.deck-heading { width: 100%; max-width: 480px; padding: 19px 4px 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 0 0 auto; }
.deck-heading h1 { font-size: clamp(18px, 5vw, 21px); line-height: 1.15; margin: 4px 0; font-weight: 600; letter-spacing: -.01em; }
.eyebrow { font-size: 11px; color: var(--muted); font-weight: 600; margin: 0 0 6px; }
.day-btn, body.has-master-bar .day-btn { position: static; width: 44px; height: 44px; flex: 0 0 auto; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--surface); }
.stage { padding: 8px 8px; gap: 0; }
.card-wrap { width: auto; height: 100%; max-width: min(calc(100vw - 40px), 360px); max-height: calc(100% - 4px); }
.card, .card-face { border-radius: 8px; }
.card { box-shadow: 0 12px 32px #0004; }
.phrase { font-size: 24px; }
.hint { display: none; }
.like-btn, .share-btn { width: 44px; height: 44px; border-radius: 50%; background: #18191ce8; color: #fff; border: 1px solid #ffffff35; }
.like-btn { top: 12px; right: 12px; }
.share-btn { top: 12px; left: 12px; }
.day-badge { display: none; }
.controls { gap: 6px; padding: 4px 0 12px; max-width: 440px; }
.controls-top { display: none; }
.deck-meta { width: 100%; display: flex; align-items: center; justify-content: space-between; min-height: 44px; gap: 8px; }
.deck-meta #histNav { display: flex; margin: 0; }
.deck-meta .hist-nav { border: 0; border-radius: 8px; background: transparent; }
.hist-btn { width: 44px; height: 44px; border: 0; background: transparent; }
#cardCaption { color: var(--muted); font-size: 13px; }
.draw-row { width: 100%; }
.btn { font-size: 16px; min-height: 48px; border-radius: 8px; padding: 12px 16px; }
.btn-primary, .more-primary, .pw-buy { background: var(--accent); border-color: var(--accent); }
.foot-row { width: 100%; max-width: none; gap: 8px; }
.foot-row .btn { font-size: 14px; min-height: 42px; padding: 8px 4px; }
.foot-row #addResultBtn { color: var(--paper); display: flex; gap: 7px; justify-content: center; align-items: center; background: transparent; border: 0; }
.foot-row #addResultBtn svg { width: 17px; }
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + var(--sab)); padding: 6px max(8px, var(--sal)) calc(8px + var(--sab)); background: var(--bg); border-top: 1px solid var(--border-soft); display: grid; grid-template-columns: repeat(5, minmax(54px, 1fr)); z-index: 69; overflow: hidden; }
.bottom-nav button { min-width: 0; width: 100%; overflow: hidden; border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; padding: 2px 1px; font-size: 11px; cursor: pointer; white-space: nowrap; }
.bottom-nav button svg { width: 22px; height: 22px; stroke-width: 1.6; }
.bottom-nav button span { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.1; }
.bottom-nav button[aria-current="page"] { color: var(--accent); }
.bottom-nav button[aria-current="page"] svg { stroke-width: 2.2; }
.experience-page, #favOverlay, #catalogOverlay { position: fixed; inset: calc(var(--header-h) + var(--sat)) 0 calc(var(--nav-h) + var(--sab)); padding: 24px max(20px, calc((100% - 760px) / 2)); background: var(--bg); overflow-y: auto; z-index: 65; align-items: stretch; }
#favOverlay > .work-close, #catalogOverlay > .work-close { display: none; }
.page-heading, .dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-heading h1, .fav-title { font: 600 26px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; margin: 0; }
#favOverlay .fav-title, #catalogOverlay .fav-title, #paywallOverlay .fav-title { margin-bottom: 22px; }
#paywallOverlay .pw-sub { text-align: center; }
.fav-grid { width: 100%; max-width: none; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 14px; }
.fav-overlay { padding-bottom: calc(var(--nav-h) + var(--sab) + 20px); }
.fav-item img { border-radius: 8px; }
.fav-item.locked img { filter: none; }
.fav-item.locked::after { content: 'Полная колода'; top: auto; bottom: 10px; left: 10px; transform: none; background: #18191ce8; color: #fff; font: 11px/1.4 inherit; font-size: 11px; padding: 5px 8px; border-radius: 4px; }
.fav-remove { width: 40px; height: 40px; top: 6px; right: 6px; }
.fav-tag { max-width: calc(100% - 12px); font-size: 12px; }
.fav-diary { width:100%; min-height:32px; margin-top:5px; border:1px solid var(--border-soft); border-radius:7px; background:var(--surface); color:var(--paper); font-size:12px; cursor:pointer; }
.fav-diary:active { background:var(--accent-soft); }
.catalog-tools { display: flex; gap: 8px; margin: -4px 0 18px; flex-wrap: wrap; }
.catalog-tools #filterBtn, .catalog-tools #fitBtn { width: auto; min-height: 44px; border-radius: 8px; padding: 8px 14px; max-width: 100%; }
.catalog-tools #fitBtn.active { background: var(--surface); border: 1px solid var(--accent); color: var(--accent); }
#fitOverlay { z-index: 80; }
.fit-note { color: var(--muted); line-height: 1.5; margin: -8px 0 20px; }
.fit-form { display: grid; gap: 22px; }
.fit-group { border: 0; padding: 0; margin: 0; min-width: 0; }
.fit-group legend { color: var(--muted); font-size: 13px; margin-bottom: 9px; padding: 0; }
.fit-options { display: flex; flex-wrap: wrap; gap: 8px; }
.fit-option { min-height: 42px; padding: 8px 13px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--paper); cursor: pointer; }
.fit-option.chosen { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.fit-selection { color: var(--muted); font-size: 13px; margin: 0; }
.fit-empty { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 36px 12px; }
.lock-banner { max-width: none; border: 0; background: var(--accent-soft); border-radius: 8px; }
.lock-banner-cta { color: var(--paper); }
.sel-share-btn { position: sticky; bottom: 0; flex: 0 0 auto; border: 0; border-radius: 8px; min-height: 48px; background: var(--accent); color: #fff; width: 100%; max-width: none; margin-top: 20px; }
.storage-note { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0 0 20px; }
.icon-button { width: 44px; height: 44px; flex: 0 0 auto; display: inline-flex; justify-content: center; align-items: center; border: 0; border-radius: 8px; background: var(--surface); color: var(--paper); cursor: pointer; }
.icon-button svg { width: 20px; height: 20px; }
.icon-button.accent { background: var(--accent); color: white; }
.action-button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; border: 0; border-radius: 8px; padding: 13px 16px; min-height: 48px; background: var(--accent); color: white; cursor: pointer; width: 100%; font-size: 15px; font-weight: 600; }
.action-button svg { width: 18px; flex-shrink: 0; }
.action-button.secondary { background: var(--surface); color: var(--paper); }
.experience-dialog { background: var(--bg); color: var(--paper); border: 1px solid var(--border); border-radius: 8px; padding: 22px; width: min(540px, calc(100% - 24px)); max-height: calc(100dvh - 36px); overflow: auto; }
.experience-dialog::backdrop { background: #000a; }
.dialog-heading h2 { font-size: 22px; font-weight: 600; margin: 0; }
.experience-dialog label { display: flex; flex-direction: column; gap: 7px; font-size: 14px; margin-bottom: 15px; }
.experience-dialog input:not([type="file"]):not([type="checkbox"]), .experience-dialog textarea, .experience-dialog select { width: 100%; min-width: 0; background: var(--surface-soft); color: var(--paper); border: 1px solid var(--border); border-radius: 6px; min-height: 44px; padding: 10px; font-size: 16px; }
.experience-dialog textarea { resize: vertical; }
.diary-card-choice { display:flex; align-items:center; gap:10px; margin-top:8px; padding:8px; border:1px solid var(--border-soft); border-radius:8px; background:var(--surface); }
.diary-card-choice img { width:42px; height:68px; flex:0 0 auto; object-fit:cover; border-radius:5px; }
.diary-card-choice span { min-width:0; display:flex; flex-direction:column; gap:4px; }
.diary-card-choice b { font-size:13px; overflow-wrap:anywhere; }
.diary-card-choice small { color:var(--muted); line-height:1.3; max-height:34px; overflow:hidden; }
.experience-dialog #diaryDesignLabel { margin-top:2px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.photo-picker { position: relative; width: 100%; min-height: 140px; border: 1px dashed var(--border); border-radius: 8px; overflow: hidden; cursor: pointer; align-items: center; justify-content: center; }
.photo-picker input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.photo-picker img { width: 100%; max-height: 240px; object-fit: contain; }
.photo-picker span { display: flex; align-items: center; gap: 10px; padding: 18px; }
.experience-dialog .check-row { flex-direction: row; align-items: center; min-height: 44px; }
.check-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.form-error { color: #fb91a7; font-size: 14px; }
.diary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 16px; }
.diary-entry { min-width: 0; border-bottom: 1px solid var(--border-soft); padding-bottom: 16px; }
.diary-entry > img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.diary-entry h2 { font-size: 17px; margin: 10px 0 4px; overflow-wrap: anywhere; }
.diary-entry p { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; font-size: 14px; }
.diary-entry time { color: var(--muted); font-size: 12px; }
.entry-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 30px 12px; max-width: 380px; margin: auto; width: 100%; }
.empty-state img { width: 150px; height: 180px; object-fit: cover; border-radius: 8px; }
.empty-state h2 { font-size: 22px; font-weight: 500; margin: 22px 0; }
.empty-state p { color: var(--muted); }
.result-preview { width: 100%; max-height: 58dvh; object-fit: contain; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.dialog-actions .action-button { flex: 1; }
.poll-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 16px 0; }
.poll-choice { min-width: 0; position: relative; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: var(--surface); padding: 0; color: var(--paper); cursor: pointer; }
.poll-choice.selected { border-color: var(--accent); }
.poll-choice img { width: 100%; height: 190px; object-fit: contain; background: #202125; display: block; }
.poll-choice span { display: block; padding: 10px 8px; font-size: 13px; overflow-wrap: anywhere; }
.poll-choice input { position: absolute; right: 10px; top: 10px; width: 22px; height: 22px; accent-color: var(--accent); }
.poll-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 0; border-bottom: 1px solid var(--border-soft); }
.poll-row button { background: transparent; border: 0; color: var(--paper); text-align: left; min-height: 44px; cursor: pointer; }
.poll-row time { color: var(--muted); font-size: 12px; }
.poll-history { margin: 24px 0 8px; }
.poll-history h2 { font-size: 19px; }
.tryon-cover { width: 100%; max-height: 46dvh; object-fit: contain; border-radius: 8px; }
.settings-tools { display: flex; gap: 12px; padding: 10px 0; }
.settings-tools button { position: static !important; width: 48px; height: 48px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border-soft); }
.more-card #permBtn { width: 100%; text-align: left; background: var(--surface); color: var(--paper); font-size: 14px; }
.more-card { border-radius: 8px; }
.more-sheet { z-index: 85; }
.more-item { border: 0; border-radius: 6px; text-align: left; }
.more-title { font-size: 22px; }
.work-zoomhint { display: none; }
.toast { bottom: calc(var(--nav-h) + var(--sab) + 12px); }
body.has-master-bar { padding-top: 0; }
body.has-master-bar .brand-header { top: calc(var(--mb-h, 53px) + var(--sat)); }
body.has-master-bar .qr-btn, body.has-master-bar .more-btn { top: calc(var(--mb-h, 53px) + 14px + var(--sat)); }
body.has-master-bar .app { padding-top: calc(var(--header-h) + var(--mb-h, 53px) + var(--sat)); }
body.has-master-bar .experience-page, body.has-master-bar #favOverlay, body.has-master-bar #catalogOverlay { top: calc(var(--header-h) + var(--mb-h, 53px) + var(--sat)); }
@media (min-width: 720px) {
  .bottom-nav { padding-inline: max(16px, calc((100% - 620px) / 2)); }
  #catalogOverlay .fav-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .brand-header { padding-left: max(24px, calc((100% - 1020px) / 2)); }
  .diary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 560px) { .brand-mark { display: none; } }
@media (max-width: 560px) {
  /* Отдаём карте больше вертикального пространства на телефоне; номер карты
     и стрелки остаются доступными, но не забирают полноценные 44px. */
  .deck-meta { min-height: 32px; }
  .deck-meta .hist-btn { height: 32px; }
  .controls { gap: 4px; padding-top: 2px; padding-bottom: 6px; }
  .foot-row .btn { min-height: 40px; }
}
@media (max-width: 360px) { .form-row { grid-template-columns: 1fr; gap: 0; } .dialog-heading h2 { font-size: 20px; } }
@media (max-height: 740px) {
  :root { --header-h: 64px; --nav-h: 64px; }
  .deck-heading { padding-top: 10px; padding-bottom: 2px; }
  .deck-heading h1 { font-size: 19px; }
  .deck-meta { min-height: 32px; }
  .deck-meta .hist-btn { height: 32px; }
  .controls { padding-bottom: 6px; gap: 2px; }
  .qr-btn, .more-btn { top: calc(8px + var(--sat)); }
}
@media (max-height: 520px) and (orientation: landscape) {
  .app { overflow-y: auto; }
  .stage { flex: 0 0 300px; }
  .deck-heading, .controls { flex-shrink: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* Слои верхней части: плашка мастера всегда занимает своё место, затем идёт
   логотип, затем содержимое. Это не даёт «Ваша колода» и «В кабинет» попасть
   под заголовок или верхнюю панель на узком экране. */
.master-bar { top: var(--sat); left: var(--sal); right: var(--sar); z-index: 70; min-height: 48px; box-sizing: border-box; }
body.has-master-bar .brand-header { top: calc(var(--mb-h, 48px) + var(--sat)); }
body.has-master-bar .app { padding-top: calc(var(--header-h) + var(--mb-h, 48px) + var(--sat)); }
body.has-master-bar .experience-page,
body.has-master-bar #favOverlay,
body.has-master-bar #catalogOverlay { top: calc(var(--header-h) + var(--mb-h, 48px) + var(--sat)); }

/* На маленьких телефонах верхняя строка не конкурирует с кнопками. */
@media (max-width: 420px) {
  .brand-header { padding-inline: 14px; }
  .brand-logo { width: 42px; height: 44px; }
  .brand-mark { display: none; }
}

.brand-logo { max-height: calc(var(--header-h) - 4px); }
.qr-btn, .more-btn { top: calc(var(--sat) + (var(--header-h) - 44px) / 2); }
body.has-master-bar .qr-btn, body.has-master-bar .more-btn { top: calc(var(--sat) + var(--mb-h, 48px) + (var(--header-h) - 44px) / 2); }
.deck-heading { padding-top: 8px; padding-bottom: 4px; }

/* Название и вопрос занимают шапку, а действия не перекрывают оборот карты. */
.brand-header { gap:10px; padding-left:max(14px,var(--sal)); padding-right:108px; }
.brand-header .brand { flex:0 0 38px; }
.brand-logo { width:38px; height:44px; }
.brand-header .deck-heading { min-width:0; max-width:none; width:auto; padding:0; flex:1; }
.brand-header .eyebrow { font-size:10px; line-height:1.2; margin:0 0 3px; }
.brand-header h1 { font-size:clamp(14px,4vw,18px); line-height:1.15; margin:0; }
.stage { padding-inline:52px; }
.card-wrap { max-width:min(100%,360px); }
.card-wrap .like-btn, .card-wrap .share-btn { width:44px; height:44px; top:calc(50% - 22px); border:1px solid var(--border-soft); background:var(--surface); color:var(--paper); }
.card-wrap .share-btn { left:-50px; right:auto; }
.card-wrap .like-btn { right:-50px; left:auto; }
.card-wrap .like-btn.liked { color:var(--accent); }
.deck-meta { min-height:32px; }
.controls { gap:3px; padding-bottom:4px; }
.controls .btn { min-height:44px; padding:8px 10px; font-size:15px; }
.controls .foot-row { gap:6px; }
.controls .foot-row .btn { min-height:44px; padding:6px 4px; font-size:13px; }
.deck-switch { padding:2px; gap:2px; }
.deck-switch button { min-height:40px; padding:6px 12px; font-size:13px; }
#cardCaption { min-width:0; line-height:1.25; }
.card-back { padding:12px; gap:8px; }
.card-back .back-logo { height:36px; width:auto; max-width:80px; flex:0 0 auto; margin:0; }
.card-back .phrase { flex:0 0 auto; margin:0; line-height:1.25; overflow-wrap:normal; }
/* При перевороте сохраняем тот же габарит, что и у лицевой стороны.
   width:100% здесь растягивал оборот на всю сцену и визуально увеличивал карту. */
.card-wrap.reading { width:auto; aspect-ratio:70 / 120; max-width:min(86vw,360px); }
@media(max-height:680px) { .app.reading { overflow-y:auto; } .app.reading .stage { flex:1 0 240px; } }

/* Кнопка карты дня живёт рядом с QR и «Ещё»: в DOM она стоит до приложения,
   поэтому static-позиционирование прятало её в обычном потоке страницы. */
.day-btn, body.has-master-bar .day-btn {
  position: fixed !important;
  left: auto;
  right: calc(112px + var(--sar));
  top: calc(var(--sat) + (var(--header-h) - 44px) / 2);
  z-index: 62;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.has-master-bar .day-btn {
  top: calc(var(--sat) + var(--mb-h, 48px) + (var(--header-h) - 44px) / 2);
}

/* На обороте действия возвращаются по бокам: фраза и логотип должны оставаться
   полностью свободными. Безопасный отступ сцены оставляет кнопки в экране. */
.card-wrap.reading .share-btn { left: -50px; right: auto; top: calc(50% - 22px); }
.card-wrap.reading .like-btn { right: -50px; left: auto; top: calc(50% - 22px); }

/* Полноэкранные окна выше шапки мастера: иначе она перехватывает «Закрыть». */
#qrOverlay, #filterOverlay, #selOverlay, #paywallOverlay, .work-overlay, .pick-sheet { z-index:80; }
.experience-dialog { top:calc(var(--sat) + 12px); bottom:auto; margin:0 auto; max-height:calc(100dvh - var(--sat) - var(--sab) - 24px); }

/* У мастера нет отдельной красной плашки: вход в кабинет живёт в правом
   верхнем углу общей шапки. Оставляем место под кнопку и переносим QR/«Ещё»
   на нижнюю строку шапки, чтобы ни один элемент не перекрывал заголовок. */
body.is-own-master { --header-h: 88px; }
.cabinet-corner { position:absolute; top:6px; right:max(14px,var(--sar)); z-index:2;
  display:inline-flex; align-items:center; justify-content:center; min-height:34px;
  padding:6px 14px; border-radius:999px; background:var(--accent); color:#fff;
  font-size:14px; font-weight:600; text-decoration:none; white-space:nowrap; }
body.is-own-master .qr-btn, body.is-own-master .more-btn {
  top:calc(var(--sat) + 48px);
}
body.is-own-master .brand-header { padding-right:108px; }
