/* ============================================================
   Сцэнічны таймер — стыль «вышыванка»
   Колеры тэм — у зменных :root ніжэй. Акцэнтны колер можна
   змяніць у наладах: тады --accent задаецца inline на <html>.
   ============================================================ */

@font-face { font-family: "Playfair Display"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/playfair-normal-400-latin.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Playfair Display"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/playfair-normal-400-cyrillic.woff2") format("woff2"); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Playfair Display"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/playfair-normal-700-latin.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Playfair Display"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/playfair-normal-700-cyrillic.woff2") format("woff2"); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Playfair Display"; font-style: italic; font-weight: 400; font-display: swap; src: url("fonts/playfair-italic-400-latin.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Playfair Display"; font-style: italic; font-weight: 400; font-display: swap; src: url("fonts/playfair-italic-400-cyrillic.woff2") format("woff2"); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }

:root {
  --band: clamp(44px, 8.5vh, 120px);   /* вышыня арнаментнай палосы */

  --accent: #c4262e;
  --bg: #15100e;
  --bg-2: #261b18;
  --panel: #2a1e1a;
  --fg: #f2e6c9;
  --muted: rgba(242, 230, 201, 0.55);
  --line: rgba(242, 230, 201, 0.22);
  --gold: #d9a441;
  --red: var(--accent);
  --red-soft: color-mix(in srgb, var(--accent) 35%, transparent);
  --orn-a: var(--accent);                /* асноўны колер арнаменту */
  --orn-b: #f2e6c9;                      /* дадатковы колер арнаменту */
  --weave: rgba(255, 255, 255, 0.035);   /* фактура палатна */
  --shadow: rgba(0, 0, 0, 0.45);
  --btn-bg: rgba(0, 0, 0, 0.35);
  --input-bg: rgba(0, 0, 0, 0.28);
  --sel: rgba(255, 255, 255, 0.1);

  --font: "Playfair Display", "Times New Roman", Times, serif;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --accent: #b1222b;
  --bg: #f1e7d3;
  --bg-2: #f8f0e0;
  --panel: #faf3e4;
  --fg: #17110f;
  --muted: rgba(23, 17, 15, 0.6);
  --line: rgba(23, 17, 15, 0.25);
  --gold: #9a6a10;
  --orn-b: #17110f;
  --weave: rgba(0, 0, 0, 0.05);
  --shadow: rgba(0, 0, 0, 0.12);
  --btn-bg: rgba(255, 255, 255, 0.5);
  --input-bg: rgba(255, 255, 255, 0.6);
  --sel: #ffffff;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font);
  color: var(--fg);
  background-color: var(--bg);
  background-image: radial-gradient(ellipse at center, var(--bg-2) 0%, var(--bg) 72%);
  display: grid;
  grid-template-rows: var(--band) 1fr var(--band);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* фактура палатна */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, var(--weave) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, var(--weave) 0 1px, transparent 1px 3px);
}

body:not(.ui) { cursor: none; }

/* ---------- арнамент ---------- */
.orn {
  position: relative;
  z-index: 1;
  height: var(--band);
  background-repeat: repeat-x;
  background-size: auto 100%;
  background-position: center top;
}
body.no-orn { --band: 2px; }
body.no-orn .orn { background-image: none !important; background-color: var(--red); }
body.no-orn .controls { bottom: 3.5vh; }

/* ---------- сцэна ---------- */
.stage {
  position: relative;
  z-index: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2vh;
  padding: 0 3vw 3vh;
}

.title {
  display: flex;
  align-items: center;
  gap: 1.1em;
  margin: 0;
  font-size: clamp(14px, 2.4vh, 32px);
  letter-spacing: .38em;
  text-transform: uppercase;
  color: var(--fg);
}
.title h1 {
  font: inherit;
  font-weight: 400;
  margin: 0;
  padding-left: .38em; /* кампенсацыя letter-spacing */
  text-align: center;
}
.gem {
  flex: none;
  width: .55em;
  height: .55em;
  background: var(--red);
  transform: rotate(45deg);
}

.subtitle {
  margin: -1.2vh 0 0;
  padding-left: .3em;
  font-size: clamp(12px, 1.8vh, 22px);
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- гадзіннік ---------- */
.clock {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.digits {
  /* --w — шырыня радка ў em, задаецца скрыптам */
  font-size: min(54vh, calc(90vw / var(--w, 2.22)));
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: lining-nums tabular-nums;
  text-shadow: 0 .02em .06em var(--shadow);
  transition: color .4s ease, opacity .3s ease;
}
.digits .d { display: inline-block; width: .64em; text-align: center; }
.digits .c { display: inline-block; width: .3em; text-align: center; transform: translateY(-.04em); }
.digits .s { display: inline-block; width: .5em; text-align: center; }

.clock.soon .digits { color: var(--gold); }

.clock.warn .digits {
  color: var(--red);
  text-shadow: 0 0 .12em var(--red-soft), 0 .02em .06em var(--shadow);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.025); }
}

