*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg:       #1a1a1a;
  --surface:  #222222;
  --surface2: #2c2c2c;
  --panel-bg: rgba(26,26,26,0.97);
  --border:   rgba(255,255,255,0.11);
  --border2:  rgba(255,255,255,0.05);
  --p1:       #e05040;
  --p2:       #4080e0;
  --text:     #dde0da;
  --dim:      #7a7f74;
  --accent:   #74a34e;
  --font:     'Courier New', Courier, monospace;
  --header-h: 2.75rem;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

/* App shell */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;    /* fallback */
  height: 100dvh;   /* dynamic — adjusts as browser chrome shows/hides */
}

/* Header */

#app-header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  z-index: 10;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.logo-box {
  background: linear-gradient(90deg, var(--p1) 50%, var(--p2) 50%);
  color: rgba(255,255,255,0.92);
  font-size: 0.9rem;
  font-weight: bold;
  letter-spacing: 0.2em;
  padding: 0.25em 0.625em;
  border-radius: 4px;
}
.logo-version { font-size: 0.65rem; opacity: 0.45; letter-spacing: 0.08em; color: var(--dim); }

#header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--dim);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
}
#discord-link {
  color: var(--dim);
  text-decoration: none;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  opacity: 0.7;
  transition: opacity 0.15s;
}
#discord-link:hover { opacity: 1; color: #7289da; }

/* Main area */

#app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* Tab bar & panes */

#tab-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.375rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 0.625rem;
  min-height: 2.375rem;
}

#tab-strip {
  display: flex;
  flex: 1;
  gap: 0.2rem;
  align-items: flex-end;
  min-width: 0;
  overflow: hidden;
}

.app-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 4px 4px 0 0;
  margin-bottom: -1px;
  padding: 0 0.875em;
  height: 2em;
  font-size: 0.62rem;
  letter-spacing: 0.13em;
  color: var(--dim);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.1s, color 0.1s;
}
.app-tab:not(:disabled):hover { background: var(--surface2); color: var(--text); }
.app-tab.active {
  background: var(--panel-bg);
  color: var(--text);
  border-color: var(--border);
  border-bottom-color: var(--panel-bg);
}

/* Lobby is the home anchor — slightly taller, accent-tinted when inactive */
.app-tab-home {
  height: 2.25rem;
  color: var(--accent);
  opacity: 0.65;
  letter-spacing: 0.12em;
}
.app-tab-home:not(:disabled):hover { opacity: 1; background: var(--surface2); color: var(--accent); }
.app-tab-home.active { color: var(--accent); opacity: 1; border-bottom-color: var(--panel-bg); }

/* Visual separator before first game tab */
.app-tab[data-tab="matchmaking"] + .app-tab {
  margin-left: 0.625rem;
  border-left: 1px solid var(--border);
}

/* Game tab close button */
.app-tab-close {
  margin-left: 0.375em;
  opacity: 0.4;
  font-size: 0.8rem;
  line-height: 1;
  vertical-align: middle;
}
.app-tab:hover .app-tab-close { opacity: 0.8; }

#tab-select {
  background: var(--bg);
  border: 1px solid var(--border2);
  color: var(--dim);
  font-family: var(--font);
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  padding: 0.25em 0.5em;
  border-radius: 3px;
  cursor: pointer;
  flex-shrink: 0;
  max-width: 10rem;
}

#app-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
}

#tab-content {
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.app-pane {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* matchmaking pane */
#pane-matchmaking {
  overflow-y: auto;
}

#mm-controls {
  padding: 1.5rem 1.75rem;
  flex-shrink: 0;
  max-width: 32.5rem;
  width: 100%;
  align-self: center;
}

#mm-mode-row {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.mm-mode-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 5px;
  padding: 0.625em 0;
  font-size: 0.65rem;
  letter-spacing: 0.16em;
  color: var(--dim);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.mm-mode-btn:hover  { color: var(--text); border-color: var(--border); }
.mm-mode-btn.active { background: rgba(255,255,255,0.07); color: var(--accent); border-color: var(--accent); }

.mm-desc {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--dim);
  text-align: center;
  padding: 0.75rem 0 0;
  flex-shrink: 0;
}

#lobby-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.625rem;
  padding: 1.25rem 0;
  border-top: 1px solid var(--border2);
  flex-shrink: 0;
  margin-top: 1rem;
}

#open-rooms-section {
  padding: 1.25rem 1.75rem 0;
  max-width: 62rem;
  width: 100%;
  align-self: center;
}

#open-rooms-list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1.25rem;
}

.open-room-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.875rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  gap: 1rem;
}

.open-room-label {
  font-size: 0.78rem;
  color: var(--text);
  letter-spacing: 0.02em;
}

.open-room-join {
  font-size: 0.72rem;
  padding: 0.3em 0.875em;
  flex-shrink: 0;
}

