:root {
  --leather:      #2a120c;
  --leather-deep: #170704;
  --leather-lit:  #3a1d12;
  --cognac:       #b87547;
  --amber:        #e3a568;
  --amber-hi:     #f3caa0;
  --amber-soft:   #c9894e;
  --cream:        #f2e3c4;
  --cream-soft:   rgba(242,227,196,0.70);
  --cream-dim:    rgba(242,227,196,0.36);
  --line:         rgba(201,137,78,0.38);
  --line-soft:    rgba(201,137,78,0.18);
  --ember:        #dc8159;
  --emberly:      #e09066;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

body {
  font-family: "Fraunces", serif;
  font-weight: 400;
  color: var(--cream);
  background:
    radial-gradient(ellipse 1100px 750px at 50% 18%, var(--leather-lit) 0%, var(--leather) 48%, var(--leather-deep) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  padding: 0;
  position: relative;
  font-size: 17px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' seed='11'/><feColorMatrix values='0 0 0 0 0.9  0 0 0 0 0.65  0 0 0 0 0.38  0 0 0 0.1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  mix-blend-mode: overlay;
  opacity: 0.5;
  z-index: 1;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 8%, rgba(232,169,104,0.07), transparent 42%),
    radial-gradient(ellipse at center, transparent 42%, rgba(0,0,0,0.6) 100%);
  z-index: 2;
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  position: relative;
  z-index: 5;
  padding: 68px 40px 72px;
  display: block;
}

/* =========================
   Header
   ========================= */

.app-header {
  text-align: center;
  padding: 0 0 52px;
  position: relative;
}
.app-header .mark {
  display: block;
  width: 30px; height: 30px;
  margin: 0 auto 22px;
  color: var(--amber);
}
.app-header .eyebrow {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.48em;
  text-transform: uppercase;
  color: var(--amber);
  margin: 0 0 22px;
}
.app-header h1 {
  font-family: "Italiana", serif;
  font-weight: 400;
  font-size: clamp(36px, 5.2vw, 54px);
  line-height: 1.05;
  margin: 0;
  color: var(--cream);
  letter-spacing: 0.015em;
}
.app-header .rule {
  display: block;
  width: 56px;
  height: 1px;
  margin: 22px auto 0;
  background: linear-gradient(to right, transparent, var(--cognac), transparent);
}
.app-header .sub {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 300;
  font-size: 17px;
  line-height: 1.5;
  color: var(--cream-soft);
  margin: 14px auto 0;
  max-width: 460px;
  letter-spacing: 0.01em;
}

/* =========================
   Settings
   ========================= */

.settings {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 32px;
  align-items: center;
  padding: 20px 28px;
  background: linear-gradient(180deg, rgba(0,0,0,0.22), rgba(0,0,0,0.1));
  border: 1px solid var(--line);
  border-radius: 2px;
  box-shadow:
    inset 0 1px 0 rgba(244,202,160,0.08),
    0 12px 30px -12px rgba(0,0,0,0.55);
  margin-bottom: 36px;
}

.settings .field {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 0;
}

.settings .lbl {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.32em;
  color: var(--amber);
  text-transform: uppercase;
  margin: 0;
  padding: 0;
}

.settings .radios { display: inline-flex; gap: 8px; }
.settings .radios label { cursor: pointer; display: inline-block; position: relative; }
.settings .radios input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0; height: 0;
}
.settings .radios .pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-size: 22px;
  width: 42px; height: 42px;
  color: var(--cream-soft);
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(0,0,0,0.22);
  transition: color 0.2s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.settings .radios input:checked + .pill {
  font-weight: 600;
  color: var(--leather-deep);
  background: radial-gradient(circle at 32% 30%, var(--amber-hi), var(--cognac));
  border-color: var(--amber);
  box-shadow: 0 0 22px rgba(232,169,104,0.35);
}
.settings .radios label:hover .pill { border-color: var(--amber); }

