body {
  display: flex;
  flex-direction: column;
}

.defs {
  position: absolute;
  width: 0;
  height: 0;
}

/* ---------- backdrop: картина замка в ночи под копотью и виньеткой ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 75% 50% at 50% 36%, color-mix(in oklab, var(--c2) 26%, transparent), transparent 72%),
    linear-gradient(180deg, rgb(13 9 7 / 0.62) 0%, rgb(13 9 7 / 0.42) 28%, rgb(13 9 7 / 0.8) 66%, rgb(13 9 7 / 0.96) 100%),
    url('../assets/art/bg-main.jpg') center 30% / cover;
}

.backdrop::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--grain);
  opacity: 0.45;
  mix-blend-mode: overlay;
}

/* ---------- titlebar ---------- */

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 4px 0 14px;
  flex: none;
  -webkit-app-region: drag;
}

.titlebar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--gold);
  font: 16px/1 var(--font-display);
}

.titlebar__emblem {
  display: grid;
  color: var(--gold);
}

.titlebar__emblem-icon {
  width: 17px;
  height: 17px;
}

.titlebar__controls {
  display: flex;
  -webkit-app-region: no-drag;
}

.titlebar__button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 32px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--parchment-faint);
  transition: background 0.15s, color 0.15s;
}

.titlebar__button:hover {
  background: rgb(201 160 78 / 0.12);
  color: var(--parchment);
}

.titlebar__button--close:hover {
  background: var(--vermilion);
  color: #fff;
}

.titlebar__icon {
  width: 16px;
  height: 16px;
}

/* ---------- tabs ---------- */

.tabs {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 16px;
  padding: 2px 0 12px;
  flex: none;
}

.tabs__item {
  padding: 4px 6px;
  border: 0;
  background: none;
  color: var(--parchment-faint);
  font: 20px/1.2 var(--font-display);
  transition: color 0.25s;
}

.tabs__item:hover {
  color: var(--parchment-dim);
}

.tabs__item--active {
  color: var(--gold-light);
}

.tabs__sep {
  width: 5px;
  height: 5px;
  background: var(--gold-deep);
  transform: rotate(45deg);
}

.tabs__indicator {
  position: absolute;
  bottom: 4px;
  left: 0;
  height: 7px;
  width: 60px;
  background: linear-gradient(90deg, transparent, var(--gold) 22%, var(--gold) 78%, transparent) center / 100% 1px no-repeat;
  transition: transform 0.45s var(--ease), width 0.45s var(--ease);
}

.tabs__indicator::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 6px;
  background: var(--gold-light);
  transform: translate(-50%, -50%) rotate(45deg);
}

/* ---------- views ---------- */

.views {
  position: relative;
  flex: 1;
  min-height: 0;
}

.view {
  position: absolute;
  inset: 0;
  padding: 10px 18px 16px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.view--active {
  opacity: 1;
  visibility: visible;
}

/* ---------- timer ---------- */

.timer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
}

.timer__dial {
  --dial-size: min(292px, 41vh);
}

.timer__candles {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  height: 46px;
}

.timer__next {
  min-height: 22px;
  margin: 0;
  color: var(--parchment-faint);
  font-style: italic;
}

.timer__controls {
  display: flex;
  align-items: center;
  gap: 30px;
}

.timer__tally {
  width: 100%;
}

/* ---------- candle (свечи до пира) ---------- */

.candle {
  width: 22px;
  height: 46px;
}