#lobby-main {
  padding: 0 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  max-width: 62rem;
  width: 100%;
  align-self: center;
}

#support-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 0;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border2);
}

#discord-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  height: 36px;
  box-sizing: border-box;
  background-color: #5865f2;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  padding: 0 1rem;
  border-radius: 4px;
  white-space: nowrap;
}

#discord-btn:hover {
  background-color: #4752c4;
}

#support-buttons-sep {
  width: 100%;
  border: none;
  border-top: 1px solid var(--border2);
  margin: 0;
}

#support-donate-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}


#bmc-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 36px;
  box-sizing: border-box;
  background-color: #74a34e;
  color: #fff;
  font-family: 'Cookie', cursive;
  font-size: 1.1rem;
  text-decoration: none;
  padding: 0 0.9rem;
  border-radius: 4px;
  white-space: nowrap;
}

#bmc-btn img {
  height: 18px;
  width: auto;
}

#bmc-btn:hover {
  background-color: #5f8a3b;
}

#lobby-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2.5rem;
  align-items: start;
}

#lobby-info-col .info-body {
  padding: 0;
  font-size: 0.72rem;
}

#lobby-info-col .info-body p { margin-bottom: 0.55rem; }
#lobby-info-col .info-title  { font-size: 0.68rem; margin-bottom: 0.875rem !important; }
#lobby-info-col .info-h      { font-size: 0.62rem; }

.lobby-section-label {
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  color: var(--dim);
  margin-bottom: 1rem;
}

.news-entry {
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border2);
}
.news-entry:last-child { border-bottom: none; }

.news-meta {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  color: var(--dim);
  margin-bottom: 0.25rem;
}

.news-title {
  font-size: 0.88rem;
  font-weight: bold;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 0.375rem;
}

.news-body {
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  color: var(--text);
  line-height: 1.6;
  opacity: 0.8;
}

/* game pane */
#pane-game {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

#gp-main {
  flex: 1;
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gp-centered {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 1.5rem;
}

/* Panel toggle button */
.panel-toggle-btn {
  background: transparent;
  border: none;
  color: var(--dim);
  padding: 0.25em 0.5em;
  font-size: 1rem;
  letter-spacing: 0;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  border-radius: 3px;
  transition: color 0.12s;
}
.panel-toggle-btn:hover { color: var(--text); opacity: 1; }

/* room chat */
#room-chat {
  width: min(16.25rem, 30vw);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border2);
  background: var(--surface);
  transition: width 0.18s ease;
  overflow: hidden;
}
#room-chat.collapsed { width: 26px; }
#room-chat.collapsed .chat-room-tab,
#room-chat.collapsed #chat-messages-area,
#room-chat.collapsed #room-chat-form { display: none !important; }
#room-chat.collapsed #chat-rooms-bar { justify-content: center; }

#chat-rooms-bar {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border2);
  overflow-x: auto;
  scrollbar-width: none;
}
#chat-rooms-bar::-webkit-scrollbar { display: none; }

.chat-room-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 0.4375em 0.75em;
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  color: var(--dim);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  position: relative;
}
.chat-room-tab:not(:disabled):hover { color: var(--text); opacity: 1; }
.chat-room-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.chat-tab-badge {
  display: inline-block;
  margin-left: 0.25em;
  background: var(--accent);
  color: var(--bg);
  border-radius: 8px;
  font-size: 0.5rem;
  padding: 1px 4px;
  font-weight: bold;
  letter-spacing: 0;
  vertical-align: middle;
}

#chat-messages-area {
  flex: 1;
  min-height: 0;
  position: relative;
}

.chat-room-msgs {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 0.5rem 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

#room-chat-form {
  display: flex;
  gap: 0.25rem;
  padding: 0.375rem;
  border-top: 1px solid var(--border2);
  flex-shrink: 0;
}
#room-chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.375em 0.5em;
  font-size: 0.72rem;
}
#room-chat-input.chat-slow {
  color: var(--text-muted, #888);
  border-color: #a05050;
}
.chat-del-btn {
  margin-left: auto; opacity: 0;
  background: none; border: none; color: #d77; cursor: pointer;
  font-size: 0.65rem; padding: 0 3px; line-height: 1; flex-shrink: 0;
}
.chat-msg:hover .chat-del-btn { opacity: 1; }
#room-chat-form button {
  padding: 0.375em 0.625em;
  font-size: 0.82rem;
  background: transparent;
  color: var(--accent);
  border-color: var(--border);
  min-width: 2rem;
}

.subtitle { color: var(--dim); font-size: 0.78rem; margin-bottom: 1.75rem; letter-spacing: 0.1em; }
.hint     { color: var(--dim); font-size: 0.72rem; margin-top: 0.75rem; }
.join-row { display: flex; gap: 0.5rem; }

.side-tabs-row {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border2);
}