/* перабор часу: лічбы чырвоныя, пад імі надпіс */
.clock.over { flex-direction: column; gap: 1.5vh; }
.clock.over .digits {
  color: var(--red);
  text-shadow: 0 0 .12em var(--red-soft), 0 .02em .06em var(--shadow);
}

.endtext {
  display: none;
  font-style: italic;
  font-weight: 400;
  letter-spacing: .01em;
  white-space: nowrap;
  text-shadow: 0 .02em .06em var(--shadow);
}
.clock.done .digits { display: none; }
.clock.done .endtext {
  display: block;
  /* --ew — прыкладная шырыня тэксту ў em, задаецца скрыптам */
  font-size: min(42vh, calc(80vw / var(--ew, 3.7)));
  animation: rise .7s ease-out both;
}
.clock.over .endtext {
  display: block;
  font-size: clamp(14px, 3.2vh, 40px);
  letter-spacing: .12em;
  color: var(--muted);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(.08em); }
  to   { opacity: 1; transform: none; }
}

/* паўза: лічбы прыглушаныя, двукроп'е міргае */
body[data-status="paused"] .digits { opacity: .55; }
body[data-status="paused"] .digits .c { animation: blink 1.1s steps(1, end) infinite; }
body[data-status="paused"] .thread span { opacity: .55; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- «нітка» — колькі засталося ---------- */
.thread {
  position: relative;
  width: min(70vw, 900px);
  height: 3px;
  background: var(--line);
}
.thread span {
  position: absolute;
  inset: 0;
  background: var(--red);
  transform-origin: center;
  transform: scaleX(1);
  transition: opacity .3s ease;
}
.thread::before,
.thread::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 9px;
  height: 9px;
  background: var(--red);
  transform: translateY(-50%) rotate(45deg);
}
.thread::before { left: -16px; }
.thread::after  { right: -16px; }
body.stopwatch .thread { visibility: hidden; }

/* ---------- успышка ў канцы ---------- */
.flash {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: var(--red);
  opacity: 0;
}
body.flashing .flash { animation: flash 2.4s ease-out both; }
@keyframes flash {
  0%, 33%, 66% { opacity: .85; }
  16%, 50%, 100% { opacity: 0; }
}

/* ---------- значок «без гуку» ---------- */
.badge {
  position: fixed;
  z-index: 3;
  top: calc(var(--band) + 2vh);
  right: 2.5vw;
  color: var(--muted);
}

/* ---------- тост ---------- */
.toast {
  position: fixed;
  z-index: 6;
  left: 50%;
  top: calc(var(--band) + 2.5vh);
  transform: translate(-50%, -8px);
  padding: .5em 1.1em;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--btn-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-family: var(--ui-font);
  font-size: clamp(13px, 1.7vh, 18px);
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- кіраванне ---------- */
.controls {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: calc(var(--band) + 2.2vh);
  transform: translateX(-50%);
  width: min(96vw, 1100px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .6rem;
  opacity: 1;
  transition: opacity .35s ease;
}
body:not(.ui) .controls { opacity: 0; pointer-events: none; }

.btn {
  font: inherit;
  font-size: clamp(13px, 1.7vh, 19px);
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: .65em 1.3em;
  color: var(--fg);
  background: var(--btn-bg);
  border: 1px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: border-color .2s, background .2s, filter .2s;
}
.btn:hover { border-color: var(--red); background: var(--red-soft); }
.btn:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff8ec; }
.btn.primary:hover { filter: brightness(1.12); }
.btn[hidden] { display: none; }

.hint {
  flex-basis: 100%;
  margin: .1em 0 0;
  text-align: center;
  font-size: clamp(11px, 1.35vh, 15px);
  letter-spacing: .08em;
  color: var(--muted);
}
@media (pointer: coarse) { .hint { display: none; } }

/* экран для залы: толькі таймер */
body.display { cursor: none; }
body.display .controls,
body.display .toast,
body.display .badge { display: none; }

/* ============================================================
   Налады
   ============================================================ */
dialog {
  width: min(94vw, 540px);
  max-height: min(90dvh, 760px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--fg);
  font-family: var(--ui-font);
  font-size: 15px;
  line-height: 1.35;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
  overflow: hidden;
}
dialog::backdrop {
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
dialog form {
  display: flex;
  flex-direction: column;
  max-height: calc(min(90dvh, 760px) - 2px);
}
dialog .orn-mini { height: 22px; z-index: auto; flex: none; }

.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 6px 22px;
  flex: none;
}
.dlg-head h2 {
  margin: 0;
  font: 400 15px/1 var(--font);
  letter-spacing: .3em;
  text-transform: uppercase;
}
.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font: 400 22px/1 var(--ui-font);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--input-bg); color: var(--fg); }
.icon-btn:focus-visible { outline: 2px solid var(--red); }

