/* Палитра из референса: тёмное дерево, золото, королевский синий, пергамент. */
:root {
  --wood-dark: #2b1d12;
  --wood: #4a3220;
  --wood-light: #6b4a2e;
  --wood-edge: #8a6440;
  --gold: #f2c84b;
  --gold-deep: #c98f1c;
  --gold-shadow: #7a4f0c;
  --royal: #2e6fb8;
  --royal-light: #6fb3ea;
  --royal-deep: #173f73;
  --purple: #6a3fc4;
  --parchment: #efe2c0;
  --parchment-dark: #d6c08e;
  --ink: #3a2615;
  --text-light: #fff8e6;
  --grass: #5f8a2a;
  --danger: #c0392b;
  --font-ui: 'PT Serif', Georgia, serif;
  --font-title: 'Philosopher', 'PT Serif', serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1a1209; font-family: var(--font-ui); color: var(--text-light); user-select: none; }
canvas#game { display: block; width: 100vw; height: 100vh; cursor: grab; }
canvas#game.dragging { cursor: grabbing; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* Текст поверх игры всегда с тёмной обводкой — как в оригинале */
.outlined, #hud-top b, .pname, .bar span, .tab, .big-gold {
  text-shadow: -1px -1px 0 #1a0f06, 1px -1px 0 #1a0f06, -1px 1px 0 #1a0f06, 1px 1px 0 #1a0f06, 0 2px 3px rgba(0,0,0,.6);
}

/* ---------- Деревянная доска ---------- */
.plank {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.08) 0 2px, transparent 2px 38px),
    linear-gradient(180deg, var(--wood-light), var(--wood) 55%, var(--wood-dark));
  border: 2px solid var(--wood-dark);
  box-shadow: inset 0 1px 0 var(--wood-edge), inset 0 -2px 0 rgba(0,0,0,.35), 0 3px 6px rgba(0,0,0,.5);
  border-radius: 0 0 10px 10px;
  padding: 6px 12px;
}

#hud-top { position: fixed; top: 0; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; align-items: flex-start; z-index: 10; }
#hud-top b { font-size: 15px; font-weight: 700; }

