:root {
  --bg: #0a0605;
  --bg-deep: #120a07;
  --wood: #1a0f0a;
  --gold: #d4a34a;
  --gold-soft: #a97c3e;
  --cream: #f5e8d0;
  --cream-dim: #c9b48e;
  --flame: #ffb34d;
  --flame-hot: #fff2d9;
}

* { box-sizing: border-box; }

/* атрибут hidden должен работать (не перебивается display: flex у .stage) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: #0a0605;
  color: var(--cream);
  font-family: "Georgia", "Times New Roman", serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse at 50% 30%, #2a170f 0%, #120906 55%, #080503 100%);
  background-attachment: fixed;
}

/* ===== фон ===== */
.scene {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 56px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  overflow: hidden;
}

.bg-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse at 50% 0%, transparent 0%, transparent 55%, rgba(0,0,0,0.85) 100%);
}

.bg-light {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse at 50% 72%, rgba(212,163,74,0.13), transparent 62%);
}

.smoke-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

/* ===== шапка ===== */
.masthead {
  text-align: center;
  z-index: 1;
  margin-top: 12px;
  animation: fadeDown 1.4s ease both;
}
.cross-deco {
  font-size: 30px;
  color: var(--gold);
  opacity: 0.5;
  line-height: 1;
  margin-bottom: 8px;
  text-shadow: 0 0 16px rgba(212,163,74,0.4);
}
.title {
  font-size: clamp(40px, 10vw, 74px);
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 6px 0 14px;
  color: var(--cream);
  text-shadow:
    0 0 40px rgba(212,163,74,0.6),
    0 0 12px rgba(212,163,74,0.8),
    0 2px 4px rgba(0,0,0,0.9);
}
/* заголовок экрана выбора — короче, не вылезает за сцену */
#typeSelect .title {
  font-size: clamp(34px, 8vw, 58px);
  letter-spacing: 0.06em;
  line-height: 1.15;
  margin: 6px 0 12px;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.subtitle {
  font-size: clamp(16px, 3vw, 20px);
  color: var(--gold);
  letter-spacing: 0.04em;
  opacity: 0.95;
  font-style: italic;
  line-height: 1.55;
  max-width: 520px;
  margin: 0 auto;
}

/* ===== экран выбора ===== */
.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  width: 100%;
  max-width: 560px;
  margin: 34px auto 0;
}
.choice-card {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255,190,90,0.08), transparent 65%),
    linear-gradient(180deg, rgba(30,16,9,0.9), rgba(14,8,5,0.95));
  border: 1px solid rgba(212,163,74,0.3);
  border-radius: 24px;
  padding: 26px 22px;
  color: var(--cream);
  cursor: pointer;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.6), 0 8px 22px rgba(0,0,0,0.55);
  border: 1px solid transparent;
}
.choice-card:hover {
  transform: translateY(-6px);
  border-color: rgba(212,163,74,0.9);
  box-shadow: inset 0 0 46px rgba(0,0,0,0.6), 0 14px 30px rgba(0,0,0,0.6), 0 0 34px rgba(212,163,74,0.25);
}
.choice-icon { font-size: 46px; line-height: 1; filter: drop-shadow(0 6px 12px rgba(0,0,0,0.7)); }
.choice-name {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(212,163,74,0.4);
}
.choice-desc {
  font-size: 14px;
  line-height: 1.55;
  color: var(--cream-dim);
  opacity: 0.95;
}
.choice-count {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 16px;
  border-radius: 30px;
  border: 1px solid rgba(212,163,74,0.4);
  background: rgba(0,0,0,0.4);
  color: var(--gold);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 520px) {
  .choice-grid { grid-template-columns: 1fr; gap: 14px; margin-top: 24px; }
  .choice-card { padding: 20px 18px; }
}

/* ===== сцена ===== */
.stage {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 6px;
}
.ritual-head {
  margin-top: 4px;
}
.ritual-head .title { font-size: clamp(32px, 8vw, 58px); letter-spacing: 0.12em; }
.ritual-head .subtitle { font-size: clamp(14px, 2.6vw, 17px); opacity: 0.9; }