/* base input, individual inputs override sizing/letter-spacing */
input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.74rem;
  padding: 0.4375em 0.625em;
  border-radius: 4px;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus { border-color: var(--accent); }

#room-code-input {
  font-size: 1.2rem;
  letter-spacing: 0.3em;
  padding: 0.5em 0.75em;
  width: 5.5rem;
  text-align: center;
  text-transform: uppercase;
}

#username-input {
  width: clamp(8rem, 15vw, 12rem);
  letter-spacing: 0.04em;
}

button {
  font-family: var(--font);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  padding: 0.625em 1.25em;
  border: 1px solid;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 0.12s;
}
button:disabled { opacity: 0.3; cursor: default; }
button:not(:disabled):hover { opacity: 0.78; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary  { background: linear-gradient(90deg, var(--p1) 0%, var(--p2) 100%); color: #fff; border: none; width: min(10rem, 50vw); }
.btn-secondary{ background: transparent; color: var(--text); border-color: var(--border); }

.room-code {
  font-size: 2.4rem;
  letter-spacing: 0.45em;
  color: var(--accent);
  margin: 1rem 0;
  font-weight: bold;
}

/* Game container */

#game-container {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

#game-panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 32px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.03);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color 0.5s ease, box-shadow 0.5s ease;
}

/* Active-player highlight — border and glow shift to P1/P2 colour */
#game-container[data-turn="1"] #game-panel {
  border-color: rgba(224,80,64,0.5);
  box-shadow: 0 4px 32px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.03), 0 0 12px rgba(224,80,64,0.18);
}
#game-container[data-turn="2"] #game-panel {
  border-color: rgba(64,128,224,0.5);
  box-shadow: 0 4px 32px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.03), 0 0 12px rgba(64,128,224,0.18);
}

/* Top bar tint */
#game-container[data-turn="1"] #game-top-bar { background: rgba(224,80,64,0.07); transition: background 0.5s ease; }
#game-container[data-turn="2"] #game-top-bar { background: rgba(64,128,224,0.07); transition: background 0.5s ease; }

/* Bottom bar tint */
#game-container[data-turn="1"] #game-actions { background: rgba(224,80,64,0.05); transition: background 0.5s ease; }
#game-container[data-turn="2"] #game-actions { background: rgba(64,128,224,0.05); transition: background 0.5s ease; }

/* Side panel strip border tint (mobile flush-layout) */
#game-container[data-turn="1"] #side-panel { border-color: rgba(224,80,64,0.35); transition: border-color 0.5s ease; }
#game-container[data-turn="2"] #side-panel { border-color: rgba(64,128,224,0.35); transition: border-color 0.5s ease; }

/* Game top bar */

#game-top-bar {
  display: flex;
  align-items: stretch;
  gap: 0;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid var(--border2);
  white-space: nowrap;
  min-height: 2.875rem;
}

.top-bar-spacer { flex: 1; }

#game-nav-btn { display: none; }
#game-fullscreen-btn { display: none; }

/* Mobile nav button — hidden on desktop, shown via media query on mobile */
#mobile-nav-btn {
  display: none;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border2);
  color: var(--dim);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}
#mobile-nav-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }

#fullscreen-btn {
  display: none;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border2);
  color: var(--dim);
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0 0.5rem;
  align-items: center;
  height: 100%;
  margin-right: -0.5rem;
}
#fullscreen-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }

/* Mobile nav drawer */
#mobile-nav-drawer {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}
#mobile-nav-drawer:not([hidden]) { pointer-events: auto; }

#mobile-nav-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  transition: opacity 0.18s ease;
}
#mobile-nav-drawer:not([hidden]) #mobile-nav-backdrop { opacity: 1; }

#mobile-nav-panel {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: min(11.25rem, 60vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0.625rem 0;
  transform: translateX(-100%);
  transition: transform 0.18s ease;
}
#mobile-nav-drawer:not([hidden]) #mobile-nav-panel { transform: translateX(0); }

#mobile-nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0 0.5rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.mobile-nav-item {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.5em 0.625em;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  color: var(--dim);
  cursor: pointer;
  text-align: left;
  font-family: var(--font);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.mobile-nav-item:hover { background: var(--surface2); color: var(--text); }
.mobile-nav-item.active { background: var(--surface2); color: var(--text); border-color: var(--border); }
.mobile-nav-item.nav-home { color: var(--accent); opacity: 0.8; }
.mobile-nav-item.nav-home.active { opacity: 1; }

.mobile-nav-close {
  opacity: 0.4;
  font-size: 0.85rem;
  margin-left: 0.375em;
}
.mobile-nav-item:hover .mobile-nav-close { opacity: 0.8; }

#mobile-nav-username {
  padding: 0.5rem 0.625rem;
  margin: 0.5rem 0.5rem 0;
  border-top: 1px solid var(--border2);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#mobile-nav-username::before { content: 'USER  '; opacity: 0.5; }

