/* Hedgewars web lobby: modelled on QTfrontend/res/css/qt.css */
:root {
  --bg: #141250;
  --panel: rgba(13, 5, 68, 0.7);
  --panel-solid: #0d0544;
  --gold: #ffcc00;
  --gold-hi: #ffff00;
  --text: #ffcc00;
  --text-soft: #e8d690;
  --link: #c8c8ff;
  --btn: rgba(18, 42, 5, 0.7);
  --btn-hover: rgba(30, 70, 8, 0.85);
  --danger: #ff5050;
  --chat-user: #ffcc00;
  --chat-nick: #ffec20;
  --chat-friend: #b0ff08;
  --chat-server: #c8c8ff;
  --chat-action: #ff80ff;
  --chat-join: #b0b0ff;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg) url(/res/Background.png) bottom center repeat-x;
  color: var(--text);
  font: bold 13px/1.35 "DejaVu Sans", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}
a { color: var(--link); }
[hidden] { display: none !important; }

.page { height: 100vh; display: flex; flex-direction: column; padding: 10px 16px 16px; gap: 10px; }

/* --- controls --- */
button, .btn {
  font: inherit; color: var(--text); cursor: pointer;
  background: var(--btn); border: 3px solid var(--gold); border-radius: 8px;
  padding: 5px 12px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
button:hover:not(:disabled), .btn:hover { border-color: var(--gold-hi); background: var(--btn-hover); }
button:disabled { color: #a0a0a0; border-color: #a0a0a0; cursor: default; }
button.primary { background: rgba(40, 90, 10, 0.9); }
button.danger { border-color: var(--danger); color: var(--danger); }
button.small { padding: 1px 8px; border-width: 2px; font-size: 12px; }
button.active { background: #2f6b0c; color: #fff6c0; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 3px solid var(--gold); border-radius: var(--radius); padding: 4px 8px; min-width: 0;
}
select { border-radius: 8px; }
input:hover, select:hover { border-color: var(--gold-hi); }
input:focus-visible, select:focus-visible, button:focus-visible, .btn:focus-visible { outline: 2px solid #fff6c0; outline-offset: 1px; }
input[type=range] { padding: 0; border: none; background: transparent; accent-color: var(--gold); }
input:disabled, select:disabled { color: #a0a0a0; border-color: #6b6b6b; }
label { display: flex; flex-direction: column; gap: 3px; }
.spacer { flex: 1; }
.buttons { display: flex; gap: 8px; align-items: center; }
.status-line { min-height: 1.4em; margin: 0; color: var(--text-soft); }
.tag { border: 2px solid var(--gold); border-radius: 6px; padding: 1px 6px; font-size: 12px; }
.count { color: var(--text-soft); font-weight: normal; }

.group {
  background: var(--panel); border: 3px solid var(--gold); border-radius: 16px;
  padding: 8px 10px; min-height: 0; min-width: 0;
}
.group h2, .group h3 { margin: 0 0 6px; font-size: 14px; display: flex; align-items: center; gap: 8px; }

/* --- connect --- */
#page-connect { align-items: center; justify-content: center; gap: 24px; }
.title-art { max-width: min(560px, 90vw); }
.connect-box { width: min(420px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 16px; }

/* --- top bar --- */
.topbar { display: flex; align-items: center; gap: 10px; }
.brand { font-size: 17px; }
.me { color: var(--text-soft); }

/* --- lobby --- */
.lobby-grid {
  flex: 1; min-height: 0; display: grid; gap: 10px;
  grid-template-columns: 1fr 220px;
  grid-template-rows: minmax(0, 1.1fr) minmax(0, 1fr);
  grid-template-areas: "rooms players" "chat players";
}
.rooms { grid-area: rooms; display: flex; flex-direction: column; gap: 6px; }
.lobby-grid .chat-area { grid-area: chat; }
.lobby-grid .players { grid-area: players; }
.rooms-toolbar { display: flex; gap: 8px; align-items: center; }
.table-wrap { flex: 1; overflow: auto; border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th { position: sticky; top: 0; background: var(--panel-solid); text-align: left; padding: 4px 6px; border-bottom: 2px solid var(--gold); white-space: nowrap; }
td { padding: 3px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: rgba(255, 204, 0, 0.12); }
tbody tr.selected { background: var(--gold); color: #00351d; }
tbody tr.ingame td { color: #a8a8a8; }
tbody tr.selected td { color: #00351d; }
td.flags img { width: 16px; height: 16px; vertical-align: middle; }
.empty { color: var(--text-soft); text-align: center; font-weight: normal; }

.chat-area { display: flex; flex-direction: column; gap: 6px; }
.chat-log { flex: 1; overflow-y: auto; font-weight: normal; word-wrap: break-word; padding-right: 4px; }
.chat-log p { margin: 1px 0; }
.chat-log .nick { color: var(--chat-nick); font-weight: bold; }
.chat-log .msg-user { color: var(--chat-user); }
.chat-log .msg-me { color: #fff6c0; }
.chat-log .msg-action { color: var(--chat-action); }
.chat-log .msg-server { color: var(--chat-server); }
.chat-log .msg-join { color: var(--chat-join); }
.chat-log .msg-warn { color: #ffa040; }
.chat-log .msg-err { color: var(--danger); }
.chat-log .motd { border-bottom: 2px solid rgba(255, 204, 0, .4); margin-bottom: 6px; padding-bottom: 4px; }
.chat-log .motd * { max-width: 100%; }
.chat-log .ts { color: #8888aa; margin-right: 4px; }
.chat-input input { width: 100%; }

.players { display: flex; flex-direction: column; }
.player-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.player-list li { display: flex; align-items: center; gap: 5px; padding: 2px 4px; border-radius: 6px; }
.player-list li:hover { background: rgba(255, 204, 0, 0.12); }
.player-list li.me { color: #fff6c0; }
.player-list .ico { width: 16px; text-align: center; font-size: 11px; }
.player-list .badge { font-size: 10px; border: 1px solid currentColor; border-radius: 4px; padding: 0 3px; opacity: .8; }

/* --- room --- */
.room-grid {
  flex: 1; min-height: 0; display: grid; gap: 10px;
  grid-template-columns: minmax(320px, 1.1fr) minmax(280px, 1fr) 200px;
  grid-template-rows: minmax(0, 1.25fr) minmax(0, 1fr);
  grid-template-areas: "cfg teams teams" "cfg chat players";
}
.cfg { grid-area: cfg; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.room-grid .teams { grid-area: teams; overflow-y: auto; }
.room-grid .chat-area { grid-area: chat; }
.room-grid .players { grid-area: players; }
.map-block { display: flex; gap: 10px; flex-wrap: wrap; }
.map-preview {
  position: relative; width: 256px; height: 128px; flex: none; border: 3px solid var(--gold); border-radius: 10px;
  background: linear-gradient(#1a3a8a, #0d0544); overflow: hidden; display: grid; place-items: center;
}
.map-preview img { max-width: 100%; max-height: 100%; image-rendering: auto; }
.map-preview .hogs-limit { position: absolute; right: 6px; bottom: 3px; font-size: 11px; color: #fff; text-shadow: 0 0 3px #000; }
.map-controls { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 6px; }
.scheme-details summary { cursor: pointer; }
#scheme-view { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 10px; font-weight: normal; padding-top: 6px; }
#scheme-view .on { color: #b0ff08; }
#scheme-view .off { color: #8888aa; }

.team-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.team-list li {
  display: flex; align-items: center; gap: 8px; padding: 4px 8px; border: 2px solid var(--gold);
  border-radius: 8px; background: var(--panel-solid);
}
.team-list li .team-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-list li .owner { color: var(--text-soft); font-weight: normal; font-size: 12px; }
.team-list .flag { width: 22px; height: 15px; }
.team-list .color-btn { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff6; padding: 0; }
.team-list .hh-btn { min-width: 46px; justify-content: center; }
.team-list .hh-btn img { width: 16px; }
.team-list.local li { border-style: dashed; }
.team-list.local li.in-game { opacity: .5; }
.team-list .bot { font-size: 11px; color: var(--text-soft); }

/* --- game --- */
#game-layer { position: fixed; inset: 0; background: #000; z-index: 10; }
#game-layer canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; outline: none; }
.game-status {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--gold); font-size: 18px;
  pointer-events: none; text-shadow: 0 0 6px #000;
}
.game-quit { position: absolute; top: 8px; right: 8px; z-index: 2; opacity: .5; padding: 2px 8px; }
.game-quit:hover { opacity: 1; }

/* --- dialog --- */
dialog {
  color: var(--text); background: var(--bg); border: 3px solid var(--gold); border-radius: 16px; padding: 16px;
  max-width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgba(0, 0, 20, 0.7); }
dialog h2 { margin-top: 0; }
.team-editor .te-grid { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; }
.team-editor section { display: flex; flex-direction: column; gap: 6px; }
.with-preview { display: flex; gap: 6px; align-items: center; }
.with-preview select { flex: 1; }
.with-preview img { max-height: 32px; max-width: 48px; }
.hog-list { display: flex; flex-direction: column; gap: 4px; }
.hog-row { display: grid; grid-template-columns: 32px 120px 1fr; gap: 6px; align-items: center; }
.hog-row img { width: 32px; height: 32px; object-fit: cover; object-position: 0 0; }
.te-error { color: var(--danger); }
.dialog-body { display: flex; flex-direction: column; gap: 10px; min-width: min(360px, 80vw); }

.select-row { display: flex; gap: 6px; align-items: center; }
.select-row select { flex: 1; min-width: 0; }

/* scheme / weapon / settings editors (PageScheme, PageSelectWeapon, PageOptions) */
dialog:has(form.wide) { max-width: min(1040px, calc(100vw - 32px)); }
form.wide { display: flex; flex-direction: column; gap: 8px; width: min(1000px, calc(100vw - 72px)); }
.ed-top { display: flex; gap: 10px; flex-wrap: wrap; }
.ed-top label { min-width: 200px; }
.ed-top .grow { flex: 1; }
.ed-note { margin: 0; color: var(--text-soft); font-weight: normal; }
.se-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 10px; }
.toggles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.toggle {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
  font-size: 11px; padding: 4px 2px; border: 2px solid transparent; border-radius: 8px; cursor: pointer; opacity: .55;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle img { width: 43px; height: 43px; }
.toggle:has(input:checked) { opacity: 1; border-color: var(--gold); background: rgba(40, 90, 10, 0.6); }
.toggle:has(input:focus-visible) { outline: 2px solid #fff6c0; }
.toggle:has(input:disabled) { cursor: default; }
.numbers { display: flex; flex-direction: column; gap: 4px; }
.num { display: grid; grid-template-columns: 32px 1fr minmax(0, 190px); align-items: center; gap: 6px; }
.num img { width: 32px; height: 32px; }
.num > span:nth-child(2) { font-size: 12px; }
.spin { display: flex; align-items: center; gap: 6px; }
.spin input { width: 84px; }
.spin output { color: var(--text-soft); font-weight: normal; font-size: 12px; white-space: nowrap; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border-radius: 8px 8px 0 0; border-bottom-width: 0; opacity: .7; }
.tabs button[aria-selected=true] { opacity: 1; background: rgba(40, 90, 10, 0.9); }
.we-hint { margin: 0; color: var(--text-soft); font-weight: normal; font-size: 12px; }
.weapon-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 3px;
  max-height: 56vh; overflow-y: auto; padding: 4px; border: 3px solid var(--gold); border-radius: 0 10px 10px 10px;
}
.weapon { padding: 1px 4px; border-width: 1px; border-color: rgba(255, 204, 0, .3); border-radius: 6px; background: transparent; gap: 4px; }
.weapon:disabled { border-color: transparent; }
.ammo-icon { flex: none; width: 32px; height: 32px; background: url(/Data/Graphics/AmmoMenu/Ammos_base.png) no-repeat; }
.weapon:disabled .ammo-icon { filter: grayscale(1) brightness(.8); }
.pips { position: relative; flex: 1; height: 36px; }
.pips img { position: absolute; width: 25px; height: 35px; }
.pips img.inf { width: 100px; height: 32px; left: 0; top: 2px; }

.icon-btn { padding: 2px 4px; border-width: 2px; flex: none; }
.icon-btn img { width: 22px; height: 22px; display: block; }
.btn-ico { width: 18px; height: 18px; }

/* --- Edit game preferences (PageOptions) --- */
.prefs-main { font-size: 15px; padding: 8px 18px; }
.prefs-main img { width: 32px; height: 30px; }
#page-prefs { overflow: hidden; }
.pref-tabs button img { width: 22px; height: 22px; }
.pref-body { flex: 1; min-height: 0; overflow-y: auto; border: 3px solid var(--gold); border-radius: 0 16px 16px 16px; padding: 12px; background: var(--panel); }
.pref-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); gap: 12px; align-content: start; }
.opt-group { display: flex; flex-direction: column; gap: 8px; }
.opt-group h3 img { width: 28px; height: 28px; }
.opt-group fieldset { border: 2px solid rgba(255, 204, 0, .4); border-radius: 8px; display: flex; flex-direction: column; gap: 6px; margin: 0; }
.opt-group legend { padding: 0 4px; }
.pref-note { margin: 0; color: var(--text-soft); font-weight: normal; grid-column: 1 / -1; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: normal; flex-wrap: wrap; }
label.check input[type=number] { width: 84px; }
input[type=checkbox], input[type=radio] { accent-color: var(--gold); width: 18px; height: 18px; }
.check-row { display: flex; gap: 14px; flex-wrap: wrap; }
.range-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.range-row input[type=range] { flex: 1; min-width: 120px; }
.range-row input[type=number] { width: 90px; }
.range-row output { color: var(--text-soft); font-weight: normal; min-width: 4em; }
.pref-panel[data-panel=controls] { grid-template-columns: minmax(0, 720px); }
.binds h4 { margin: 12px 0 2px; border-bottom: 2px solid rgba(255, 204, 0, .4); }
.bind-desc { margin: 6px 0 2px; color: var(--text-soft); font-weight: normal; font-size: 12px; }
.bind-row { display: grid; grid-template-columns: 1fr minmax(120px, 180px) auto; gap: 8px; align-items: center; padding: 1px 0; font-weight: normal; }
.bind-key { justify-content: center; padding: 2px 8px; border-width: 2px; font-weight: bold; }
.bind-key.changed { color: #b0ff08; }
.bind-key.capturing { background: var(--gold); color: #00351d; }

/* stats */
.stats-list { font-weight: normal; max-height: 50vh; overflow: auto; }
.stats-list li { margin: 2px 0; }

#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 20; }
.toast { background: var(--panel-solid); border: 3px solid var(--gold); border-radius: 10px; padding: 6px 14px; }
.toast.error { border-color: var(--danger); }

@media (max-width: 1150px) {
  .room-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1.3fr) minmax(0, 1fr);
    grid-template-areas: "cfg teams" "chat players";
  }
  .lobby-grid { grid-template-columns: 1fr 180px; }
  .map-preview { width: 100%; max-width: 256px; aspect-ratio: 2 / 1; height: auto; }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .page { height: auto; min-height: 100vh; padding: 10px 16px; }
  .lobby-grid, .room-grid { grid-template-columns: 1fr; grid-template-rows: none; grid-template-areas: none; }
  .lobby-grid > *, .room-grid > * { grid-area: auto !important; min-height: 200px; }
  .team-editor .te-grid, .se-grid { grid-template-columns: 1fr; }
  .num { grid-template-columns: 32px 1fr; }
  .num > :last-child { grid-column: 1 / -1; }
  td:nth-child(n+6), th:nth-child(n+6) { display: none; }
}