.candle-stage {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* полка */
.shelf {
  position: relative;
  width: 100%;
  height: 36px;
  margin-top: -14px;
}
.shelf-table {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 320px;
  height: 10px;
  background: linear-gradient(180deg, #1b110b, #3a2a1d 60%, #19100b);
  border-radius: 4px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.7);
}
.shelf-table::before,
.shelf-table::after {
  content: "";
  position: absolute;
  top: 5px;
  bottom: -4px;
  width: 3px;
  background: linear-gradient(180deg, #241a12, #0d0906);
}
.shelf-table::before { left: 6px; }
.shelf-table::after { right: 6px; }

.candle-scene {
  position: relative;
  width: 360px;
  height: 520px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

#candleSvg {
  position: relative;
  z-index: 2;
  height: 100%;
  width: auto;
  filter: drop-shadow(0 22px 30px rgba(0,0,0,0.85));
}

/* ореол */
.halo {
  position: absolute;
  left: 50%;
  bottom: 40px;
  width: 440px;
  height: 440px;
  transform: translateX(-50%);
  background: radial-gradient(circle,
    rgba(255,180,80,0.50) 0%,
    rgba(255,150,60,0.28) 30%,
    transparent 70%);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 2.4s ease;
  pointer-events: none;
}
.halo.lit { animation: haloPulse 4.5s ease-in-out infinite; }
/* сценарий «за здравие»: светлее ореол */
.candle-scene[data-type="health"] .halo {
  background: radial-gradient(circle,
    rgba(255,210,120,0.72) 0%,
    rgba(255,190,90,0.4) 35%,
    transparent 72%);
}

/* локальное свечение пламени */
.flame-glow {
  position: absolute;
  left: 50%;
  bottom: 96px;
  width: 210px;
  height: 210px;
  transform: translateX(-50%);
  background: radial-gradient(circle,
    rgba(255,205,110,0.95) 0%,
    rgba(255,160,70,0.4) 40%,
    transparent 72%);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 1.4s ease;
  filter: blur(12px);
  pointer-events: none;
  z-index: 1;
}

/* ===== пламя: многослойное, плавное ===== */
#flameGroup {
  transition: opacity 1.4s ease;
}
.flame-outer {
  fill: url(#flameGradOuter);
  transform-origin: 50% 100%;
  animation: flickerOuter 2.2s ease-in-out infinite alternate;
}
.flame-inner {
  fill: url(#flameGradInner);
  transform-origin: 50% 100%;
  animation: flickerInner 1.7s ease-in-out infinite alternate;
}
.flame-core {
  fill: var(--flame-hot);
  transform-origin: 50% 100%;
  animation: flickerCore 0.9s ease-in-out infinite alternate;
}
.flame-tip {
  fill: #ffe9b0;
  opacity: 0.45;
}
.flame-tip:first-of-type {
  transform-origin: 100% 100%;
  animation: flickerTip 1.6s ease-in-out infinite alternate;
}
.flame-tip:last-of-type {
  transform-origin: 0% 100%;
  animation: flickerTip 2.0s ease-in-out 0.5s infinite alternate;
}
.wax-glow {
  opacity: 0;
  animation: waxGlow 3.4s ease-in-out infinite;
}
#flameGroup.ignite .wax-glow {
  animation: waxGlow 3.4s ease-in-out infinite;
}

/* свечи в разных сценариях */
.candle-scene[data-type="repose"] .flame-outer {
  fill: url(#flameGradOuter);
  filter: saturate(0.9) brightness(0.96);
}
.candle-scene[data-type="health"] .flame-outer {
  fill: url(#flameGradOuter);
  filter: saturate(1.25) brightness(1.12);
}
.candle-scene[data-type="health"] .flame-inner {
  filter: saturate(1.2) brightness(1.15);
}
.candle-scene[data-type="health"] .wax-glow {
  opacity: 0.9;
}

/* анимации пламени — фазовый сдвиг, плавные кривые (без скачков) */
@keyframes flickerOuter {
  0%   { transform: scale(1) rotate(-1deg) translateY(0); }
  30%  { transform: scale(1.06, 0.97) rotate(1.2deg) translateY(-2px); }
  60%  { transform: scale(0.96, 1.04) rotate(-0.8deg) translateY(0); }
  100% { transform: scale(1.03, 0.99) rotate(1deg) translateY(-1px); }
}
@keyframes flickerInner {
  0%   { transform: scale(1.05, 0.97); }
  40%  { transform: scale(0.95, 1.06); }
  100% { transform: scale(1.02, 0.98); }
}
@keyframes flickerCore {
  0%   { transform: scale(0.96); opacity: 0.88; }
  50%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 0.94; }
}
@keyframes flickerTip {
  0%   { transform: scale(0.9, 0.85); opacity: 0.35; }
  45%  { transform: scale(1.1, 1.12); opacity: 0.7; }
  100% { transform: scale(0.95, 1); opacity: 0.5; }
}
@keyframes waxGlow {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.85; }
}

@keyframes haloPulse {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

@keyframes drip {
  0%, 55% { transform: scaleY(1); opacity: 0.85; }
  65%, 100% { transform: scaleY(1.35); opacity: 0.5; }
}
.wax-drip.d1 { transform-origin: top; animation: drip 8s ease-in-out infinite; }
.wax-drip.d2 { transform-origin: top; animation: drip 11s 2.5s ease-in-out infinite; }
.wax-drip.d3 { transform-origin: top; animation: drip 7s 5s ease-in-out infinite; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== счётчик ===== */
.counter {
  text-align: center;
  margin: 8px 0 0;
  padding: 12px 30px 14px;
  border: 1px solid rgba(212,163,74,0.4);
  border-radius: 44px;
  background: linear-gradient(180deg, rgba(26,14,9,0.75), rgba(12,7,5,0.85));
  backdrop-filter: blur(3px);
  box-shadow:
    inset 0 0 30px rgba(212,163,74,0.1),
    0 12px 28px rgba(0,0,0,0.6);
  animation: fadeUp 1.6s 0.2s ease both;
}
.counter-label {
  display: block;
  font-size: 12.5px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--cream-dim);
  margin-bottom: 5px;
}
.counter-value {
  display: block;
  font-size: 44px;
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 0 22px rgba(212,163,74,0.6), 0 1px 2px rgba(0,0,0,0.8);
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}
.counter.bump .counter-value { animation: bump 0.45s ease; }
@keyframes bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

/* кнопка зажигания */
.light-btn {
  margin-top: 26px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 17px 36px;
  font-size: 18px;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #191006;
  background: linear-gradient(180deg, #f5d68e 0%, #dcab54 55%, #c08a35 100%);
  border: 1px solid rgba(255,224,150,0.55);
  border-radius: 50px;
  cursor: pointer;
  box-shadow:
    0 8px 24px rgba(0,0,0,0.65),
    0 0 36px rgba(216,168,78,0.5),
    inset 0 1px 0 rgba(255,255,255,0.6);
  transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.2s, filter 0.2s;
}
.light-btn:hover:not(:disabled) {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 12px 30px rgba(0,0,0,0.7), 0 0 54px rgba(216,168,78,0.85), inset 0 1px 0 rgba(255,255,255,0.65);
}
.light-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.99);
  transition-duration: 0.05s;
}
.light-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: saturate(0.7);
}
.switch-btn {
  margin-top: 14px;
  padding: 10px 26px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--gold);
  background: transparent;
  border: 1px solid rgba(212,163,74,0.45);
  border-radius: 40px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.03em;
}
.switch-btn:hover {
  border-color: rgba(212,163,74,0.9);
  background: rgba(212,163,74,0.1);
  transform: translateY(-1px);
}
.light-btn .btn-icon { font-size: 22px; }