.hud-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.375em 0.875em;
  border-right: 1px solid var(--border2);
  gap: 1px;
  min-width: 4rem;
}
.hud-cell:last-child { border-right: none; }

.hud-label {
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  color: var(--dim);
  text-transform: uppercase;
}

.hud-value {
  font-size: 0.88rem;
  font-weight: bold;
  letter-spacing: 0.06em;
  color: var(--text);
}

#day-counter  { color: var(--text); }

#turn-indicator        { font-size: 0.88rem; font-weight: bold; letter-spacing: 0.06em; }
#turn-indicator.my-turn    { color: #80ee80; }
#turn-indicator.their-turn { color: var(--dim); }

#funds-p1 { color: var(--p1); }
#funds-p2 { color: var(--p2); }

/* Canvas */

#canvas-wrapper {
  position: relative;
  overflow: hidden;
  line-height: 0;
}

/* Ready check overlay */

#ready-check-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8,8,16,0.78);
  backdrop-filter: blur(2px);
  z-index: 50;
  line-height: 1.4;
}
.rc-status {
  font-size: 0.7rem;
  color: var(--dim);
  letter-spacing: 0.06em;
}
.rc-status .rc-tag-ready { color: #80ee80; }

/* Pregame (ready check -> map roll -> pick mode) */

#pregame-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: clamp(1rem, 5vw, 2.25rem) clamp(1.5rem, 6vw, 3rem);
  text-align: center;
  min-width: min(20rem, 90vw);
  box-shadow: 0 8px 32px rgba(0,0,0,0.8);
}

#pregame-vs-line {
  font-size: 0.85rem;
  color: var(--dim);
  letter-spacing: 0.08em;
  margin-bottom: 1.375rem;
}

.pg-title {
  font-size: 0.68rem;
  letter-spacing: 0.28em;
  color: var(--accent);
  font-weight: bold;
  margin-bottom: 0.875rem;
}

.pg-countdown {
  font-size: 2.2rem;
  font-weight: bold;
  color: var(--text);
  margin-bottom: 1.125rem;
  letter-spacing: 0.04em;
}

.pg-countdown.urgent {
  color: #ee4444;
  animation: clock-pulse 0.6s ease-in-out infinite alternate;
}

.pg-mapname {
  font-size: 1.6rem;
  font-weight: bold;
  color: var(--text);
  letter-spacing: 0.12em;
  margin-bottom: 0.375rem;
}

.pg-side {
  font-size: 0.72rem;
  color: var(--dim);
  letter-spacing: 0.06em;
  margin-bottom: 1.125rem;
}

.pg-row {
  display: flex;
  gap: 0.625rem;
  justify-content: center;
  margin-bottom: 0.625rem;
}

.pg-map-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.875rem 0;
}

.map-pick-btn {
  width: min(12.5rem, 60vw);
  margin: 0 auto;
  letter-spacing: 0.1em;
}

#btn-ready { width: min(12.5rem, 60vw); margin-bottom: 0.875rem; }
#btn-ready:disabled { background: transparent; color: var(--dim); border-color: var(--border); }

#game-canvas {
  display: block;
  image-rendering: pixelated;
  /* width/height set in JS when map loads */
}

/* Game bottom bar */

/* game-actions: bottom bar on desktop, inline in top bar on mobile */
#game-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: rgba(255,255,255,0.04);
  border-top: 1px solid var(--border2);
  min-height: 2.875rem;
  flex-shrink: 0;
}

#game-bottom-bar {
  display: none;
}

.hud-cell[data-active="1"] .hud-label { color: var(--accent); }
.clock-low      { color: #f0c040 !important; }
.clock-critical { color: #ee4444 !important; animation: clock-pulse 0.6s ease-in-out infinite alternate; }
@keyframes clock-pulse { from { opacity: 1; } to { opacity: 0.5; } }

#btn-clock-off {
  font-size: 0.72rem;
  padding: 0.375em 0.875em;
  opacity: 0.5;
}
#btn-clock-off:not(:disabled):hover { opacity: 0.8; }
#btn-clock-off.agreed { color: var(--accent); border-color: var(--accent); opacity: 1; }

#btn-concede {
  font-size: 0.72rem;
  padding: 0.375em 0.875em;
  color: #d87060;
  border-color: rgba(216,112,96,0.35);
  background: transparent;
  opacity: 0.65;
}
#btn-concede:not(:disabled):hover { opacity: 1; }
#btn-concede[data-state="confirm"] {
  background: #c04030;
  color: #fff;
  border-color: #c04030;
  opacity: 1;
}

#btn-end-turn {
  background: var(--p1);
  color: #fff;
  border-color: var(--p1);
  padding: 0.5em 1.75em;
  font-size: 0.8rem;
}
#btn-end-turn:disabled {
  background: transparent;
  color: var(--dim);
  border-color: var(--border);
}

