* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  background: #10151c;
  color: #e8ecf1;
}

.screen { width: 100%; height: 100vh; }
.hidden { display: none !important; }

/* ---------- Setup / login screen ---------- */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, #1b2a3d, #0a0e14 70%);
}
.setup-box {
  background: #161d28;
  border: 1px solid #2a3648;
  border-radius: 16px;
  padding: 40px 48px;
  width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  margin: 40px auto;
}
.setup-box h1 { margin: 0 0 4px; font-size: 2.4em; }
.setup-box h2 { margin: 0 0 6px; }
.subtitle { color: #8ba0bc; margin-bottom: 28px; }
.hint { color: #6d7f96; font-size: .8em; margin-top: 14px; }
.setup-row { text-align: right; margin-bottom: 18px; }
.setup-row label { display: block; margin-bottom: 6px; font-size: .9em; color: #a7b7ca; }
.setup-row select, .setup-row input {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid #33455c; background: #0f1620; color: #e8ecf1; font-size: 1em;
}
.error-text { color: #ff6b6b; font-size: .85em; min-height: 1.2em; margin: 8px 0; }
.primary-btn {
  width: 100%; padding: 13px; margin-top: 10px;
  background: linear-gradient(135deg, #d64545, #a52424);
  border: none; border-radius: 10px; color: white; font-size: 1.05em; font-weight: 700;
  cursor: pointer; transition: transform .1s, box-shadow .2s;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(214,69,69,.35); }

/* ---------- Game screen ---------- */
#app-screen { display: flex; flex-direction: column; }
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: #131a24; border-bottom: 1px solid #263243;
  flex-shrink: 0; gap: 10px;
}
#turnInfo { font-weight: 700; font-size: 1.1em; }
#phaseInfo { color: #f0b23c; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-right: auto; }
#meInfo { color: #93a5bc; font-size: .9em; }
.small-btn {
  padding: 6px 12px; background: #22303f; border: 1px solid #34465c;
  color: #e8ecf1; border-radius: 8px; cursor: pointer; font-size: .9em;
}
.small-btn:hover { background: #2c3e52; }
.small-btn:disabled { opacity: .4; cursor: not-allowed; }

#lobbyView { display: flex; align-items: center; justify-content: center; }

#main { flex: 1; display: flex; min-height: 0; }
#sidebar {
  width: 300px; flex-shrink: 0; background: #121822; border-left: 1px solid #263243;
  padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
}
#mapAndRules { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#mapWrap {
  flex: 1; position: relative; overflow: hidden; min-height: 0;
  background: #1b2838;
  padding: 14px;
  box-sizing: border-box;
}
#mapWrap::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 2;
  border: 14px solid transparent;
  border-image: repeating-linear-gradient(115deg, #4a2f18 0 6px, #6b451f 6px 12px, #3a2412 12px 18px) 14;
  box-shadow:
    inset 0 0 0 3px #241708,
    inset 0 2px 10px rgba(0,0,0,.7),
    0 8px 30px rgba(0,0,0,.6);
}
#map { width: 100%; height: 100%; display: block; position: relative; z-index: 1; border-radius: 2px; }

/* players panel */
#playersPanel { display: flex; flex-direction: column; gap: 6px; }
.player-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border-radius: 8px; background: #182130; font-size: .88em;
}
.player-row.active { outline: 2px solid #f0b23c; background: #22301f; }
.player-row.me { border: 1px solid #3a5a80; }
.player-row .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.player-row .pname { flex: 1; }
.player-row .pstats { color: #93a5bc; font-size: .85em; }

#cardsPanel h3, #actionPanel h3 { margin: 0 0 6px; font-size: .95em; color: #a7b7ca; }
#myCards { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.card-chip {
  padding: 4px 8px; border-radius: 6px; background: #22303f; font-size: .8em;
  border: 1px solid #34465c;
}

#territoryDetail {
  background: #182130; border: 1px solid #2a3a4f; border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
}
#tdName { font-size: 1.15em; font-weight: 800; color: #fff; }
#tdOwner { display: flex; align-items: center; gap: 6px; font-size: .9em; color: #cdd8e5; }
#tdOwner .dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
#tdBreakdown { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.piece-chip {
  display: flex; align-items: center; gap: 5px; padding: 6px 10px;
  background: #0f1620; border: 1px solid #2f4159; border-radius: 8px;
  font-size: 1.2em; font-weight: 800; color: #fff;
}
.piece-chip .icon { font-size: 1.1em; }
.piece-chip .lbl { font-size: .5em; font-weight: 600; color: #93a5bc; }
#tdTotal { font-size: .85em; color: #f0b23c; font-weight: 700; margin-top: 2px; }

#actionPanel { display: flex; flex-direction: column; gap: 8px; }
#reinforceInfo { font-size: .92em; color: #f0b23c; font-weight: 600; }
#selectionInfo { font-size: .88em; color: #cdd8e5; line-height: 1.5; }
#diceArea { display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; }
.dice-round { display: flex; align-items: center; gap: 6px; }
.round-label { font-size: .72em; color: #6d7f96; width: 40px; flex-shrink: 0; }
.dice-row { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.dice-sep { color: #6d7f96; font-size: .8em; margin: 0 2px; }
.die {
  width: 30px; height: 30px; border-radius: 6px; background: #eee; color: #111;
  display: flex; align-items: center; justify-content: center; font-weight: 800;
  font-size: 1em; box-shadow: 0 2px 4px rgba(0,0,0,.4);
  animation: diceRoll .45s ease-out;
}
.die.att { background: linear-gradient(145deg, #ee6b64, #c53a35); color: white; }
.die.def { background: linear-gradient(145deg, #5a92d6, #2c5590); color: white; }
@keyframes diceRoll {
  0% { transform: rotate(0deg) scale(.3); opacity: 0; }
  60% { transform: rotate(300deg) scale(1.15); opacity: 1; }
  100% { transform: rotate(360deg) scale(1); }
}
#actionButtons { display: flex; flex-wrap: wrap; gap: 6px; }

#log {
  flex: 1; min-height: 100px; max-height: 180px; overflow-y: auto;
  background: #0d1219; border-radius: 8px; padding: 8px; font-size: .8em;
  color: #9fb0c4; display: flex; flex-direction: column-reverse;
}
#log div { padding: 2px 0; border-bottom: 1px solid #1b232f; }

/* chat panel */
#chatPanel {
  display: flex; flex-direction: column; gap: 6px;
  background: #0d1219; border-radius: 8px; padding: 8px;
  flex-shrink: 0;
}
#chatTabs { display: flex; gap: 4px; }
.chat-tab {
  flex: 1; padding: 6px 4px; background: #182130; border: 1px solid #263243;
  color: #93a5bc; border-radius: 6px; cursor: pointer; font-size: .82em;
}
.chat-tab.active { background: #22303f; color: #fff; border-color: #3a4f68; }
#privateRecipient {
  padding: 6px 8px; border-radius: 6px; border: 1px solid #33455c;
  background: #0f1620; color: #e8ecf1; font-size: .85em;
}
#chatMessages {
  height: 140px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
  padding: 4px 2px;
}
.chat-msg { font-size: .82em; line-height: 1.4; padding: 4px 8px; border-radius: 8px; max-width: 90%; }
.chat-msg.me { align-self: flex-end; background: #2a4a6e; color: #eaf2ff; }
.chat-msg.them { align-self: flex-start; background: #22303f; color: #d6e0ec; }
.chat-msg .who { font-size: .75em; opacity: .65; display: block; margin-bottom: 1px; }
.chat-msg.system { align-self: center; background: transparent; color: #7c8ca0; font-style: italic; }
#chatInputRow { display: flex; gap: 6px; }
#chatInput {
  flex: 1; padding: 7px 10px; border-radius: 6px; border: 1px solid #33455c;
  background: #0f1620; color: #e8ecf1; font-size: .85em;
}
.privacy-pulse {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: #ff3b3b; flex-shrink: 0; margin-right: 6px; vertical-align: middle;
  box-shadow: 0 0 0 0 rgba(255,59,59,.7);
  animation: privacyPulse 1.4s infinite;
}
.privacy-pulse.hidden { display: none; }
@keyframes privacyPulse {
  0% { box-shadow: 0 0 0 0 rgba(255,59,59,.7); }
  70% { box-shadow: 0 0 0 7px rgba(255,59,59,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,59,59,0); }
}

/* ---------- map ---------- */
.territory-shape {
  stroke: rgba(0,0,0,.6); stroke-width: .6; cursor: pointer;
  transition: filter .12s;
  filter: url(#dropShadow);
  vector-effect: non-scaling-stroke;
}
.territory-shape:hover { stroke: #fff; stroke-width: 1.3; }
.territory-shape.selected { stroke: #ffd23c; stroke-width: 1.8; }
.territory-shape.attackable { stroke: #ff5252; stroke-width: 1.6; animation: pulseAttackShape 1s infinite; }
.territory-shape.capture-flash { animation: captureFlashShape .8s ease-out; }

@keyframes pulseAttackShape {
  0%, 100% { filter: url(#dropShadow) drop-shadow(0 0 2px #ff5252); }
  50% { filter: url(#dropShadow) drop-shadow(0 0 8px #ff5252); }
}
@keyframes captureFlashShape {
  0% { filter: url(#dropShadow) drop-shadow(0 0 0px #ffd23c); }
  40% { filter: url(#dropShadow) drop-shadow(0 0 14px #ffd23c); }
  100% { filter: url(#dropShadow) drop-shadow(0 0 0px #ffd23c); }
}

.territory-badge { cursor: pointer; pointer-events: none; }
.territory-badge .badge-halo {
  fill: rgba(10,14,20,.72); stroke: rgba(255,255,255,.55); stroke-width: .8;
  pointer-events: auto;
}
.territory-badge.selected .badge-halo { stroke: #ffd23c; stroke-width: 1.4; }
.territory-badge.attackable .badge-halo { stroke: #ff5252; stroke-width: 1.4; }
.territory-badge.capture-flash .badge-halo { animation: captureFlashShape .8s ease-out; }
.territory-badge .armyCount {
  fill: #fff; font-size: 8.5px; font-weight: 900; text-anchor: middle; pointer-events: none;
}
.territory-badge .pieceRow {
  fill: #ffe9a8; font-size: 6.5px; text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: rgba(0,0,0,.8); stroke-width: 1.5px;
}
.edge.sea {
  stroke: #e8c563; stroke-width: 1; stroke-dasharray: 1.5 2.5; stroke-linecap: round;
  opacity: .8;
  pointer-events: none;
}
.continent-label {
  fill: rgba(255,255,255,.55); font-size: 10px; font-weight: 800; letter-spacing: .5px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.7));
  pointer-events: none;
}

/* continent bonus badges */
.continent-badge { pointer-events: none; }
.continent-badge circle {
  stroke: #1a1108; stroke-width: 1.3;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.6));
}
.continent-badge text {
  fill: #fff8e0; font-size: 8.5px; font-weight: 900; text-anchor: middle;
  paint-order: stroke; stroke: rgba(0,0,0,.55); stroke-width: 1px;
}

/* compass rose */
.compass-rose { pointer-events: none; opacity: .55; }
.compass-ring { fill: none; stroke: #d8b56a; stroke-width: 1; }
.compass-spoke { stroke: #d8b56a; stroke-width: .6; }
.compass-dir { fill: #d8b56a; font-size: 7px; font-weight: 800; text-anchor: middle; }
.territory-name {
  fill: #fff; font-size: 5.6px; font-weight: 700; text-anchor: middle;
  pointer-events: none; paint-order: stroke; stroke: rgba(0,0,0,.85); stroke-width: 1.4px;
}

/* modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  background: #161d28; border: 1px solid #2a3648; border-radius: 14px;
  padding: 30px 34px; max-width: 460px; width: 90%;
  max-height: 85vh; overflow-y: auto;
}
.modal-box.wide { max-width: 640px; }
.modal-box h2 { margin-top: 0; }
.modal-box h3 { margin: 18px 0 8px; color: #a7b7ca; font-size: 1em; }
.modal-box ul { padding-right: 18px; line-height: 1.9; font-size: .92em; color: #cdd8e5; }
.map-credit { font-size: .75em; color: #62728a; margin-top: 14px; }

/* admin table */
#usersTable { width: 100%; border-collapse: collapse; font-size: .85em; }
#usersTable th, #usersTable td { padding: 6px 8px; border-bottom: 1px solid #263243; text-align: right; }
#usersTable th { color: #93a5bc; font-weight: 600; }
#usersTable td.pw { font-family: monospace; color: #f0b23c; }
.admin-add-user { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.admin-add-user input {
  flex: 1; min-width: 100px; padding: 8px 10px; border-radius: 6px;
  border: 1px solid #33455c; background: #0f1620; color: #e8ecf1;
}
#gameSlotPicker { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.slot-check { display: flex; align-items: center; gap: 8px; font-size: .9em; }

/* rules panel */
#rulesPanel {
  flex-shrink: 0; background: #121822; border-top: 1px solid #263243;
  padding: 10px 16px; max-height: 42vh; overflow-y: auto;
}
#rulesBody {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 10px;
}
.rules-col h4 { margin: 10px 0 4px; color: #f0b23c; font-size: .92em; }
.rules-col h4:first-child { margin-top: 0; }
.rules-col p { margin: 2px 0 8px; font-size: .82em; color: #cdd8e5; line-height: 1.6; }
.rules-col table { width: 100%; border-collapse: collapse; font-size: .78em; margin-bottom: 8px; }
.rules-col table caption { text-align: right; color: #93a5bc; font-size: .85em; margin-bottom: 4px; }
.rules-col th, .rules-col td { padding: 3px 6px; border-bottom: 1px solid #223047; text-align: center; }
.rules-col th { color: #93a5bc; }

/* territory cards (under chat) */
#cardsPanel { display: flex; flex-direction: column; gap: 8px; }
#myCards { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 0; }
.risk-card {
  width: 74px; height: 104px; border-radius: 8px; position: relative; overflow: hidden;
  background: linear-gradient(160deg, #efe6cf, #d9cca4);
  border: 2px solid #8a7a4e; box-shadow: 0 3px 8px rgba(0,0,0,.5);
  display: flex; flex-direction: column; align-items: center;
  padding: 3px 2px 0;
}
.risk-card .rc-name-fa { font-size: 7px; font-weight: 800; color: #2a2318; text-align: center; line-height: 1.1; }
.risk-card .rc-name-en { font-size: 4.5px; font-weight: 700; color: #5a4f33; letter-spacing: .3px; text-align: center; margin-bottom: 1px; }
.risk-card .rc-silhouette { width: 46px; height: 34px; margin: 1px 0; }
.risk-card .rc-silhouette path { fill: #2f6b3d; stroke: #1c4527; stroke-width: 2; }
.risk-card .rc-ribbon {
  width: 100%; margin-top: auto; padding: 3px 0 4px;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  background: linear-gradient(180deg, #b23c3c, #8a2424);
  border-top: 1px solid #6e1c1c;
}
.risk-card .rc-icon { font-size: 11px; line-height: 1; }
.risk-card .rc-stars { font-size: 6px; color: #ffd23c; letter-spacing: 1px; }

#tradePreview {
  background: #0f1620; border: 1px solid #33455c; border-radius: 8px; padding: 10px;
  font-size: .82em; color: #cdd8e5; display: flex; flex-direction: column; gap: 6px;
}
#tradePreview .tp-line { display: flex; justify-content: space-between; }
#tradePreview .tp-win { color: #f0b23c; font-weight: 700; }
#tradePreview .tp-actions { display: flex; gap: 6px; margin-top: 4px; }

@media (max-width: 900px) {
  #main { flex-direction: column; }
  #sidebar { width: 100%; height: 40vh; border-left: none; border-top: 1px solid #263243; }
}
