:root {
  color-scheme: dark;
  --bg: #101620;
  --panel: #1a2635;
  --panel2: #14202f;
  --border: #34465b;
  --accent: #7ce5bd;
  --ink: #e9f1f7;
  --muted: #a0b0c2;
  --danger: #f49caa;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; min-height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink); background: var(--bg); overflow-x: hidden;
}
button, input { font: inherit; }
button, .action {
  display: inline-block; min-height: 44px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 12px;
  color: var(--ink); background: #26394d; cursor: pointer;
}
button:hover:not(:disabled), .action:hover { filter: brightness(1.1); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
a { text-decoration: none; color: inherit; }
.hidden { display: none !important; }

.shell {
  margin: 0 auto; padding: 10px; max-width: 1440px;
  height: 100vh; height: 100dvh;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 8px;
}
.header {
  min-width: 0; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 1px 4px 5px; border-bottom: 1px solid #273747;
}
.eyebrow, .section-label { font-size: 9px; font-weight: 800; letter-spacing: 1.5px; color: var(--accent); }
h1 { font-size: 21px; letter-spacing: 4px; line-height: 1.1; margin: 3px 0; color: #d7eee7; }
h2 { margin: 6px 0 10px; font-size: 21px; line-height: 1.2; }
.subtitle, .hint { color: var(--muted); margin: 0; }
.subtitle { font-size: 11px; }
.hint { font-size: 12px; line-height: 1.5; }
.connection {
  flex-shrink: 0; display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); background: #152232;
  border-radius: 20px; padding: 7px 10px; white-space: nowrap; font-size: 11px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: #db9c72; }
.dot.online { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.layout { min-height: 0; min-width: 0; display: grid; align-items: stretch; }
.layout:not(.room-active) { place-items: center; }
.panel, .roomIntro, .roomActions {
  border: 1px solid var(--border); border-radius: 18px;
  background: linear-gradient(135deg, #1b2a39, #152130);
  box-shadow: 0 8px 32px #0002;
}
.lobby {
  width: min(100%, 520px); max-height: 100%; overflow: auto;
  padding: clamp(15px, 2.5vw, 24px);
}
.lobby h2 { font-size: 24px; }
.lobby label, .roomActions label {
  display: block; margin: 12px 0 5px; font-size: 12px; color: #b9c7d7;
}
input {
  min-width: 0; width: 100%; min-height: 44px; padding: 9px 11px;
  border: 1px solid #3a4e63; border-radius: 10px;
  color: #fff; background: #0e1927;
}
.action { display: block; width: 100%; margin-top: 9px; text-align: center; }
.primary { background: var(--accent); border-color: transparent; color: #10251f; font-weight: 800; }
.secondary { background: #263b47; border-color: #568174; }
.subtle { background: transparent; }
.divider { display: flex; align-items: center; gap: 12px; margin: 16px 0 8px; color: #8195aa; font-size: 10px; letter-spacing: 1.5px; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--border); flex: 1; }
.join, .share { display: flex; gap: 6px; }
.join button, .share button { flex-shrink: 0; }
.status { min-height: 20px; margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.status.error { color: var(--danger); }

/* В комнате поле получает основную площадь — как в исходной игре. */
.room {
  min-height: 0; min-width: 0;
  display: grid; gap: 8px;
  grid-template-columns: clamp(235px, 26vw, 340px) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "intro map" "actions map";
}
.roomIntro { grid-area: intro; min-width: 0; padding: 14px; }
.roomActions { grid-area: actions; min-height: 0; min-width: 0; padding: 13px 14px; overflow-y: auto; }
.roomTitle { display: flex; align-items: flex-start; justify-content: space-between; gap: 7px; margin-top: 9px; }
.roomTitle h2 { font-size: 17px; margin: 0 0 4px; overflow-wrap: anywhere; }
.roomTitle h2 span { color: var(--accent); }
.pill {
  flex-shrink: 0; padding: 5px 7px; border: 1px solid #517565;
  border-radius: 9px; color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: .5px;
}
.players { display: grid; grid-template-columns: 1fr; gap: 6px; margin: 12px 0 0; }
.player {
  min-width: 0; overflow-wrap: anywhere; padding: 9px 10px;
  background: var(--panel2); border: 1px solid #324357;
  border-left: 3px solid var(--accent); border-radius: 10px;
}
.player:nth-child(2) { border-left-color: #f4a477; }
.player small { display: block; font-size: 9px; color: var(--muted); letter-spacing: 1px; }
.share { margin-bottom: 10px; }
.share input { font-size: 11px; }
.share button { padding: 8px; font-size: 11px; }
.roomActions label { margin: 0 0 6px; }
.activity { min-height: 30px; margin-top: 10px; font-size: 12px; color: var(--accent); overflow-wrap: anywhere; }
.mapWrap {
  grid-area: map; position: relative; display: grid; place-items: center;
  min-height: 0; min-width: 0; height: 100%; overflow: hidden;
  border: 1px solid #3b5065; border-radius: 18px;
  background: radial-gradient(ellipse at 48% 40%, #233547, #152230 75%);
  box-shadow: inset 0 0 60px #07131b44;
}
.mapWrap canvas { display: block; width: 100%; height: 100%; object-fit: contain; }
.mapCaption {
  position: absolute; inset: auto 0 0; padding: 8px;
  background: #101c2cdb; color: #bbccda; font-size: 11px; text-align: center;
}
footer { min-width: 0; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 10px; padding: 1px 4px; color: #8195aa; font-size: 10px; }

@media (max-width: 700px) and (orientation: portrait) {
  .shell { height: auto; min-height: 100dvh; display: flex; flex-direction: column; padding: 8px; }
  .header { padding: 2px 2px 6px; }
  .layout { display: block; flex: 1; }
  .lobby { max-height: none; width: 100%; }
  .room { height: auto; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; grid-template-areas: "intro" "map" "actions"; }
  .roomIntro, .roomActions { padding: 12px; }
  .roomIntro .players { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .mapWrap { height: min(58dvh, 650px); min-height: 280px; }
  .mapWrap canvas { width: 100%; height: 100%; }
  .roomActions { overflow: visible; }
  .subtitle { display: none; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .shell { padding: 7px; gap: 5px; }
  .header { padding-bottom: 3px; }
  .eyebrow, .subtitle { display: none; }
  h1 { font-size: 17px; margin: 0; }
  .room { grid-template-columns: clamp(205px, 28vw, 260px) minmax(0, 1fr); gap: 6px; }
  .roomIntro, .roomActions { padding: 9px; border-radius: 12px; }
  .roomTitle { margin-top: 5px; }
  .roomTitle h2 { font-size: 14px; }
  .players { margin-top: 5px; gap: 4px; }
  .player { padding: 4px 7px; font-size: 12px; }
  .player small { font-size: 8px; }
  .roomActions .action { margin-top: 5px; padding: 6px; min-height: 36px; }
  .share { margin-bottom: 6px; }
  .share input, .share button { min-height: 36px; padding: 6px; }
  .activity { margin-top: 5px; min-height: 0; font-size: 10px; }
  .mapWrap { border-radius: 12px; }
  footer { font-size: 9px; }
}
@media (max-width: 380px) {
  .roomTitle { flex-wrap: wrap; }
  .share { flex-wrap: wrap; }
  .share button { width: 100%; }
}

/* Сетевые ходы: интерфейс повторяет логику управления исходной игры. */
.lobbyOptions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
select { display: block; background: #0e1927; border: 1px solid #3a4e63; border-radius: 10px; color: white; padding: 9px 7px; width: 100%; min-height: 40px; font: inherit; }
.turnInfo { border-top: 1px solid #334257; padding-top: 8px; margin-top: 8px; font-size: 12px; font-weight: 700; color: #a9d9cc; }
.player.active { background: #273c45; border-color: #7ce5bd; }
.player:nth-child(2).active { border-color: #f4a477; }
.player.offline { opacity: .5; }
.player b { display: block; font-size: 18px; margin-top: 3px; }
.player small { text-transform: uppercase; }
.activity { margin: 5px 0 10px; min-height: 25px; line-height: 1.35; }
.activity.error { color: #ff8c9d; }
.moveControls { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 6px; }
.moveControls button { padding: 7px 9px; }
#undoBtn { font-size: 22px; }
#commitBtn { font-size: 13px; font-weight: 700; }
.zoomControls { display: flex; gap: 6px; margin-top: 6px; }
.zoomControls button { flex: 1; min-height: 36px; padding: 5px; }
#leaveBtn { margin-top: 6px; font-size: 11px; padding: 6px; min-height: 33px; }
#shareArea { margin-bottom: 5px; }
#autoBtn { font-size: 12px; }
.mapWrap canvas { object-fit: initial; touch-action: none; }
.mapWrap { user-select: none; }
.mapCaption { pointer-events: none; }
@media (max-width: 700px) and (orientation:portrait) {
  .shell { height: 100dvh; min-height: 0; }
  .layout.room-active { min-height: 0; display: block; }
  .room { height: 100%; display:grid; grid-template-rows: auto minmax(0,1fr) auto; grid-template-areas:'intro' 'map' 'actions'; }
  .roomIntro,.roomActions { padding: 7px 9px; }
  .roomTitle h2 { font-size: 14px; margin: 0; }
  .roomTitle { margin-top: 4px; }
  .section-label { font-size: 9px; }
  .players { margin: 5px 0 0 !important; }
  .player { padding: 5px 7px; font-size: 11px; }
  .player b { font-size: 14px; }
  .turnInfo { padding-top: 5px; margin-top: 5px; }
  .mapWrap { height: auto; min-height: 0; }
  .roomActions .activity { margin: 2px 0 5px; min-height: 0; max-height: 42px; overflow: auto; }
  .roomActions .action { margin-top: 5px; padding: 6px; min-height: 36px; }
  .moveControls button { min-height: 40px; }
  #shareArea { display:none; }
  .roomActions { max-height: 170px; overflow:auto; }
  footer { display:none; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .turnInfo { margin-top: 5px; padding-top: 4px; font-size: 10px; }
  .player b { font-size: 13px; }
  .roomActions .activity { max-height: 36px; overflow: auto; }
  #shareArea { display:none; }
  .roomActions .zoomControls button { min-height: 27px; }
}
@media (orientation:landscape) and (max-height:520px) {
  .roomIntro .players { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .roomIntro .player { overflow:hidden; padding:4px 5px; }
  .roomIntro .player div { overflow:hidden; white-space:nowrap; text-overflow:ellipsis; font-size:10px; }
  .roomIntro .player small { white-space:nowrap; font-size:7px; letter-spacing:0; }
  .roomIntro .player b { font-size:12px; margin-top:1px; }
  .roomActions .activity { margin:2px 0 6px; min-height:0; max-height:34px; }
  .roomActions .moveControls button { min-height:36px; }
  .roomActions #leaveBtn { min-height:28px; }
}

@media (max-width:700px) and (orientation:portrait) { .room.waiting #shareArea { display:block; } }
@media (orientation:landscape) and (max-height:520px) { .room.waiting #shareArea { display:block; } }

/* 0.3.0: игровое поле приоритетно; результаты партии и реванш. */
#matchBtn { margin-top: 12px; }
#matchType { color: #93aabe; font-weight: 600; letter-spacing: .3px; }
.resultBrief { margin: 2px 0 8px; color: var(--accent); font-weight: 750; }
#endActions { border-top: 1px solid var(--border); margin-top: 9px; padding-top: 8px; }
#endActions .action { margin-top: 5px; }
.resultOverlay { position: fixed; inset: 0; z-index: 50; background: #050b13ce; backdrop-filter: blur(8px); display: grid; place-items: center; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
.resultCard { width: min(100%, 430px); max-height: 94dvh; overflow: auto; background: #1a2635; border: 1px solid #466076; border-radius: 21px; padding: clamp(15px,4vw,24px); box-shadow: 0 22px 75px #0009; }
.resultCard h2 { font-size: 26px; margin: 8px 0 7px; color: #d7eee7; }
.resultCard .action { width: 100%; margin-top: 8px; }
.resultCard .hint { margin: 8px 0 12px; }
.resultStats { display: grid; gap: 7px; margin: 13px 0; }
.resultRow { display: flex; gap: 10px; justify-content: space-between; align-items: center; border: 1px solid #334a5f; border-left: 4px solid var(--c); border-radius: 11px; background: #101d2b; padding: 10px 12px; }
.resultRow span { min-width: 0; overflow-wrap: anywhere; }
.resultRow b { white-space: nowrap; }
.roomIntro .section-label { overflow-wrap: anywhere; }
.roomIntro .player { min-width: 0; }
.roomIntro .player > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room { min-width: 0; }
@media (orientation: portrait) {
 .shell { height: 100dvh; min-height: 0; max-width: none; display: grid; grid-template-rows: auto minmax(0,1fr); padding: max(6px,env(safe-area-inset-top)) 7px max(6px,env(safe-area-inset-bottom)); gap: 5px; }
 .header { padding: 1px 3px 3px; }
 .eyebrow,.subtitle { display: none; }
 h1 { font-size: 17px; margin: 0; }
 .layout.room-active { min-height: 0; display: block; }
 .room { display: grid; height: 100%; grid-template-columns: minmax(0,1fr); grid-template-rows: auto minmax(0,1fr) auto; grid-template-areas: 'intro' 'map' 'actions'; gap: 5px; }
 .roomIntro { padding: 6px 8px; border-radius: 12px; }
 .roomIntro .players { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 5px; margin: 5px 0 0 !important; }
 .roomTitle { margin-top: 3px; }
 .roomTitle h2 { font-size: 13px; margin: 0; }
 .roomIntro .player { padding: 4px 7px; font-size: 11px; }
 .roomIntro .player small { font-size: 8px; }
 .roomIntro .player b { font-size: 13px; margin-top: 1px; }
 .turnInfo { margin-top: 4px; padding-top: 3px; font-size: 11px; }
 .mapWrap { height: auto; min-height: 0; border-radius: 13px; }
 .roomActions { max-height: 195px; padding: 5px 8px; border-radius: 12px; overflow-y: auto; }
 .roomActions .activity { margin: 1px 0 5px; min-height: 16px; max-height: 32px; overflow: auto; font-size: 11px; }
 .moveControls button { min-height: 39px; }
 .zoomControls { margin-top: 4px; }
 .zoomControls button { min-height: 32px; }
 .roomActions #leaveBtn { min-height: 29px; margin-top: 4px; }
 #endActions { margin-top: 5px; padding-top: 4px; }
 #endActions .action { min-height: 32px; }
 #shareArea { display: none; }
 .room.waiting #shareArea { display: block; }
 .room.waiting .roomActions { max-height: 250px; }
 footer { display: none; }
}
@media (orientation:landscape) and (max-height:520px) {
 #matchType { display: none; }
 .roomIntro .players { grid-template-columns: repeat(2,minmax(0,1fr)); }
 .roomActions { padding: 7px; }
 .roomActions .activity { max-height: 34px; }
 .roomActions #endActions .action { min-height: 32px; }
 .roomActions #leaveBtn { min-height: 28px; }
}