.currency { display: grid; grid-template-columns: auto auto; gap: 4px 10px; align-items: center; }
.cur { display: flex; align-items: center; gap: 5px; min-width: 120px; }
.plus { width: 20px; height: 20px; border-radius: 4px; border: 1px solid var(--wood-dark); background: linear-gradient(var(--wood-edge), var(--wood)); color: var(--text-light); font-weight: 700; line-height: 1; padding: 0; margin-left: auto; }
.tab { border: 2px solid var(--wood-dark); border-radius: 6px; padding: 3px 10px; font-size: 13px; color: var(--text-light); }
.gold-tab { background: linear-gradient(var(--gold), var(--gold-deep)); }
.purple-tab { background: linear-gradient(#9a6cf0, var(--purple)); }

.profile { display: flex; gap: 8px; align-items: center; min-width: 260px; }
.crown { width: 54px; height: 46px; display: grid; place-items: end center; font-weight: 700; font-size: 13px;
  background: radial-gradient(circle at 50% 70%, #e9eef5, #9aa6b8 70%); clip-path: polygon(0 35%, 18% 0, 35% 30%, 50% 0, 65% 30%, 82% 0, 100% 35%, 92% 100%, 8% 100%);
  color: var(--ink); padding-bottom: 4px; }
.pinfo { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.pname { font-family: var(--font-title); text-align: center; font-size: 16px; }
.bar { position: relative; height: 16px; border-radius: 8px; background: #1a0f06; border: 1px solid #000; overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; width: 0; transition: width .4s; }
.bar.xp i { background: linear-gradient(var(--royal-light), var(--royal)); }
.bar.energy i { background: linear-gradient(#ffe57a, var(--gold-deep)); }
.bar span { position: relative; display: block; text-align: center; font-size: 11px; line-height: 15px; font-weight: 700; }
.bar .bolt { position: absolute; left: 4px; top: 0; }

.pop { display: flex; align-items: center; gap: 6px; padding: 10px 12px; }
.resources { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.resources div { display: flex; align-items: center; gap: 6px; }

.ico { width: 22px; height: 22px; border-radius: 50%; display: inline-block; flex: none; box-shadow: inset 0 -2px 0 rgba(0,0,0,.3), 0 1px 2px #000; }
.ico.coin { background: radial-gradient(circle at 35% 30%, #fff3b0, var(--gold) 40%, var(--gold-deep)); }
.ico.gem { background: radial-gradient(circle at 35% 30%, #fff, var(--royal-light) 40%, var(--royal)); border-radius: 30% 30% 50% 50%; }
.ico.helm { background: radial-gradient(circle at 40% 35%, #f0d2a0, #b07a4a); }
.ico.wood { background: radial-gradient(circle at 50% 50%, #e2b77a 25%, #8a5a2b 30%, #5b3a1a); }
.ico.stone { background: linear-gradient(135deg, #e6e3dc, #9a968e); border-radius: 5px; }
.ico.iron { background: linear-gradient(135deg, #c7d2e0, #5c6b80); border-radius: 4px; }

/* ---------- Круглые кнопки слева ---------- */
#hud-left { position: fixed; left: 10px; top: 32%; display: flex; flex-direction: column; gap: 10px; z-index: 10; }
.round { width: 58px; height: 58px; border-radius: 50%; font-size: 24px; color: var(--text-light);
  background: radial-gradient(circle at 50% 35%, #4a6b8c, #1d2f45);
  border: 3px solid #b8c4d0; box-shadow: 0 0 0 2px #1a1209, inset 0 -4px 6px rgba(0,0,0,.45), 0 4px 8px rgba(0,0,0,.6);
  transition: transform .12s; }
.round:hover { transform: scale(1.08); border-color: var(--gold); }
.round.small { width: 46px; height: 46px; font-size: 20px; }

/* ---------- Золотая большая кнопка ---------- */
.big-gold { min-width: 104px; padding: 12px 16px; border-radius: 50%; aspect-ratio: 1; font-family: var(--font-title); font-size: 16px; line-height: 1.1; color: var(--text-light);
  background: radial-gradient(circle at 50% 30%, #ffe680, var(--gold) 45%, var(--gold-deep));
  border: 4px solid #3a2a1a; box-shadow: 0 0 0 3px var(--gold-shadow), inset 0 -6px 8px rgba(0,0,0,.3), 0 6px 12px rgba(0,0,0,.6); }
.big-gold:hover { filter: brightness(1.1); }
.big-gold:disabled { filter: grayscale(.8) brightness(.7); cursor: default; }
.big-gold.wide { border-radius: 14px; aspect-ratio: auto; width: 100%; }

/* ---------- Панель ---------- */
#panel { position: fixed; z-index: 20; left: 50%; top: 52%; transform: translate(-50%, -50%); width: min(720px, calc(100vw - 32px)); max-height: 76vh; display: flex; flex-direction: column;
  border: 8px solid var(--wood); border-image: linear-gradient(var(--wood-edge), var(--wood-dark)) 1; background: var(--parchment); color: var(--ink); box-shadow: 0 12px 40px rgba(0,0,0,.7); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; background: linear-gradient(var(--royal), var(--royal-deep)); color: var(--text-light); font-family: var(--font-title); font-size: 20px; }
#panel-close { background: none; border: none; color: var(--text-light); font-size: 20px; }
#panel-body { padding: 14px; overflow: auto; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card { background: linear-gradient(#f7eed6, var(--parchment-dark)); border: 2px solid var(--wood-light); border-radius: 8px; padding: 8px; text-align: center; display: flex; flex-direction: column; gap: 6px; }
.card canvas { align-self: center; }
.card h4 { margin: 0; font-family: var(--font-title); font-size: 16px; }
.card .cost { font-size: 12px; color: #5a4028; min-height: 16px; }
.card button { border: 2px solid var(--wood-dark); border-radius: 6px; background: linear-gradient(var(--royal-light), var(--royal)); color: #fff; padding: 4px; font-weight: 700; }
.card button:disabled { filter: grayscale(1); opacity: .6; cursor: default; }
.row { display: flex; justify-content: space-between; align-items: center; padding: 6px 4px; border-bottom: 1px dashed var(--parchment-dark); }
#chat-log { height: 260px; overflow: auto; background: #fff8e4; border: 1px solid var(--parchment-dark); padding: 6px; margin-bottom: 8px; font-size: 14px; }
#chat-input { width: 100%; padding: 8px; font-family: inherit; border: 2px solid var(--wood-light); border-radius: 6px; }

/* ---------- Синий баннер ---------- */
#banner { position: fixed; top: 90px; left: 50%; transform: translateX(-50%); z-index: 9; padding: 12px 48px; text-align: center; min-width: 460px;
  background: linear-gradient(rgba(70,150,220,.92), rgba(30,100,170,.92)); border: 3px solid #e9f4ff; border-radius: 4px; box-shadow: 0 6px 18px rgba(0,0,0,.5); }
#banner-title { font-size: 18px; font-weight: 700; }
#banner-sub { font-size: 14px; opacity: .9; margin-top: 2px; }

/* ---------- Нижняя панель боя ---------- */
#deploy-bar { position: fixed; bottom: 6px; left: 50%; transform: translateX(-50%); display: flex; align-items: flex-end; gap: 10px; z-index: 10; }
#unit-slots { display: flex; gap: 6px; padding: 8px 10px; }
#unit-slots { background: linear-gradient(var(--wood-light), var(--wood-dark)); border: 2px solid var(--wood-dark); border-radius: 10px; box-shadow: 0 4px 10px rgba(0,0,0,.6); }
.slot { width: 76px; height: 92px; border-radius: 8px; border: 2px solid var(--wood-dark); background: radial-gradient(circle at 50% 80%, #8fbf5a, #3c5a1e); position: relative; display: grid; place-items: center; }
.slot.selected { border-color: var(--gold); box-shadow: 0 0 10px var(--gold); }
.slot.empty { filter: grayscale(1) brightness(.6); }
.slot .count { position: absolute; right: 4px; bottom: 2px; font-weight: 700; font-size: 16px; }
.slot .name { position: absolute; left: 0; right: 0; top: 2px; font-size: 11px; text-align: center; }

/* ---------- Панель дорог ---------- */
#road-bar { position: fixed; bottom: 6px; left: 50%; transform: translateX(-50%); display: flex; align-items: stretch; gap: 8px; z-index: 10; max-width: calc(100vw - 16px); }
#road-slots { display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; background: linear-gradient(var(--wood-light), var(--wood-dark)); border: 2px solid var(--wood-dark); border-radius: 10px; box-shadow: 0 4px 10px rgba(0,0,0,.6); }
.slot.road { width: 96px; height: 96px; cursor: pointer; background: radial-gradient(circle at 50% 60%, #8fbf5a, #3c5a1e); }
.slot.road canvas { width: 72px; height: 48px; margin-top: 8px; }
.slot.road .rcost { position: absolute; left: 0; right: 0; bottom: 3px; text-align: center; font-size: 11px; font-weight: 700; }
.road-side { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; padding: 8px 10px; min-width: 150px; background: linear-gradient(var(--wood-light), var(--wood-dark)); border: 2px solid var(--wood-dark); border-radius: 10px; box-shadow: 0 4px 10px rgba(0,0,0,.6); }
#road-cost { font-size: 13px; font-weight: 700; }
#btn-roads-done { padding: 8px 14px; font-size: 15px; }
.round.active { border-color: var(--gold); box-shadow: 0 0 0 2px #1a1209, 0 0 14px var(--gold); }

/* ---------- Панель гарнизона (как дороги) ---------- */
#garrison-bar { position: fixed; bottom: 6px; left: 50%; transform: translateX(-50%); display: flex; align-items: stretch; gap: 8px; z-index: 10; max-width: calc(100vw - 16px); }
#garrison-slots { display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; background: linear-gradient(var(--wood-light), var(--wood-dark)); border: 2px solid var(--wood-dark); border-radius: 10px; box-shadow: 0 4px 10px rgba(0,0,0,.6); }
#garrison-info { font-size: 13px; }
.slot canvas { width: 60px; height: 60px; }
.slot { cursor: pointer; }
.muted-light { color: var(--parchment); padding: 20px; font-size: 14px; }

/* ---------- Панель хода ---------- */
#turn-bar { position: fixed; bottom: 6px; left: 50%; transform: translateX(-50%); z-index: 10; display: flex; align-items: flex-end; gap: 10px; max-width: calc(100vw - 16px);
  padding: 6px 12px 8px; background: repeating-linear-gradient(90deg, rgba(0,0,0,.08) 0 2px, transparent 2px 38px), linear-gradient(var(--wood-light), var(--wood-dark));
  border: 2px solid var(--wood-dark); border-radius: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.6); }
#turn-current { position: relative; width: 84px; height: 84px; flex: none; }
#turn-current canvas { width: 84px; height: 84px; border-radius: 50%; border: 4px solid var(--gold); box-shadow: 0 0 0 2px var(--wood-dark), 0 0 14px rgba(242,200,75,.6); }
#turn-current span { position: absolute; left: -10px; right: -10px; bottom: -4px; text-align: center; font-size: 12px; font-weight: 700; }
#turn-queue { display: flex; gap: 6px; align-items: center; overflow: hidden; padding-bottom: 6px; }
.q-unit canvas { width: 50px; height: 50px; border-radius: 50%; border: 3px solid #b8c4d0; box-shadow: 0 0 0 2px var(--wood-dark); display: block; }
#turn-actions { display: flex; gap: 6px; padding-bottom: 6px; margin-left: 8px; }
#turn-actions .round:disabled { filter: grayscale(1) brightness(.6); cursor: default; transform: none; }

/* ---------- Карточка юнита ---------- */
#unit-card { position: fixed; z-index: 25; pointer-events: none; min-width: 220px; max-width: 300px; padding: 8px 12px 10px;
  background: var(--parchment); color: var(--ink); border: 3px solid var(--wood); border-radius: 8px; box-shadow: 0 8px 22px rgba(0,0,0,.6); font-size: 13px; }
.uc-name { font-family: var(--font-title); font-size: 17px; text-align: center; margin-bottom: 4px; }
.uc-stats, .stats { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 12px; }
.uc-hp { margin-top: 6px; height: 14px; }
.uc-hp i { background: linear-gradient(#b7e36a, #5f9a2a); }
.uc-hp span { color: #fff; font-size: 10px; line-height: 13px; }
.uc-note { margin-top: 4px; font-size: 12px; color: var(--royal-deep); }
.uc-hit { margin-top: 6px; font-weight: 700; }
.uc-hit.good { color: #2f7a1c; } .uc-hit.bad { color: #9a2a1a; }

/* ---------- Бой ждёт ---------- */
#away-box { position: fixed; z-index: 12; right: 12px; top: 120px; width: 250px; padding: 12px; text-align: center; font-size: 13px;
  background: linear-gradient(rgba(70,150,220,.95), rgba(30,100,170,.95)); border: 3px solid #e9f4ff; border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.5); }
#away-box button { margin-top: 8px; padding: 6px 12px; font-size: 14px; }

/* ---------- Панели: армия, казарма, походы ---------- */
#panel-body h4 { font-family: var(--font-title); margin: 12px 0 6px; color: var(--royal-deep); }
.unit-row { gap: 10px; align-items: center; }
.unit-row.locked { opacity: .55; }
.portrait { width: 48px; height: 48px; border-radius: 50%; border: 2px solid var(--wood-light); flex: none; }
.portrait.sm { width: 36px; height: 36px; }
.grow { flex: 1; min-width: 0; }
.count-col { text-align: right; min-width: 90px; }
.btn-row { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.btn-row .tab { padding: 6px 12px; font-size: 14px; }
.tab:disabled { filter: grayscale(.9); opacity: .7; cursor: default; }
.raid-tab { background: linear-gradient(#e0604a, #9a2a1a); }
.muted { color: #7a6448; font-style: italic; }
.center { text-align: center; }
.q-item { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.q-bar { height: 8px; margin-top: 3px; }
.q-bar i { background: linear-gradient(var(--royal-light), var(--royal)); transition: width 1s linear; }
.q-cancel { border: none; background: none; color: #9a2a1a; font-size: 18px; }
.mission { border: 2px solid var(--parchment-dark); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: linear-gradient(#f7eed6, #efe2c0); }
.mission.locked { opacity: .55; }
.m-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.m-head b { font-family: var(--font-title); font-size: 17px; margin-right: 4px; }
.chip { font-size: 11px; padding: 1px 8px; border-radius: 10px; background: var(--parchment-dark); }
.m-desc { font-size: 13px; margin: 6px 0; }
.m-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.small-cta { width: auto !important; padding: 8px 16px !important; font-size: 14px !important; flex: none; }

#toast { position: fixed; bottom: 130px; left: 50%; transform: translateX(-50%); z-index: 30; pointer-events: none; }
#toast div { background: rgba(26,15,6,.9); border: 2px solid var(--gold-deep); padding: 8px 16px; border-radius: 8px; margin-top: 6px; animation: fade 3s forwards; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Вход ---------- */
#login { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(circle, rgba(26,18,9,.6), rgba(26,18,9,.95)); }
.parchment { width: min(380px, calc(100vw - 32px)); padding: 28px; background: var(--parchment); color: var(--ink); text-align: center; border: 8px solid var(--wood); box-shadow: 0 0 0 3px var(--gold-deep), 0 20px 60px #000; }
.parchment h1 { font-family: var(--font-title); margin: 0; font-size: 36px; color: var(--royal-deep); }
.parchment .subtitle { font-family: var(--font-title); font-size: 17px; color: var(--gold-shadow); letter-spacing: .12em; text-transform: uppercase; margin-bottom: 2px; }
.parchment input { width: 100%; padding: 10px; margin: 6px 0; font: inherit; border: 2px solid var(--wood-light); border-radius: 6px; text-align: center; user-select: text; }
.parchment form { margin: 6px 0 4px; }
.parchment form .big-gold { margin-top: 10px; }

@media (max-width: 900px) {
  #hud-top { transform: translateX(-50%) scale(.72); transform-origin: top center; }
  #hud-left { top: auto; bottom: 120px; }
  .round { width: 46px; height: 46px; font-size: 20px; }
  #hud-left { bottom: 140px; }
  #turn-current, #turn-current canvas { width: 60px; height: 60px; }
  .q-unit canvas { width: 36px; height: 36px; }
  #away-box { top: auto; bottom: 120px; }
  .slot.road { width: 76px; height: 86px; }
  #banner { min-width: 0; width: calc(100vw - 32px); padding: 10px; }
}

/* ---------- Вход ---------- */
.auth-tabs { display: flex; gap: 6px; margin: 14px 0 6px; }
.auth-tabs button { flex: 1; padding: 8px; border: 2px solid var(--wood-light); border-radius: 6px; background: var(--parchment-dark); color: var(--ink); font-family: var(--font-title); font-size: 16px; }
.auth-tabs button.on { background: var(--royal); color: var(--text-light); border-color: var(--royal-deep); }
.auth-hint { font-size: 12px; color: #6b5537; min-height: 0; }
.auth-err { color: var(--danger); font-size: 14px; min-height: 18px; margin-top: 4px; }
.auth-note { background: #fff3cf; border: 1px solid var(--gold-deep); border-radius: 6px; padding: 8px; font-size: 14px; margin-top: 10px; }
.linklike { background: none; border: none; color: var(--royal-deep); text-decoration: underline; font-size: 14px; margin-top: 10px; }
#profile { cursor: pointer; }
#guest-mark { margin-left: 6px; color: #ffcf4a; }

/* ---------- Значки и формы в панелях ---------- */
.round { position: relative; }
.badge { position: absolute; top: -2px; right: -2px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--danger); color: #fff;
  font: 700 12px/20px var(--font-ui); font-style: normal; border: 2px solid var(--wood-dark); }
.form-row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.form-row input { flex: 1; min-width: 0; padding: 7px 10px; font: inherit; border: 2px solid var(--wood-light); border-radius: 6px; background: #fff8e4; color: var(--ink); user-select: text; }
.form-grid { display: grid; gap: 8px; max-width: 360px; }
.form-grid input { padding: 8px 10px; font: inherit; border: 2px solid var(--wood-light); border-radius: 6px; background: #fff8e4; color: var(--ink); user-select: text; }
.note { font-size: 13px; color: #6b5537; }
.warn-box { background: #fff3cf; border: 1px solid var(--gold-deep); border-radius: 6px; padding: 10px; margin-bottom: 10px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #b9a888; margin-right: 6px; vertical-align: 1px; }
.dot.on { background: #4caf50; box-shadow: 0 0 4px #4caf50; }
.row .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row .acts .tab { padding: 4px 9px; }
.unread { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; text-align: center; margin-left: 4px; }
.gift-box { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: #fff3cf; border: 1px solid var(--gold-deep); border-radius: 6px; padding: 8px 10px; margin: 8px 0; }

/* ---------- Чат и переписка ---------- */
#chat-log .sys { color: var(--royal-deep); font-style: italic; }
#chat-log .who { cursor: default; }
.dm-log { height: 300px; overflow: auto; background: #fff8e4; border: 1px solid var(--parchment-dark); padding: 8px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 6px; }
.dm-msg { max-width: 78%; padding: 6px 10px; border-radius: 10px; background: #efe2c0; font-size: 14px; user-select: text; }
.dm-msg.mine { align-self: flex-end; background: #cfe2f6; }
.dm-msg small { display: block; color: #8a7458; font-size: 11px; }

@media (max-width: 600px) {
  .row { flex-wrap: wrap; gap: 6px; }
  .row .acts { width: 100%; justify-content: flex-start; }
}
#panel-body .tab:not(.gold-tab):not(.raid-tab):not(.purple-tab) { background: linear-gradient(var(--wood-edge), var(--wood)); }
.form-grid .tab { padding: 8px 12px; font-size: 15px; }
.form-grid .auth-err:empty { display: none; }

/* Логотип на экране входа */
.parchment h1.logo { margin: -6px 0 0; line-height: 0; }
.parchment h1.logo img { width: min(300px, 70vw); height: auto; filter: drop-shadow(0 4px 6px rgba(43,29,18,.35)); }