.candle__svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.candle__wax {
  fill: url(#candle-wax);
}

.candle__wick {
  stroke: #2b1d12;
  stroke-width: 1.2;
  stroke-linecap: round;
}

.candle__halo,
.candle__flame,
.candle__ember {
  opacity: 0;
  transition: opacity 0.8s;
}

.candle__flame {
  transform-box: view-box;
  transform-origin: 12px 17px;
}

.candle__ember {
  fill: #ff8a3a;
}

.candle--lit .candle__flame {
  opacity: 1;
  animation: flicker 2.4s ease-in-out infinite alternate;
  animation-delay: var(--delay, 0s);
}

.candle--lit .candle__halo {
  opacity: 0.6;
}

.candle--smoulder .candle__ember {
  opacity: 1;
  animation: smoulder 1.8s ease-in-out infinite alternate;
}

@keyframes flicker {
  0% {
    transform: scale(1, 1) skewX(0);
  }
  30% {
    transform: scale(0.93, 1.07) skewX(-3deg);
  }
  65% {
    transform: scale(1.05, 0.95) skewX(2deg);
  }
  100% {
    transform: scale(0.97, 1.04) skewX(-1deg);
  }
}

@keyframes smoulder {
  from {
    opacity: 0.35;
  }
}

/* ---------- tally (сегодняшний итог, разлинованный как строка рукописи) ---------- */

.tally {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 10px 0;
  border-top: 1px solid var(--gold-hair);
  border-bottom: 1px solid var(--gold-hair);
}

.tally__cell {
  text-align: center;
}

.tally__cell + .tally__cell {
  border-left: 1px solid var(--gold-hair);
}

.tally__value {
  color: var(--gold-light);
  font: 22px/1.2 var(--font-display);
  white-space: nowrap;
}

.tally__label {
  color: var(--parchment-faint);
  font-size: 13px;
  font-style: italic;
}

/* ---------- chronicle (Летопись на пергаменте) ---------- */

.stats {
  overflow-y: auto;
}

.chronicle {
  position: relative;
  padding: 18px 20px 14px;
}

.chronicle__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.chronicle__title {
  margin: 0;
  font: 34px/1 var(--font-display);
  color: var(--ink);
}

.chronicle__title .rubric {
  color: var(--vermilion);
}

.chronicle__date {
  margin: 0;
  color: var(--ink-faint);
  font-style: italic;
}

.chronicle__hero {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin: 12px 0 4px;
}

.chronicle__hero-value {
  font: 34px/1.1 var(--font-display);
  color: var(--vermilion);
}

.chronicle__hero-label {
  color: var(--ink-soft);
  font-style: italic;
  font-size: 16px;
}

.chronicle__entries {
  margin: 8px 0 14px;
}

.chronicle__entry {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
}

.chronicle__entry dt {
  color: var(--ink-soft);
}

/* Точечная направляющая между названием и числом, как в оглавлении старой книги */
.chronicle__entry::after {
  content: '';
  order: 1;
  flex: 1;
  border-bottom: 1.5px dotted rgb(92 70 49 / 0.45);
  transform: translateY(-4px);
}

.chronicle__entry dd {
  order: 2;
  margin: 0;
  font: 19px/1 var(--font-display);
  color: var(--ink);
}

/* ---------- chart (дозор за неделю, тушью) ---------- */

.chart {
  position: relative;
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid rgb(92 70 49 / 0.3);
}

.chart__title {
  margin-bottom: 10px;
  font: 19px/1.2 var(--font-display);
  color: var(--ink);
}

/* Справа оставлен жёлоб под подписи шкалы, чтобы они не наезжали на столбики */
.chart__plot {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  height: 132px;
  padding-right: 30px;
  border-bottom: 1.5px solid var(--ink-soft);
}

.chart__gridline {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed rgb(92 70 49 / 0.28);
  pointer-events: none;
}

.chart__gridline-label {
  position: absolute;
  right: 0;
  bottom: 1px;
  color: var(--ink-faint);
  font-size: 11px;
  font-style: italic;
}

.chart__col {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 0 1px;
  border: 0;
  background: transparent;
}

.chart__bar {
  width: min(22px, 68%);
  min-height: 2px;
  border: 1.2px solid var(--ink-soft);
  border-bottom: 0;
  border-radius: 3px 3px 0 0;
  background: repeating-linear-gradient(-45deg, rgb(92 70 49 / 0.75) 0 1.2px, transparent 1.2px 4px);
  transition: height 0.5s var(--ease), filter 0.15s;
}

.chart__col:hover .chart__bar,
.chart__col:focus-visible .chart__bar {
  filter: brightness(0.75);
}

.chart__col--today .chart__bar {
  border-color: var(--vermilion);
  background: linear-gradient(180deg, var(--vermilion-light), var(--vermilion));
}

.chart__value {
  margin-bottom: 3px;
  color: var(--ink);
  font: 14px/1 var(--font-display);
  white-space: nowrap;
}

.chart__axis {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-top: 5px;
  padding-right: 30px;
  color: var(--ink-faint);
  font-size: 12.5px;
  font-style: italic;
  text-align: center;
}

.chart__axis-label--today {
  color: var(--vermilion);
  font-style: normal;
  font-weight: 700;
}

.chart__note {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-style: italic;
  font-size: 14px;
}

/* Дракон на полях, как маргиналии писцов */
.chart__dragon {
  position: absolute;
  right: -6px;
  bottom: -12px;
  width: 64px;
  height: 42px;
  background: var(--ink-soft);
  opacity: 0.5;
  mask: url('../assets/art/dragon-1.svg') center / contain no-repeat;
}

.chart__tooltip {
  position: absolute;
  z-index: 2;
  padding: 7px 10px;
  border: 1px solid var(--gold-line);
  border-radius: 3px;
  background: var(--soot);
  color: var(--parchment);
  box-shadow: 0 10px 24px rgb(40 20 5 / 0.45);
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -100%);
}