.tabs {
  display: flex;
  gap: 2px;
  padding: 2px 22px 0;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.tab {
  flex: 1;
  padding: 10px 4px 11px;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: var(--muted);
  font: 500 14px var(--ui-font);
  letter-spacing: .02em;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--fg); }
.tab.on { color: var(--fg); border-bottom-color: var(--red); }
.tab:focus-visible { outline: 2px solid var(--red); outline-offset: -2px; border-radius: 6px; }

.dlg-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 22px 10px;
  scrollbar-width: thin;
}
.panel { display: grid; gap: 20px; }
.panel[hidden] { display: none; }
#countdown-opts[hidden] { display: none; }

.field { display: grid; gap: 8px; }
.lbl {
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.help { margin: 0; font-size: 13px; line-height: 1.4; color: var(--muted); }
.help[hidden] { display: none; }
.inline { display: flex; gap: 10px; align-items: center; }

input[type="text"],
select {
  width: 100%;
  height: 42px;
  font: inherit;
  color: var(--fg);
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}
input[type="text"]::placeholder { color: var(--muted); opacity: .8; }
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}
#link-out { font-size: 13px; color: var(--muted); }
#link-out[hidden] { display: none; }

/* сегментаваны пераключальнік */
.seg {
  display: flex;
  padding: 3px;
  border-radius: 11px;
  background: var(--input-bg);
  border: 1px solid var(--line);
}
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg span {
  display: block;
  padding: 8px 6px;
  text-align: center;
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  transition: background .2s, color .2s;
}
.seg input:checked + span { background: var(--sel); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.seg input:focus-visible + span { outline: 2px solid var(--red); outline-offset: -2px; }

/* пераключальнікі */
.switches { display: grid; }
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 0;
  cursor: pointer;
}
.switch[hidden] { display: none; }
.switch input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 42px;
  height: 26px;
  margin: 0;
  border-radius: 13px;
  background: var(--line);
  position: relative;
  cursor: pointer;
  transition: background .2s;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  transition: transform .2s;
}
.switch input:checked { background: var(--red); }
.switch input:checked::after { transform: translateX(16px); }
.switch input:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* працягласць і этапы */
.timebox { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.timebox.multi .seglist { flex-basis: 100%; }
.seglist { display: grid; gap: 8px; }
.segrow { display: grid; grid-template-columns: 120px; gap: 8px; align-items: center; }
.segrow.multi { grid-template-columns: 1fr 110px 32px; }
.seg-dur { font-variant-numeric: tabular-nums; text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  font: 13px var(--ui-font);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.chip:hover { border-color: var(--red); background: var(--red-soft); }
.chip:focus-visible { outline: 2px solid var(--red); }

.link {
  border: 0;
  background: none;
  color: var(--red);
  font: 500 14px var(--ui-font);
  padding: 4px 0;
  cursor: pointer;
  text-align: left;
  justify-self: start;
}
.link:hover { text-decoration: underline; }
.link:focus-visible { outline: 2px solid var(--red); border-radius: 4px; }

input[type="range"] { flex: 1; accent-color: var(--red); margin: 0; }
input[type="color"] {
  width: 46px;
  height: 36px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--input-bg);
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 6px; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 6px; }

dialog .btn {
  font-family: var(--ui-font);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: .01em;
  text-transform: none;
  padding: 0 16px;
  height: 40px;
  border-radius: 10px;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
dialog .btn.wide { width: 100%; }

.keys summary { cursor: pointer; font-size: 14px; color: var(--muted); padding: 4px 0; }
.keys summary:hover { color: var(--fg); }
.keys dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  margin: 12px 0 0;
  font-size: 14px;
  align-items: center;
}
.keys dt, .keys dd { margin: 0; }
kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  font: 12px/1.5 var(--ui-font);
  text-align: center;
  white-space: nowrap;
}

.dlg-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px 16px;
  border-top: 1px solid var(--line);
  flex: none;
}
.spacer { flex: 1; }

@media (max-width: 420px) {
  .segrow.multi { grid-template-columns: 1fr 96px 32px; }
  .dlg-body { padding: 16px 16px 8px; }
  .dlg-foot { padding: 10px 16px 14px; }
  .tabs { padding: 2px 16px 0; }
}

@media (prefers-reduced-motion: reduce) {
  .clock.warn .digits { animation: none; }
  .clock.done .endtext { animation: none; }
  body[data-status="paused"] .digits .c { animation: none; }
  body.flashing .flash { animation: flash-soft 1.2s ease-out both; }
  @keyframes flash-soft { 0% { opacity: .6; } 100% { opacity: 0; } }
}

/* нізкія экраны (тэлефон у ландшафце): лічбы меншыя, каб кнопкі іх не закрывалі */
@media (max-height: 480px) {
  .digits { font-size: min(36vh, calc(90vw / var(--w, 2.22))); }
  .clock.done .endtext { font-size: min(30vh, calc(80vw / var(--ew, 3.7))); }
  .stage { padding-bottom: 12vh; }
}