/* Action menu */

#action-menu {
  position: fixed;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem;
  min-width: 10.5rem;
  z-index: 200;
  box-shadow: 0 8px 28px rgba(0,0,0,0.65), 0 0 0 1px rgba(116,163,78,0.08);
  backdrop-filter: blur(6px);
  font-family: 'Courier New', Courier, monospace;
  animation: menu-pop 110ms ease-out;
}
@keyframes menu-pop {
  from { opacity: 0; transform: translateY(-2px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
#action-menu .menu-header {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  color: var(--accent);
  padding: 0.45em 0.85em 0.55em;
  border-bottom: 1px solid var(--border2);
  margin-bottom: 0.2rem;
  text-transform: uppercase;
  font-weight: bold;
}
#action-menu .menu-sep {
  height: 1px;
  background: var(--border2);
  margin: 0.25rem 0.35rem;
}
#action-menu .menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 0.5em 0.85em;
  font: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  border-radius: 4px;
  cursor: pointer;
  transition: background 80ms ease;
}
#action-menu .menu-item:not(:disabled):hover {
  background: var(--surface2);
  color: var(--accent);
}
#action-menu .menu-item:disabled {
  cursor: not-allowed;
  color: var(--dim);
  opacity: 0.55;
}
#action-menu .menu-label { font-weight: bold; letter-spacing: 0.08em; }
#action-menu .menu-sub {
  font-size: 0.66rem;
  color: var(--accent);
  letter-spacing: 0.05em;
  opacity: 0.85;
}
#action-menu .menu-item:disabled .menu-sub { color: var(--dim); }
#action-menu .menu-cancel { color: var(--dim); font-size: 0.7rem; }
#action-menu .menu-cancel:hover { color: var(--text); background: var(--surface2); }

/* Combat preview overlay */