.chart__tooltip-title {
  color: var(--gold);
  font-style: italic;
}

/* ---------- settings (Устав) ---------- */

.settings {
  overflow-y: auto;
  padding-bottom: 28px;
}

.settings__section + .settings__section {
  margin-top: 22px;
}

.settings__title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 2px 8px;
  color: var(--gold-light);
  font: 400 22px/1.2 var(--font-display);
}

/* Плющевой лист киноварью: так писцы отмечали начало раздела */
.settings__title::before {
  content: '❧';
  color: var(--vermilion-light);
  font: 20px/1 'Segoe UI Symbol', serif;
}

.settings__panel {
  padding: 2px 14px;
}

.settings__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 0;
}

.settings__note {
  margin: 10px 2px 0;
  color: var(--parchment-faint);
  font-size: 13px;
  font-style: italic;
}

/* ---------- credits (авторы картин, музыки и звуков) ---------- */

.credits {
  margin: 14px 2px 0;
  color: var(--parchment-faint);
  font-size: 13px;
}

.credits__summary {
  color: var(--parchment-dim);
  font-style: italic;
  cursor: pointer;
}

.credits__summary:hover {
  color: var(--gold-light);
}

.credits__group {
  margin: 10px 0 4px;
  color: var(--gold);
  font: 16px/1.2 var(--font-display);
}

.credits__list {
  margin: 0;
  padding-left: 16px;
}

.credits__item {
  margin: 3px 0;
  user-select: text;
}

/* ---------- field ---------- */

.field {
  display: block;
  padding: 12px 0;
}

.field + .field {
  border-top: 1px solid var(--gold-hair);
}

.field--inline {
  cursor: pointer;
}

.field__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field__label {
  font-weight: 600;
}

.field__sub {
  color: var(--parchment-faint);
  font-style: italic;
  font-weight: 400;
}

.field__value {
  color: var(--gold-light);
  font: 17px/1 var(--font-display);
  white-space: nowrap;
}

.field__hint {
  margin-top: 3px;
  color: var(--parchment-faint);
  font-size: 13px;
  font-style: italic;
}

.field__body {
  margin-top: 10px;
}

.field--inline .field__body {
  margin-top: 0;
}

/* ---------- slider ---------- */

.slider {
  --fill: 50%;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  appearance: none;
  cursor: pointer;
}

.slider:disabled {
  opacity: 0.35;
  cursor: default;
}

.slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold-light)) 0 / var(--fill) 100% no-repeat, rgb(0 0 0 / 0.55);
  box-shadow: inset 0 1px 1px rgb(0 0 0 / 0.6), 0 1px 0 rgb(201 160 78 / 0.12);
}

/* Ползунок в виде ромба из сусального золота */
.slider::-webkit-slider-thumb {
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: 1px solid #f6e2a0;
  background: var(--gold-leaf);
  box-shadow: 0 0 0 3px rgb(17 12 10 / 0.9), 0 0 12px rgb(201 160 78 / 0.55);
  transform: rotate(45deg);
  appearance: none;
  transition: transform 0.15s var(--ease);
}

.slider:active::-webkit-slider-thumb {
  transform: rotate(45deg) scale(1.2);
}

/* ---------- switch ---------- */

.switch {
  position: relative;
  display: inline-block;
  flex: none;
}

.switch__input {
  position: absolute;
  opacity: 0;
}

.switch__track {
  display: block;
  width: 42px;
  height: 22px;
  border: 1px solid var(--gold-line);
  border-radius: 11px;
  background: rgb(0 0 0 / 0.5);
  transition: background 0.25s, border-color 0.25s;
}

.switch__thumb {
  display: block;
  width: 14px;
  height: 14px;
  margin: 3px;
  border-radius: 50%;
  background: var(--parchment-faint);
  transition: transform 0.25s var(--ease), background 0.25s;
}

.switch__input:checked + .switch__track {
  border-color: var(--gold);
  background: linear-gradient(160deg, var(--c1), var(--c2));
}

.switch__input:checked + .switch__track .switch__thumb {
  background: var(--gold-leaf);
  transform: translateX(20px);
}

.switch__input:focus-visible + .switch__track {
  outline: 2px solid var(--gold-light);
  outline-offset: 2px;
}

/* ---------- shields (строгость) ---------- */

.shields {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 14px 0 4px;
}

.shield {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--parchment-faint);
  font: 16px/1.1 var(--font-display);
  transition: color 0.25s;
}

.shield:hover {
  color: var(--parchment);
}

.shield__svg {
  width: 52px;
  height: 61px;
  overflow: visible;
  transition: transform 0.3s var(--ease), filter 0.3s;
}

.shield:hover .shield__svg {
  transform: translateY(-2px);
}

.shield__body {
  fill: rgb(0 0 0 / 0.38);
  stroke: var(--gold-line);
  stroke-width: 1.5;
  transition: fill 0.3s, stroke 0.3s;
}

.shield__charge {
  fill: var(--gold-deep);
  opacity: 0.55;
  transition: fill 0.3s, opacity 0.3s;
}

.shield--active {
  color: var(--gold-light);
}

.shield--active .shield__svg {
  filter: drop-shadow(0 4px 10px rgb(0 0 0 / 0.6));
}

.shield--active .shield__body {
  fill: var(--c2);
  stroke: var(--gold);
  stroke-width: 2.6;
}

.shield--active .shield__charge {
  fill: var(--gold-light);
  opacity: 1;
}

.shields__desc {
  min-height: 3em;
  margin: 0 0 12px;
  color: var(--parchment-dim);
  font-style: italic;
  text-align: center;
}

/* ---------- swatch (финифть дозора) ---------- */

.swatches {
  display: flex;
  gap: 10px;
}

.swatch {
  display: grid;
  padding: 0;
  border: 0;
  background: none;
  transition: transform 0.2s var(--ease);
}

.swatch:hover {
  transform: translateY(-2px);
}

.swatch__svg {
  width: 26px;
  height: 30px;
  overflow: visible;
}

.swatch__body {
  fill: var(--focus-2);
  stroke: var(--gold-line);
  stroke-width: 3;
}

.swatch--active .swatch__body {
  fill: var(--focus-1);
  stroke: var(--gold-light);
  stroke-width: 5;
}