.settings input[type="number"] {
  width: 60px;
  font-family: "Italiana", serif;
  font-size: 26px;
  color: var(--amber-hi);
  text-align: center;
  border: 0;
  border-bottom: 1px solid var(--cognac);
  background: transparent;
  padding: 2px 4px;
  outline: 0;
}
.settings input[type="number"]:focus { border-bottom-color: var(--amber); }

/* =========================
   Board + pulya
   ========================= */

.board {
  padding: 34px 28px 30px;
  background:
    radial-gradient(ellipse at center, rgba(232,169,104,0.04) 0%, transparent 60%),
    rgba(0,0,0,0.28);
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.35),
    inset 0 0 0 4px rgba(0,0,0,0.12),
    inset 0 0 0 5px rgba(184,117,71,0.16),
    0 40px 80px -20px rgba(0,0,0,0.6);
  margin-bottom: 40px;
  position: relative;
}

.pulya-wrapper {
  display: grid;
  grid-template-columns: minmax(90px, auto) minmax(0, 1fr) minmax(90px, auto);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    ".    north .   "
    "west frame east"
    ".    south .   ";
  gap: 22px 26px;
  align-items: center;
  justify-items: center;
  max-width: 1040px;
  margin: 0 auto;
}

.pulya-frame {
  grid-area: frame;
  position: relative;
  width: 100%;
  max-width: 720px;
  aspect-ratio: 1 / 1;
  filter: drop-shadow(0 0 24px rgba(232,169,104,0.08));
}

.name-field {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  font-family: "Fraunces", serif;
}
.name-field input {
  width: 100%;
  min-width: 0;
  max-width: 280px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 400;
  font-size: 20px;
  color: var(--amber-hi);
  text-align: center;
  padding: 6px 8px;
  outline: 0;
  letter-spacing: 0.005em;
}
.name-field input:focus { border-bottom-color: var(--amber); }
.name-field input::placeholder { color: var(--cream-dim); font-style: italic; }

.name-north { grid-area: north; }
.name-south { grid-area: south; }
.name-west  { grid-area: west; }
.name-east  { grid-area: east; }
.name-north, .name-south { max-width: 320px; }
.name-west,  .name-east  { max-width: 150px; }

.board[data-players="3"] .name-north { visibility: hidden; }

/* =========================
   SVG (pulya diagram)
   ========================= */

.pulya-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.pulya-svg .frame-rect {
  fill: rgba(0,0,0,0.22);
  stroke: var(--amber-soft);
  stroke-width: 1.6;
  stroke-opacity: 0.85;
}

.pulya-svg .diag {
  stroke: var(--amber-soft);
  stroke-width: 1.4;
  stroke-opacity: 0.78;
  fill: none;
  stroke-linecap: round;
}

.pulya-svg .zoneline {
  stroke: var(--amber-soft);
  stroke-width: 0.9;
  stroke-dasharray: 2 3;
  fill: none;
  stroke-opacity: 0.32;
}

.pulya-svg .split {
  stroke: var(--amber-soft);
  stroke-width: 0.7;
  fill: none;
  stroke-opacity: 0.22;
}

.board[data-players="3"] .pulya-svg .split-4p { display: none; }
.board[data-players="4"] .pulya-svg .split-3p { display: none; }