.status {
  min-height: 24px;
  margin-top: 14px;
  font-size: 15px;
  text-align: center;
  line-height: 1.5;
  padding: 0 12px;
  transition: opacity 0.2s;
}
.status.ok { color: #d8ca9a; text-shadow: 0 0 14px rgba(212,163,74,0.35); }
.status.err { color: #db9d8a; }

/* эпитафия */
.epitaph {
  margin-top: 30px;
  max-width: 600px;
  text-align: center;
  padding: 24px 28px;
  border: 1px solid rgba(212,163,74,0.3);
  border-radius: 18px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255,190,100,0.09), transparent 60%),
    linear-gradient(180deg, rgba(26,14,9,0.78), rgba(12,7,5,0.92));
  box-shadow: inset 0 0 60px rgba(0,0,0,0.7), 0 0 26px rgba(212,163,74,0.1);
  opacity: 0;
  transform: translateY(10px) scale(0.97);
  transition: opacity 0.9s ease, transform 0.9s ease;
}
.epitaph.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.epitaph p {
  margin: 12px 0;
  font-size: clamp(17px, 3.8vw, 22px);
  font-style: italic;
  color: var(--cream);
  line-height: 1.65;
}
.ornament {
  color: var(--gold);
  opacity: 0.6;
  font-size: 16px;
  letter-spacing: 0.4em;
  display: block;
  text-align: center;
}

