:root {
  --paper: #f6ecd2; --paper2: #efe1bd; --ink: #3b2a14; --line: #c9ad76;
  --accent: #d1432b; --gold: #ffd34d; --sea: #4aa0ab;
  --hand: "Marker Felt", "Chalkboard SE", "Comic Sans MS", "Bradley Hand", cursive;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--paper2);
  background-image: radial-gradient(circle at 20% 10%, #f9f1db 0, transparent 55%), radial-gradient(circle at 90% 90%, #e8d6a8 0, transparent 50%);
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { font-family: var(--hand); margin: 0; }

.card { background: var(--paper); border: 2.5px solid var(--ink); border-radius: 16px; box-shadow: 3px 4px 0 rgba(59,42,20,.25); padding: 12px 14px; }
.hint { font-size: 13px; opacity: .7; margin-top: 4px; }

/* ---------- настройка ---------- */
#setup { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.setup-card { width: min(560px, 100%); padding: 22px 24px; }
.setup-card h1 { font-size: clamp(30px, 6vw, 44px); color: var(--accent); }
.sub { margin: 6px 0 16px; line-height: 1.4; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0 4px; flex-wrap: wrap; }
.row label { font-weight: 700; }
.seg { display: inline-flex; border: 2.5px solid var(--ink); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; background: #fff8e6; padding: 8px 16px; font-weight: 700; font-size: 17px; border-right: 2px solid var(--ink); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--gold); }
.names { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin: 12px 0; }   /* по одному игроку в строке: имя + сложность */
.names div { display: flex; align-items: center; gap: 8px; min-width: 0; border: 2.5px solid var(--ink); border-radius: 12px; padding: 4px 8px; background: #fffaf0; }
.names span { font-size: 26px; }
.names input { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; font-size: 16px; font-weight: 600; padding: 6px 2px; outline: none; }
button.big { width: 100%; margin-top: 16px; padding: 12px 16px; border: 3px solid var(--ink); border-radius: 14px; background: var(--accent); color: #fff; font-family: var(--hand); font-size: 22px; box-shadow: 0 4px 0 var(--ink); }
button.big:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
button.big:disabled { background: #b9a98a; cursor: default; opacity: .75; }
button.link { display: block; margin: 12px auto 0; background: none; border: 0; text-decoration: underline; font-size: 15px; }

/* ---------- игра ---------- */
#game { display: flex; height: 100vh; height: 100dvh; gap: 10px; padding: 10px; }
#boardWrap { flex: 1; min-width: 0; display: flex; }
#board { position: relative; flex: 1; min-height: 280px; border: 3px solid var(--ink); border-radius: 14px; overflow: hidden; box-shadow: 4px 5px 0 rgba(59,42,20,.3); background: #e6d8b4; touch-action: none; cursor: grab; }
#board.grabbing { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#bg { position: absolute; left: 0; top: 0; display: block; max-width: none; }
#svg { position: absolute; left: 0; top: 0; overflow: visible; }
#tiles { position: absolute; left: 0; top: 0; }
.tile { position: absolute; display: block; max-width: none; opacity: 0; transition: opacity .3s; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.tile.on { opacity: 1; }
#modeSeg { position: absolute; right: 10px; top: 10px; z-index: 6; display: flex; border: 2.5px solid var(--ink); border-radius: 16px; overflow: hidden; background: #fff8e6; box-shadow: 0 3px 0 var(--ink); }
#modeSeg button { border: 0; border-right: 2px solid var(--ink); background: transparent; padding: 8px 12px; font-weight: 800; font-size: 14px; white-space: nowrap; }
#modeSeg button:last-child { border-right: 0; }
#modeSeg button.on { background: var(--gold); }
#zoomBtns { position: absolute; left: 10px; top: 10px; display: flex; flex-direction: column; gap: 8px; z-index: 6; }
#zoomBtns button { width: 46px; height: 46px; border-radius: 50%; border: 2.5px solid var(--ink); background: #fff8e6; font-size: 22px; font-weight: 800; line-height: 1; box-shadow: 0 3px 0 var(--ink); padding: 0; }
#zoomBtns button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.credit { position: absolute; right: 8px; bottom: 4px; max-width: 78%; text-align: right; font-size: 11px; background: rgba(255,250,235,.85); padding: 1px 6px; border-radius: 6px; }
.credit a { color: inherit; }

#panel { width: 340px; flex: none; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; padding-right: 2px; }
.panel-top { display: flex; justify-content: space-between; align-items: center; }
.panel-top h2 { font-size: 26px; color: var(--accent); }
.mini { width: 34px; height: 34px; border: 2.5px solid var(--ink); border-radius: 50%; background: #fff8e6; font-weight: 800; font-size: 17px; margin-left: 6px; }

.turn .who { display: flex; align-items: center; gap: 10px; }
#whoEmoji { font-size: 38px; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; border: 3px solid var(--ink); }
.whoName { font-family: var(--hand); font-size: 24px; line-height: 1.1; }
.whoSub { font-size: 14px; opacity: .8; min-height: 18px; }
.dieRow { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
#die { width: 84px; height: 84px; flex: none; display: grid; place-items: center; font-size: 74px; line-height: 1; background: #fff; border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 4px 0 var(--ink); padding-bottom: 6px; }
#die.shake { animation: shake .5s linear infinite; }
@keyframes shake { 0%{transform:rotate(0)} 25%{transform:rotate(-12deg) translateY(-3px)} 50%{transform:rotate(9deg)} 75%{transform:rotate(-7deg) translateY(-2px)} 100%{transform:rotate(0)} }
.dieSide { flex: 1; min-width: 0; }
.dieSide button.big { margin-top: 0; font-size: 19px; padding: 10px 8px; }
#stepsLeft { margin-top: 8px; font-weight: 700; font-size: 15px; min-height: 20px; }

#players { display: flex; flex-direction: column; gap: 6px; }
.prow { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 2.5px solid var(--ink); border-radius: 14px; background: var(--paper); }
.prow.cur { background: #fff3b8; box-shadow: 0 0 0 3px var(--gold); }
.prow .pe { font-size: 24px; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; border: 2.5px solid var(--ink); flex: none; }
.prow .pi { flex: 1; min-width: 0; }
.prow .pn { font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prow .pm { font-size: 13px; opacity: .85; }
.stamps { display: flex; gap: 2px; margin-top: 2px; }
.stamps span { font-size: 17px; filter: grayscale(1); opacity: .28; }
.stamps span.got { filter: none; opacity: 1; }
.badges { font-size: 14px; }

.potCard { font-size: 15px; }
.logCard { padding: 8px 12px; flex: 1; min-height: 70px; }
#log { list-style: none; margin: 0; padding: 0; font-size: 13.5px; line-height: 1.35; }
#log li { padding: 1px 0; opacity: .6; }
#log li:last-child { opacity: 1; font-weight: 700; }

#toast { position: absolute; left: 50%; bottom: 7%; transform: translateX(-50%) translateY(12px); background: var(--ink); color: #fff8e6; padding: 10px 20px; border-radius: 30px; font-family: var(--hand); font-size: clamp(14px, 2.2vw, 24px); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; text-align: center; max-width: 86%; z-index: 5; }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- элементы поля ---------- */
.edge-c { fill: none; stroke: #fffaf0; stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
.edge-l { fill: none; stroke: #b5522b; stroke-width: 6; stroke-dasharray: 14 9; stroke-linecap: round; stroke-linejoin: round; }
.edge-c.hot-c { stroke: var(--gold); stroke-width: 24; opacity: .95; }
.edge-l.hot { stroke: #d1432b; stroke-width: 8; stroke-dasharray: none; }
#board.hybrid .edge-l { stroke: #a8381d; }
#board.hybrid .edge-c { stroke: #fffaf0; stroke-width: 13; opacity: .92; }
#board.photo .edge-l { stroke: #ffb61e; }
#board.photo .edge-c { stroke: #fff; stroke-width: 13; opacity: .6; }
#board.photo .edge-l.hot { stroke: #e0362a; }
.nd .disc { stroke: #5a3a18; stroke-width: 4; }
.nd .lbl { font-family: var(--hand); fill: var(--ink); stroke: #fffbea; stroke-width: 6; paint-order: stroke; pointer-events: none; }
.nd .icon { pointer-events: none; }
.nd .ring { fill: none; stroke: var(--accent); stroke-width: 7; display: none; transform-box: fill-box; transform-origin: center; }
.nd.opt { cursor: pointer; }
.nd.opt .ring { display: block; animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(.9); opacity: 1; } 50% { transform: scale(1.18); opacity: .55; } }
.nd .check { display: none; }
.nd.got .check { display: block; }
.nd.home .disc { stroke: var(--accent); stroke-width: 8; animation: glow 1s ease-in-out infinite; }
@keyframes glow { 50% { stroke-width: 14; } }
.pawn { transform-box: fill-box; transform-origin: center bottom; }
.tok.cur .pawn { animation: bob .8s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-9px); } }

/* ---------- окно ---------- */
#modal { position: fixed; inset: 0; background: rgba(40,28,10,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal-box { width: min(420px, 100%); background: var(--paper); border: 3px solid var(--ink); border-radius: 20px; box-shadow: 5px 6px 0 rgba(0,0,0,.35); padding: 20px 22px; text-align: center; animation: pop .22s ease-out; max-height: 92vh; overflow-y: auto; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.m-icon { font-size: 64px; line-height: 1.1; }
.modal-box h3 { font-size: 26px; margin: 4px 0 8px; color: var(--accent); }
.modal-box p { margin: 0 0 6px; font-size: 17px; line-height: 1.4; text-align: left; white-space: pre-line; }
.modal-box p.c { text-align: center; }
.m-btns { display: flex; gap: 10px; margin-top: 12px; }
.m-btns button { flex: 1; margin: 0; font-size: 19px; padding: 10px 8px; }
.m-btns button.alt { background: #fff8e6; color: var(--ink); }

/* ---------- узкие экраны ---------- */
@media (max-aspect-ratio: 1/1), (max-width: 820px) {
  #game { flex-direction: column; height: auto; min-height: 100vh; }
  #boardWrap { flex: none; width: 100%; }
  #board { height: 66vh; min-height: 340px; }
  #panel { width: 100%; overflow: visible; }
  .names { grid-template-columns: 1fr; }
}

/* ---------- места, владельцы, сложность ---------- */
.names select { flex: none; border: 0; background: transparent; font: inherit; font-size: 14px; font-weight: 700; max-width: 45%; outline: none; cursor: pointer; }
.lv { margin-left: 6px; font-size: 13px; opacity: .8; }
.placesCard { padding: 8px 10px; }
#places { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
.pchip { display: flex; align-items: center; gap: 5px; font-size: 12.5px; min-width: 0; }
.pchip .pcn { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pchip b { font-size: 12px; white-space: nowrap; }
.pchip i { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--ink); font-style: normal; font-size: 13px; }
.nd .owner { display: none; }
.nd.owned .owner { display: block; }

/* ---------- круги и капитал ---------- */
.panel-top h2 small { font-family: inherit; font-size: 14px; color: var(--ink); opacity: .7; margin-left: 4px; }
.stamps span.cnt { filter: none; opacity: .85; margin-left: 6px; font-size: 12px; font-weight: 800; align-self: center; }

/* ---------- фото-аватары, карточки игроков, сохранения ---------- */
.names span.avwrap { position: relative; flex: none; font-size: inherit; display: inline-block; }
.names .avbtn { position: relative; width: 46px; height: 46px; border-radius: 50%; border: 2.5px solid var(--ink); background: #fff8e6 center / cover no-repeat; font-size: 26px; line-height: 1; padding: 0; cursor: pointer; }
.names .avbtn i { position: absolute; right: -6px; bottom: -6px; font-style: normal; font-size: 13px; background: #fff; border: 2px solid var(--ink); border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; }
.names .avx { position: absolute; right: -6px; top: -6px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; font-size: 11px; line-height: 1; padding: 0; cursor: pointer; }
#continueBox { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
#continueBox:empty { display: none; }
.savecard { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 2.5px solid var(--ink); border-radius: 14px; padding: 8px 12px; background: #fff3b8; }
.savecard .svi { min-width: 0; font-size: 15px; }
.dim { opacity: .7; font-size: 12.5px; }
.svb { display: flex; gap: 6px; flex: none; }
.svb button { border: 2.5px solid var(--ink); border-radius: 12px; background: var(--accent); color: #fff; font-weight: 800; padding: 8px 12px; cursor: pointer; }
.svb button.alt { background: #fff8e6; color: var(--ink); }
.prow { display: block; cursor: pointer; }
.prow-main { display: flex; align-items: center; gap: 8px; }
.pe, #whoEmoji { background-size: cover; background-position: center; background-repeat: no-repeat; }
.chev { font-size: 14px; opacity: .6; margin-left: auto; align-self: flex-start; }
.pdet { margin-top: 8px; padding-top: 8px; border-top: 2px dashed rgba(59,42,20,.3); font-size: 13px; line-height: 1.45; cursor: default; }
.pdet .dl { margin-bottom: 5px; }
.pdet .dli { padding-left: 4px; }
.pdet .dli.no { opacity: .55; }
.pbtns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pbtns button { border: 2px solid var(--ink); border-radius: 10px; background: #fff8e6; padding: 5px 9px; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.pchip i { background-size: cover; background-position: center; }
.tok.flash .pawn { animation: flash .6s ease-in-out 3; }
@keyframes flash { 50% { transform: scale(1.6); } }

/* шапка панели: заголовок + номер круга, три кнопки в одну строку */
.panel-top { align-items: flex-start; gap: 8px; }
.panel-top h2 { min-width: 0; font-size: 24px; line-height: 1.05; }
.panel-top h2 small { display: block; margin: 2px 0 0; font-size: 13px; }
.top-btns { display: flex; flex: none; gap: 6px; }
.top-btns .mini { margin-left: 0; }

/* ---------- корабли в море ---------- */
#svg { pointer-events: none; }                      /* корабли лежат под схемой троп, но должны ловить нажатия */
#svg .nd { pointer-events: auto; }
#ships { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
.ship { position: absolute; transform: translate(-50%, -50%); pointer-events: auto; cursor: pointer; }
.ship svg { display: block; width: 100%; height: auto; overflow: visible; }
.ship svg.flip { transform: scaleX(-1); }
.ship .drift { animation: shipDrift var(--dur, 20s) ease-in-out infinite alternate; will-change: transform; }
.ship .bob { animation: shipBob 3.4s ease-in-out infinite; transform-origin: 50% 80%; }
.ship.galley .drift { animation: shipSail var(--dur, 80s) linear infinite; }
@keyframes shipDrift { from { transform: translate(0, 0); } to { transform: translate(var(--dx), var(--dy)); } }
@keyframes shipBob { 0%, 100% { transform: translateY(0) rotate(-2.5deg); } 50% { transform: translateY(-5px) rotate(2.5deg); } }
@keyframes shipSail { 0% { transform: translate(0, 0); opacity: 0; } 6% { opacity: 1; } 92% { opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ship .drift, .ship .bob { animation: none; } }