#combat-preview {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 2rem));
  background: var(--panel-bg);
  border: 1px solid rgba(122,182,72,0.28);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.7), 0 0 0 1px rgba(0,0,0,0.45);
  font-family: 'Courier New', Courier, monospace;
  color: var(--text);
  z-index: 240;
  overflow: hidden;
  animation: cp-fade 140ms ease-out;
  pointer-events: none;
}
@keyframes cp-fade {
  from { opacity: 0; transform: translate(-50%, 4px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.cp-head {
  background: rgba(122,182,72,0.08);
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border2);
  text-align: center;
  letter-spacing: 0.12em;
}
.cp-head-title { display: block; font-size: 0.72rem; font-weight: bold; color: var(--accent); }
.cp-head-sub   { display: block; font-size: 0.62rem; color: var(--dim); margin-top: 0.15rem; }
.cp-body {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.5rem;
  padding: 0.75rem 0.9rem;
}
.cp-block { font-size: 0.72rem; line-height: 1.5; }
.cp-role  { font-size: 0.65rem; font-weight: bold; letter-spacing: 0.1em; }
.cp-role.cp-p1 { color: #e05040; }
.cp-role.cp-p2 { color: #4080e0; }
.cp-name  { font-size: 0.95rem; font-weight: bold; margin: 0.15rem 0 0.45rem; letter-spacing: 0.08em; }
.cp-hpbar {
  position: relative;
  width: 100%;
  height: 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(0,0,0,0.5);
  border-radius: 2px;
  overflow: hidden;
}
.cp-hp-ghost, .cp-hp-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
}
.cp-hp-ghost.cp-p1 { background: rgba(224,80,64,0.28); }
.cp-hp-ghost.cp-p2 { background: rgba(64,128,224,0.28); }
.cp-hp-fill.cp-p1  { background: #e05040; }
.cp-hp-fill.cp-p2  { background: #4080e0; }
.cp-hp-fill.cp-hp-low { background: #ee4444; }
.cp-hp-line  { margin-top: 0.3rem; display: flex; gap: 0.5rem; font-size: 0.72rem; }
.cp-hp-num   { font-weight: bold; }
.cp-dmg      { color: #ff5533; }
.cp-no-dmg   { color: var(--dim); }
.cp-terrain  { font-size: 0.65rem; color: var(--dim); margin-top: 0.25rem; }
.cp-formula  { font-size: 0.65rem; color: var(--dim); margin-top: 0.25rem; }
.cp-no-counter { font-style: italic; }
.cp-result   { font-size: 0.7rem; color: var(--text); margin-top: 0.1rem; }
.cp-divider  {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: rgba(255,255,255,0.45);
  border-left: 1px solid var(--border2);
  border-right: 1px solid var(--border2);
  padding: 0 0.5rem;
}
.cp-hint {
  background: rgba(255,180,0,0.13);
  color: rgba(255,200,80,0.95);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-align: center;
  padding: 0.7rem 0.8rem;
  border-top: 1px solid rgba(255,180,0,0.35);
  font-weight: bold;
  pointer-events: auto;
  cursor: pointer;
  transition: background 80ms ease;
  user-select: none;
}
.cp-hint:hover { background: rgba(255,180,0,0.22); color: #fff; }
.cp-hint:active { background: rgba(255,180,0,0.32); }
.cp-hint-sub { display: inline-block; margin-top: 0.2rem; font-size: 0.6rem; font-weight: normal; color: rgba(255,200,80,0.65); letter-spacing: 0.05em; }

/* Tile tooltip */

#tile-tooltip {
  position: fixed;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4375em 0.625em;
  font-size: 0.66rem;
  line-height: 1.55;
  color: var(--text);
  pointer-events: none;
  z-index: 250;
  min-width: 8rem;
  max-width: 14rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.55);
  letter-spacing: 0.03em;
}
.tt-row     { display: flex; justify-content: space-between; gap: 0.875rem; }
.tt-title   { font-weight: bold; color: var(--text); letter-spacing: 0.08em; }
.tt-sub     { color: var(--dim); }
.tt-divider { height: 1px; background: var(--border2); margin: 0.3em -0.125em; }
.tt-stars   { color: #aaddff; }
.tt-warn    { color: #ffee44; }
.tt-p1      { color: var(--p1); font-weight: bold; }
.tt-p2      { color: var(--p2); font-weight: bold; }

/* Message banner */

#msg-banner {
  position: fixed;
  top: calc(var(--header-h) + 0.75rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.625rem 1.25rem;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  z-index: 300;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
  cursor: pointer;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

/* Game-over banner variants */
#msg-banner.banner-victory { border-color: var(--accent); box-shadow: 0 4px 24px rgba(116,163,78,0.35); }
#msg-banner.banner-defeat  { border-color: var(--p1);     box-shadow: 0 4px 24px rgba(224,80,64,0.35); }
#msg-banner.banner-neutral { border-color: var(--border); }

.banner-outcome {
  font-size: 1.1rem;
  font-weight: bold;
  letter-spacing: 0.22em;
}
#msg-banner.banner-victory .banner-outcome { color: var(--accent); }
#msg-banner.banner-defeat  .banner-outcome { color: var(--p1); }
#msg-banner.banner-neutral .banner-outcome { color: var(--dim); }

.banner-reason {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--dim);
}
.banner-dismiss {
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  color: var(--dim);
  opacity: 0.5;
  margin-top: 0.125rem;
}

/* Side panel */

#side-panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 32px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.03);
  width: min(20rem, 28vw);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.18s ease;
}
#side-panel.collapsed { width: 26px; }
#side-panel.collapsed .tab-btn,
#side-panel.collapsed .side-view { display: none !important; }
#side-panel.collapsed .side-tabs-row { justify-content: center; }


.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--dim);
  font-family: var(--font);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  padding: 0.5em 0.25em;
  border-radius: 0;
  cursor: pointer;
  transition: color 0.12s;
}
.tab-btn:not(:disabled):hover { opacity: 1; color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.side-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#log-entries {
  padding: 0.5rem 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.log-entry {
  font-size: 0.66rem;
  letter-spacing: 0.03em;
  line-height: 1.5;
  padding: 0.25em 0;
  border-bottom: 1px solid var(--border2);
  color: var(--dim);
  word-break: break-word;
}
.log-entry:last-child { border-bottom: none; }
.log-entry.p1   { color: #e07868; }
.log-entry.p2   { color: #6090d8; }
.log-entry.sys  { color: var(--accent); opacity: 0.7; text-align: center; letter-spacing: 0.08em; padding: 0.5em 0; }



/* Chat */

.chat-msg {
  display: flex; align-items: baseline; gap: 0.15em;
  font-size: 0.72rem;
  line-height: 1.5;
  word-break: break-word;
  color: var(--text);
}
.chat-msg .chat-ts {
  color: var(--dim);
  font-size: 0.6rem;
  margin-right: 0.3125em;
  opacity: 0.7;
  flex-shrink: 0;
}
.chat-msg .chat-sender { font-weight: bold; margin-right: 0.25em; }
.chat-msg.p1 .chat-sender { color: var(--p1); }
.chat-msg.p2 .chat-sender { color: var(--p2); }
.chat-msg.sys { color: var(--dim); font-style: italic; text-align: center; }

.tab-btn .tab-badge {
  display: inline-block;
  margin-left: 0.3125em;
  background: var(--accent);
  color: var(--bg);
  border-radius: 8px;
  font-size: 0.55rem;
  padding: 1px 5px;
  font-weight: bold;
  letter-spacing: 0;
  vertical-align: middle;
}

/* Info / damage guide */

#info-view { padding: 0; }
.info-body {
  padding: 0.625rem 0.75rem;
  font-size: 0.66rem;
  line-height: 1.55;
  color: var(--text);
  letter-spacing: 0.02em;
  word-break: break-word;
}
.info-body p { margin-bottom: 0.5rem; }
.info-body p:last-child { margin-bottom: 0; }
.info-body b { color: var(--accent); font-weight: bold; }
.info-title {
  color: var(--accent);
  letter-spacing: 0.14em;
  font-size: 0.64rem;
  margin-bottom: 0.75rem !important;
  text-align: center;
  font-weight: bold;
}
.info-h {
  color: var(--dim);
  letter-spacing: 0.1em;
  font-size: 0.58rem;
  margin-top: 0.75rem !important;
  margin-bottom: 0.25rem !important;
  text-transform: uppercase;
}
.info-eq {
  background: rgba(255,255,255,0.05);
  border-left: 2px solid var(--accent);
  padding: 0.375em 0.5em;
  font-size: 0.62rem;
  line-height: 1.5;
}
.info-eg {
  color: var(--dim);
  font-size: 0.62rem;
  padding-left: 0.5em;
  font-style: italic;
}
.info-table {
  width: 100%;
  font-size: 0.62rem;
  border-collapse: collapse;
  margin: 0.25rem 0 0.5rem;
}
.info-table td { padding: 1px 2px; vertical-align: top; }
.info-table td:first-child  { color: #aaddff; width: 3em; white-space: nowrap; }
.info-table td:nth-child(2) { color: var(--text); width: 2.5em; }
.info-table td:last-child   { color: var(--dim); }
.info-tip {
  color: var(--accent);
  opacity: 0.8;
  font-size: 0.62rem;
  border-top: 1px solid var(--border2);
  padding-top: 0.5em;
  margin-top: 0.75rem !important;
}

.damage-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.6rem;
  margin-top: 0.375rem;
  table-layout: fixed;
}
.damage-matrix th,
.damage-matrix td {
  padding: 2px 0;
  text-align: center;
  border: 1px solid var(--border2);
  letter-spacing: 0;
}
.damage-matrix thead th { color: var(--accent); font-weight: bold; }
.damage-matrix tbody th { color: var(--accent); font-weight: bold; }
.damage-matrix td       { color: var(--text); }
.damage-matrix td.dm-high { color: #80ee80; font-weight: bold; }
.damage-matrix td.dm-mid  { color: var(--text); }
.damage-matrix td.dm-low  { color: var(--dim); }
.damage-matrix td.dm-none { color: var(--dim); opacity: 0.35; }
.matrix-axis {
  font-size: 0.58rem;
  color: var(--dim);
  letter-spacing: 0.04em;
  margin-top: 0.375rem;
  text-align: center;
}

/* Tablet — minor adjustments */

@media (max-width: 780px) {
  h1 { font-size: 1.4rem; }
  .room-code { font-size: 1.8rem; }
  #game-top-bar { gap: 0.625rem; font-size: 0.72rem; padding: 0.375rem 0.625rem; }
  #lobby-columns { grid-template-columns: 1fr; gap: 0; }
  #lobby-info-col { border-top: 1px solid var(--border2); padding-top: 1.25rem; margin-top: 0.5rem; }
}

/* Mobile — flash-prevention only (hides tab bar before JS module loads) */
@media (max-width: 600px), (orientation: landscape) and (max-height: 500px) {
  #tab-bar { display: none; }
}

/* Mobile layout — driven by JS-set .is-mobile class on #app */

#app.is-mobile #app-main               { padding: 0; }
#app.is-mobile #tab-bar                { display: none; }
#app.is-mobile #app-header             { min-height: 1.625rem; height: 1.625rem; padding: 0 0.5rem; gap: 0.375rem; justify-content: flex-start; }
#app.is-mobile #app-header .logo-version { display: none; }
#app.is-mobile #app-header #header-right { margin-left: auto; }
#app.is-mobile #mobile-nav-btn         { display: flex; align-items: center; height: 100%; padding: 0 0.5rem; margin-left: -0.5rem; }
#app.is-mobile #fullscreen-btn         { display: flex; align-items: center; height: 100%; }
#app.is-mobile .logo-box               { font-size: 0.72rem; padding: 0.1em 0.5em; }

/* In room-mode the header is still visible (hamburger lives there) */
#app.is-mobile.room-mode #app-header   { display: flex; }
#app.is-mobile.room-mode #msg-banner   { top: 0.5rem; }

/* When game is active: hide slim header — game-top-bar takes over */
#app.is-mobile.game-active.room-mode #app-header { display: none; }
#app.is-mobile.game-active.room-mode #game-nav-btn {
  display: flex;
  align-items: center;
  align-self: stretch;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border2);
  color: var(--dim);
  font-size: 1rem;
  padding: 0 0.5625rem;
  cursor: pointer;
  flex-shrink: 0;
}
#app.is-mobile.game-active.room-mode #game-nav-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
#app.is-mobile.game-active.room-mode #game-fullscreen-btn {
  display: flex;
  align-items: center;
  align-self: stretch;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border2);
  color: var(--dim);
  font-size: 1rem;
  padding: 0 0.5625rem;
  cursor: pointer;
  flex-shrink: 0;
}
#app.is-mobile.game-active.room-mode #game-fullscreen-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }

/* Compact HUD */
#app.is-mobile.room-mode #game-top-bar { min-height: 1.75rem; padding: 0 0.375rem; }
#app.is-mobile.room-mode .hud-cell     { padding: 0.125em 0.375em; min-width: 2.75rem; gap: 0; }
#app.is-mobile.room-mode .hud-label    { display: none; }
#app.is-mobile.room-mode .hud-value    { font-size: 0.78rem; }

/* Compact action bar — stays at bottom of game-panel in both modes */
#app.is-mobile.room-mode #game-actions {
  padding: 0.25rem 0.5rem; min-height: 0; gap: 0.375rem;
  background: transparent;
}
#app.is-mobile.room-mode #btn-end-turn  { padding: 0.25em 0.75em; font-size: 0.68rem; }
#app.is-mobile.room-mode #btn-concede,
#app.is-mobile.room-mode #btn-clock-off { padding: 0.25em 0.4375em; font-size: 0.58rem; }

/* Viewport chain — prevent pane-game from scrolling instead of canvas panning */
#app.is-mobile.room-mode #pane-game    { overflow: hidden; align-items: stretch; justify-content: flex-start; }
#app.is-mobile.room-mode #gp-main      { align-items: stretch; justify-content: flex-start; min-height: 0; }
#app.is-mobile.room-mode #game-container { flex: 1; min-height: 0; position: relative; gap: 0; }
#app.is-mobile.room-mode #game-panel   { flex: 1; min-height: 0; min-width: 0; border-radius: 0; border-left: none; border-right: none; }
#app.is-mobile.room-mode #canvas-wrapper { flex: 1; min-height: 0; }
#app.is-mobile.room-mode #game-canvas  { width: 100% !important; height: 100% !important; }

/* Side panels — thin strips, overlay when opened */
#app.is-mobile.room-mode #side-panel,
#app.is-mobile.room-mode #room-chat    { transition: none; }
#app.is-mobile.room-mode #side-panel   { width: 26px !important; border-radius: 0; border-top: none; border-bottom: none; }
#app.is-mobile.room-mode #side-panel:not(.collapsed) {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: min(17.5rem, 85vw) !important; z-index: 10;
}
#app.is-mobile.room-mode #room-chat    { width: 26px !important; }
#app.is-mobile.room-mode #app-body     { position: relative; }
#app.is-mobile.room-mode #room-chat:not(.collapsed) {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: min(16.25rem, 85vw) !important; z-index: 20;
}

/* Pregame / waiting */
#app.is-mobile.room-mode .gp-centered  { justify-content: center; padding: 1rem; }

/* ── Profile widget + auth modal ─────────────────────────────────── */
#profile-widget {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.25rem 0.5rem; border: 1px solid var(--border);
  border-radius: 4px; background: var(--surface2);
  font-size: 0.85rem;
}
#profile-name { font-weight: 600; max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-stats { opacity: 0.85; font-variant-numeric: tabular-nums; display: inline-flex; gap: 0.4rem; align-items: baseline; }
.profile-stat-label { font-size: 0.65rem; opacity: 0.6; margin-right: 0.2rem; letter-spacing: 0.05em; }
.mod-badge { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.06em; color: #e8a; background: #4a1a3a; border: 1px solid #c06090; border-radius: 3px; padding: 0.05em 0.35em; }
.profile-stat-sep   { opacity: 0.35; }
#profile-auth-btn { padding: 0.15rem 0.5rem; font-size: 0.75rem; }
#app.is-mobile #profile-widget .profile-wl   { display: none; }
#app.is-mobile #profile-widget #profile-name { max-width: 4.5rem; }

#auth-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.auth-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.auth-modal-panel {
  position: relative; background: var(--panel-bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 1.25rem; width: min(22rem, 92vw); display: flex; flex-direction: column; gap: 0.75rem;
}
.auth-tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); }
.auth-tab {
  flex: 1; background: none; border: none; color: inherit; padding: 0.5rem; cursor: pointer;
  border-bottom: 2px solid transparent; font-weight: 600; opacity: 0.6;
}
.auth-tab.active { opacity: 1; border-bottom-color: var(--accent, #74a34e); }
#auth-form { display: flex; flex-direction: column; gap: 0.6rem; }
#auth-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.8rem; opacity: 0.85; }
#auth-form input { padding: 0.4rem 0.5rem; background: var(--surface); border: 1px solid var(--border); color: inherit; border-radius: 3px; }
.auth-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.25rem; }
.auth-error { color: #d77; font-size: 0.8rem; }
.auth-hint  { font-size: 0.7rem; opacity: 0.6; }