/* ===== записки ===== */
.notes-section {
  z-index: 1;
  width: 100%;
  margin-top: 56px;
  padding: 30px 26px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(26,13,8,0.88), rgba(14,8,5,0.93));
  border: 1px solid rgba(212,163,74,0.2);
  box-shadow: inset 0 0 60px rgba(0,0,0,0.6), 0 0 30px rgba(212,163,74,0.05);
  animation: fadeUp 1.8s 0.4s ease both;
}
.notes-title {
  text-align: center;
  color: var(--gold);
  font-size: clamp(22px, 4.5vw, 30px);
  letter-spacing: 0.05em;
  margin: 0 0 22px;
  font-weight: 700;
  text-shadow: 0 0 18px rgba(212,163,74,0.3);
}
.note-form textarea {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  padding: 13px 15px;
  font-family: inherit;
  font-size: 15px;
  color: var(--cream);
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(212,163,74,0.32);
  border-radius: 13px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.note-form textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212,163,74,0.12);
}
.note-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 11px;
}
.note-count { font-size: 12px; color: var(--cream-dim); }
.note-submit {
  padding: 10px 24px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #1a0f06;
  background: linear-gradient(180deg, #e9ca8a, #c99c4a);
  border: 1px solid rgba(255,224,150,0.5);
  border-radius: 32px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5), 0 0 20px rgba(212,163,74,0.25);
  transition: transform 0.15s;
}
.note-submit:hover:not(:disabled) { transform: translateY(-1px); }
.note-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.note-status {
  min-height: 17px;
  font-size: 13.5px;
  color: var(--gold-soft);
  margin-top: 9px;
  line-height: 1.45;
}
.note-status.err { color: #db9d8a; }
.note-status.ok { color: #d8ca9a; }

.notes-list {
  list-style: none;
  padding: 0;
  margin: 22px 0 0;
  display: grid;
  gap: 10px;
}
.notes-list.empty::before {
  content: "Пока никто не написал. Будьте первым, кто потерял надежду на оператора (или нашёл здравие смены).";
  display: block;
  text-align: center;
  color: var(--cream-dim);
  font-size: 14px;
  padding: 18px 0;
}
.note-item {
  padding: 13px 15px;
  border-radius: 13px;
  background: rgba(0,0,0,0.38);
  border-left: 2px solid var(--gold);
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.4);
  animation: fadeUp 0.5s ease both;
  position: relative;
}
.note-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 6px;
  text-transform: uppercase;
}
.badge-repose {
  color: #c9a874;
  background: rgba(150,90,40,0.18);
  border: 1px solid rgba(201,168,116,0.4);
}
.badge-health {
  color: #ffe2a8;
  background: rgba(255,190,90,0.12);
  border: 1px solid rgba(255,210,140,0.5);
}
.note-text { margin: 4px 0 6px; }
.note-time {
  display: block;
  font-size: 11px;
  color: var(--gold-soft);
  opacity: 0.7;
}

/* звук */
.sound-toggle {
  position: fixed;
  bottom: 18px;
  right: 18px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid rgba(212,163,74,0.55);
  background: rgba(20,10,6,0.9);
  color: var(--gold);
  font-size: 23px;
  cursor: pointer;
  z-index: 20;
  box-shadow: 0 6px 18px rgba(0,0,0,0.75);
  transition: transform 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sound-toggle:hover { transform: scale(1.07); }
.sound-toggle[aria-pressed="true"] {
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(212,163,74,0.55);
}
.sound-init-hint {
  position: fixed;
  bottom: 26px;
  right: 88px;
  z-index: 19;
  padding: 11px 18px;
  border-radius: 32px;
  border: 1px solid rgba(212,163,74,0.55);
  background: rgba(20,10,6,0.94);
  color: var(--gold);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,0.75);
  animation: fadeUp 1.2s ease both;
}

/* футер */
.footer {
  z-index: 1;
  width: 100%;
  text-align: center;
  margin-top: 44px;
  color: var(--cream-dim);
  font-size: 12px;
  line-height: 1.55;
}
.notice {
  max-width: 540px;
  margin: 0 auto 10px;
  padding: 9px 15px;
  border: 1px dashed rgba(212,163,74,0.32);
  border-radius: 11px;
  background: rgba(0,0,0,0.45);
  color: #a89376;
}
.footer-meta { opacity: 0.72; font-size: 11px; }
.star {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* дым */
.smoke-layer::before,
.smoke-layer::after {
  content: "";
  position: absolute;
  bottom: 40px;
  left: 50%;
  width: 150px;
  height: 220px;
  background:
    radial-gradient(closest-side, rgba(210,196,180,0.12), transparent);
  filter: blur(18px);
  opacity: 0;
  z-index: 0;
}
.smoke-layer.lit::before,
.smoke-layer.lit::after {
  animation: smoke 13s ease-in-out infinite;
}
.smoke-layer.lit::after {
  animation-delay: 6.5s;
}
@keyframes smoke {
  0% { transform: translateX(-50%) translateY(30px) scale(0.6); opacity: 0; }
  18% { opacity: 0.42; }
  100% { transform: translateX(-40%) translateY(-340px) scale(2.4); opacity: 0; }
}

/* ===== адаптив: смартфоны ===== */
@media (max-width: 480px) {
  .scene { padding: 14px 12px 48px; }
  .title { letter-spacing: 0.1em; line-height: 1.12; }
  .subtitle br { display: none; }
  .candle-scene { width: 300px; height: 460px; }
  .shelf-table { width: 250px; }
  .halo { width: 360px; height: 360px; }
  .counter-value { font-size: 38px; }
  .light-btn { padding: 15px 28px; font-size: 17px; }
  .sound-toggle { right: 12px; bottom: 12px; }
  .sound-init-hint { right: 76px; bottom: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
}