.pulya-svg .north-dead { fill: url(#deadfade); }
.board[data-players="4"] .pulya-svg .north-dead { display: none; }

.pulya-svg .medallion {
  fill: var(--leather-deep);
  stroke: var(--amber);
  stroke-width: 1.3;
}
.pulya-svg .medallion-ring {
  fill: none;
  stroke: var(--cognac);
  stroke-width: 0.7;
  stroke-opacity: 0.55;
}
.pulya-svg .seal-text {
  font-family: "Italiana", serif;
  font-size: 22px;
  font-weight: 400;
  fill: var(--amber-hi);
  letter-spacing: 0.02em;
}

/* =========================
   Player marks (initial letter, outer edge)
   ========================= */

.player-mark {
  position: absolute;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--leather-deep);
  border: 1px solid var(--amber);
  color: var(--amber-hi);
  font-family: "Italiana", serif;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  pointer-events: none;
  box-shadow:
    0 0 10px rgba(0,0,0,0.5),
    0 0 18px rgba(232,169,104,0.12);
  letter-spacing: 0;
}
.player-mark-north { top: 4.545%;  left: 50%;     transform: translate(-50%, -50%); }
.player-mark-south { top: 95.455%; left: 50%;     transform: translate(-50%, -50%); }
.player-mark-west  { top: 50%;     left: 4.545%;  transform: translate(-50%, -50%); }
.player-mark-east  { top: 50%;     left: 95.455%; transform: translate(-50%, -50%); }
.board[data-players="3"] .player-mark-north { display: none; }

/* =========================
   Zone inputs
   ========================= */

.sector {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.zone {
  position: absolute;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.14);
  border: 0;
  border-radius: 1px;
  cursor: text;
  transition: background 0.22s ease, box-shadow 0.22s ease;
}

.zone:hover {
  background: rgba(232,169,104,0.10);
}

.zone:focus-within {
  background: rgba(232,169,104,0.16);
  box-shadow:
    inset 0 0 0 1px var(--amber),
    0 0 18px rgba(244,202,160,0.22);
  z-index: 3;
}

.zone input {
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  padding: 0;
  text-align: center;
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-size: 17px;
  color: var(--amber-hi);
  line-height: 1;
  letter-spacing: 0.01em;
  min-width: 0;
}
.zone input::placeholder { color: transparent; }

.zone input::-webkit-outer-spin-button,
.zone input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.zone input[type="number"] { -moz-appearance: textfield; }

/* ===== Zone positions (widened pulya: band 68.2%–78.4% / 21.6%–31.8%) ===== */

/* SOUTH */
.sector-south .zone-gora       { left: 40%; top: 60%;   width: 20%; height: 8%; }
.sector-south .zone-pulya      { left: 30%; top: 68.5%; width: 40%; height: 9.7%; }
.sector-south .zone-whist-west  { left: 19%; top: 82%;  width: 21%; height: 11%; }
.sector-south .zone-whist-north { left: 42%; top: 82%;  width: 16%; height: 11%; }
.sector-south .zone-whist-east  { left: 60%; top: 82%;  width: 21%; height: 11%; }
.board[data-players="3"] .sector-south .zone-whist-north { display: none; }
.board[data-players="3"] .sector-south .zone-whist-west  { width: 30%; }
.board[data-players="3"] .sector-south .zone-whist-east  { left: 52%; width: 30%; }

/* WEST */
.sector-west .zone-gora        { left: 32%;   top: 44%; width: 9%;   height: 12%; }
.sector-west .zone-pulya       { left: 22%;   top: 40%; width: 9.7%;  height: 20%; }
.sector-west .zone-whist-north { left: 5%; top: 22%; width: 13%; height: 16%; }
.sector-west .zone-whist-east  { left: 5%; top: 42%; width: 13%; height: 16%; }
.sector-west .zone-whist-south { left: 5%; top: 62%; width: 13%; height: 16%; }
.board[data-players="3"] .sector-west .zone-whist-north { display: none; }
.board[data-players="3"] .sector-west .zone-whist-east  { top: 25%; height: 22%; }
.board[data-players="3"] .sector-west .zone-whist-south { top: 53%; height: 22%; }

/* EAST */
.sector-east .zone-gora        { left: 59%;   top: 44%; width: 9%;  height: 12%; }
.sector-east .zone-pulya       { left: 68.3%; top: 40%; width: 9.7%; height: 20%; }
.sector-east .zone-whist-north { left: 82%; top: 22%; width: 13%; height: 16%; }
.sector-east .zone-whist-west  { left: 82%; top: 42%; width: 13%; height: 16%; }
.sector-east .zone-whist-south { left: 82%; top: 62%; width: 13%; height: 16%; }
.board[data-players="3"] .sector-east .zone-whist-north { display: none; }
.board[data-players="3"] .sector-east .zone-whist-west  { top: 25%; height: 22%; }
.board[data-players="3"] .sector-east .zone-whist-south { top: 53%; height: 22%; }

/* NORTH */
.sector-north .zone-gora        { left: 40%; top: 32%; width: 20%; height: 8%; }
.sector-north .zone-pulya       { left: 30%; top: 21.8%; width: 40%; height: 9.7%; }
.sector-north .zone-whist-west  { left: 19%; top: 7%; width: 21%; height: 11%; }
.sector-north .zone-whist-south { left: 42%; top: 7%; width: 16%; height: 11%; }
.sector-north .zone-whist-east  { left: 60%; top: 7%; width: 21%; height: 11%; }
.board[data-players="3"] .sector-north { display: none; }

/* =========================
   Saldo
   ========================= */

.saldo {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 22px 0 0;
  border-top: 1px solid var(--line);
  position: relative;
}
.saldo:empty { display: none; }
.saldo::before {
  content: "Итог";
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.45em;
  text-transform: uppercase;
  color: var(--amber);
  background: var(--leather);
  padding: 0 14px;
}
.saldo .item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  padding: 18px 4px;
  gap: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.saldo .item:last-child { border-bottom: 0; }
.saldo .item .name {
  font-family: "Italiana", serif;
  font-size: 28px;
  color: var(--cream);
  letter-spacing: 0.02em;
}
.saldo .item .amount {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-size: 38px;
  line-height: 1;
}
.saldo .item.pos .amount { color: var(--amber-hi); }
.saldo .item.neg .amount { color: var(--emberly); }
.saldo .item.zero .amount { color: var(--cream-soft); }
.saldo .item.pos .amount::before { content: "+"; }
.saldo .item.neg .amount::before { content: "−"; }

/* =========================
   Responsive
   ========================= */

@media (max-width: 960px) {
  .app { padding: 48px 18px 60px; }
  .board { padding: 26px 18px 24px; }

  .pulya-wrapper {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 22px 16px;
    max-width: none;
    margin: 0;
  }
  .board[data-players="4"] .pulya-wrapper {
    grid-template-areas:
      ".    north ."
      "west .     east"
      ".    south ."
      "frame frame frame";
  }
  .board[data-players="3"] .pulya-wrapper {
    grid-template-areas:
      "west .     east"
      ".    south ."
      "frame frame frame";
  }
  .pulya-wrapper > .name-north { grid-area: north; justify-self: center; width: 100%; max-width: 280px; }
  .pulya-wrapper > .name-south { grid-area: south; justify-self: center; width: 100%; max-width: 280px; }
  .pulya-wrapper > .name-west  { grid-area: west;  justify-self: stretch; width: auto; max-width: none; }
  .pulya-wrapper > .name-east  { grid-area: east;  justify-self: stretch; width: auto; max-width: none; }
  .pulya-wrapper > .pulya-frame {
    grid-area: frame;
    max-width: 560px;
    width: 100%;
    margin: 10px auto 0;
    justify-self: center;
  }

  .board[data-players="3"] .name-north { display: none; }

  .name-field input {
    padding: 8px 10px;
    font-size: 16px;
    max-width: none;
  }

  .sector-west .zone-whist-north,
  .sector-west .zone-whist-east,
  .sector-west .zone-whist-south { left: 6%; width: 10%; }
  .sector-east .zone-whist-north,
  .sector-east .zone-whist-west,
  .sector-east .zone-whist-south { left: 84%; width: 10%; }
  .sector-west .zone-pulya  { left: 22%;   width: 10%; top: 36%; height: 28%; }
  .sector-east .zone-pulya  { left: 68%;   width: 10%; top: 36%; height: 28%; }
  .sector-south .zone-pulya { left: 30%; top: 68%;   width: 40%; height: 10.5%; }
  .sector-north .zone-pulya { left: 30%; top: 21.5%; width: 40%; height: 10.5%; }
  .zone-pulya input { font-size: 16px; }

  .saldo .item .name { font-size: 22px; }
  .saldo .item .amount { font-size: 30px; }
}

@media (max-width: 640px) {
  .app { padding: 40px 14px 52px; }
  .board { padding: 22px 14px 22px; }
}

@media (max-width: 400px) {
  .app { padding: 32px 8px 44px; }
  .board { padding: 18px 10px 18px; }
  .pulya-wrapper { gap: 8px 4px; }
  .name-field input { font-size: 15px; padding: 7px 8px; }
  .zone input { font-size: 15px; }
  .zone-pulya input { font-size: 14px; }
}

@media (max-width: 360px) {
  .saldo .item { padding: 14px 2px; }
}

/* =========================
   Info footer (rules + method, for SEO)
   ========================= */

.info {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 28px 80px;
  position: relative;
  z-index: 5;
  color: var(--cream-soft);
  font-family: "Fraunces", serif;
  font-size: 16px;
  line-height: 1.7;
}
.info::before {
  content: "";
  display: block;
  width: 72px;
  height: 1px;
  margin: 0 auto 56px;
  background: linear-gradient(to right, transparent, var(--cognac), transparent);
}
.info-block {
  margin-bottom: 56px;
}
.info-block:last-child { margin-bottom: 0; }

.info h2 {
  font-family: "Italiana", serif;
  font-weight: 400;
  font-size: 30px;
  color: var(--cream);
  margin: 0 0 18px;
  letter-spacing: 0.015em;
  line-height: 1.1;
}
.info h3 {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 500;
  font-size: 20px;
  color: var(--amber-hi);
  margin: 26px 0 8px;
  letter-spacing: 0.005em;
}
.info p {
  margin: 0 0 14px;
}
.info ol, .info ul {
  margin: 0 0 16px;
  padding-left: 22px;
}
.info ol { padding-left: 28px; }
.info li {
  margin-bottom: 8px;
}
.info ol li::marker {
  font-family: "Italiana", serif;
  color: var(--amber);
  font-size: 17px;
}
.info ul li::marker {
  color: var(--cognac);
}
.info b {
  color: var(--amber-hi);
  font-weight: 500;
  font-family: "Fraunces", serif;
  font-variant-numeric: tabular-nums;
}
.info i {
  color: var(--amber);
  font-style: italic;
}
.info sub {
  font-size: 0.72em;
  vertical-align: sub;
  line-height: 1;
  color: var(--cream-soft);
}

.info .formula {
  margin: 16px 0 18px;
  padding: 20px 22px;
  background: rgba(0,0,0,0.32);
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2);
}
.info .formula p {
  margin: 0 0 12px;
  font-style: italic;
  color: var(--cream-soft);
  font-size: 15px;
}
.info .formula pre {
  font-family: "JetBrains Mono", monospace;
  font-weight: 400;
  font-size: 13px;
  line-height: 1.75;
  color: var(--amber-hi);
  margin: 0;
  white-space: pre-wrap;
  overflow-x: auto;
  letter-spacing: 0.005em;
}

.footer-bottom {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--line-soft);
  text-align: center;
}
.footer-bottom .copyright {
  margin: 0;
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 400;
  font-size: 14px;
  letter-spacing: 0.01em;
  color: var(--cream-dim);
}
.footer-bottom a {
  color: var(--amber);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1px;
  transition: color 0.18s, border-color 0.18s;
}
.footer-bottom a:hover {
  color: var(--amber-hi);
  border-bottom-color: var(--amber);
}

@media (max-width: 640px) {
  .info { padding: 16px 18px 64px; font-size: 15px; }
  .info::before { margin-bottom: 44px; }
  .info h2 { font-size: 26px; }
  .info h3 { font-size: 18px; }
  .info-block { margin-bottom: 44px; }
  .info .formula { padding: 16px 18px; }
  .info .formula pre { font-size: 12px; }
  .footer-bottom { margin-top: 36px; padding-top: 20px; }
  .footer-bottom .copyright { font-size: 13px; }
}
