/* Desktop layout — a wide window driven by a mouse (core.js
   isDesktopLayout() uses the same query). Grid, widths and order only:
   colours, fonts and borders stay in mini_app.css,
   so this file serves both designs. Nothing here applies on a phone or in
   a narrow Telegram window. */

/* The game sidebar and its toggle exist only in the desktop layout. */
#game-side, #btn-side-toggle, #map-zoom { display: none; }

/* ─── Tournament organiser panel (.tm-*) ─────────────────────────── */
/* Six tabs don't fit a phone: scroll them instead of clipping the last. */
#tm-tabs { overflow-x: auto; }
#tm-tabs .lobby-tab { flex: 0 0 auto; padding-left: 10px; padding-right: 10px; }
.tm-seating {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0;
  align-items: stretch;
}
.tm-table {
  flex: 1 1 200px;
  min-width: 180px;
  background: var(--surface, var(--hg-paper-raised));
  border: 1px solid var(--line, var(--hg-rule-soft));
  border-radius: var(--hg-r, 10px);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color .15s ease, background-color .15s ease;
}
.tm-table.tm-drop {
  border-color: var(--accent, var(--hg-ink));
  background: var(--fill, var(--hg-paper-sunk));
}
.tm-table.tm-short {
  border-color: var(--red, var(--hg-oxblood));
}
.tm-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--fill, var(--hg-paper-sunk));
  border: 1px solid var(--line, var(--hg-rule-soft));
  border-radius: var(--hg-r-sm, 6px);
  cursor: grab;
  font-size: 13px;
  user-select: none;
}
.tm-chip:active {
  cursor: grabbing;
}
.tm-chip-unqualified {
  font-size: 11px;
  color: var(--red, var(--hg-oxblood));
  font-style: italic;
}
.tm-chip-move {
  font-size: 11px;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--surface, var(--hg-paper-raised));
  border: 1px solid var(--line, var(--hg-rule-soft));
  color: var(--text, var(--hg-ink));
}
.tm-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line, var(--hg-rule-soft));
}
.tm-danger {
  color: var(--red, var(--hg-oxblood)) !important;
  border-color: var(--red, var(--hg-oxblood)) !important;
}
.tm-rounds-table {
  width: 100%;
  overflow-x: auto;
  margin: 12px 0;
}
.tm-round-row {
  display: grid;
  grid-template-columns: 32px minmax(110px, 1.2fr) minmax(130px, 1.2fr) 60px 60px 140px 60px 36px;
  gap: 6px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--line, var(--hg-rule-soft));
  min-width: 650px;
}

@media (min-width: 1024px) and (hover: hover) and (pointer: fine) {
  :root {
    --dt-content: 1320px;
    /* Side padding that centres a --dt-content column inside a full-width
       scroller (the scrollbar stays at the window edge). */
    --dt-gutter: max(24px, calc((100% - var(--dt-content)) / 2));
    --dt-side: 340px;
  }

  #lobby, #tournament-view, #tournament-manage-view, #award-room-view, #leaderboard-view, #profile-view {
    padding-left: var(--dt-gutter);
    padding-right: var(--dt-gutter);
  }

  /* ── Lobby ──────────────────────────────────────────────────────
     One wrapping flex column/row: topbar on top, then the nav bar docked
     below it (not fixed at the bottom), then the games as a grid of
     rows/cards. lobby.js shows #lobby with an inline display:block,
     hence the attribute selector and !important. */
  .safe-area-deadzone { height: max(var(--safe-t, 0px), 12px); }
  #lobby[style*="block"] {
    display: flex !important; flex-wrap: wrap; align-items: center; align-content: flex-start;
    column-gap: 24px; padding-top: 0; padding-bottom: 0;
  }
  #lobby > * { flex: 0 0 100%; min-width: 0; order: 8; }
  #lobby > .safe-area-deadzone { order: 0; }
  #lobby > .lobby-topbar { order: 1; }
  #lobby > .lobby-nav {
    position: static; order: 2;
    display: flex; gap: 4px; padding: 4px 0 8px; margin-bottom: 14px;
    background: transparent; border-top: 0; border-bottom: 1px solid var(--hg-rule-soft);
  }
  .lobby-nav-item {
    flex: 0 0 auto; flex-direction: row; gap: 8px;
    padding: 6px 16px; font-size: 14px; min-height: 40px;
  }
  .lobby-nav-item.active::after { display: none; }
  .lobby-nav-item.active {
    border-bottom: 3px solid var(--hg-ink); margin-bottom: -9px; padding-bottom: 12px;
  }
  .lobby-nav-create { margin-left: auto; }
  /* The ＋ and Rating sheets' buttons, laid out in the row (lobby.js
     placeLobbySheetItems); the profile closes the row on the right. */
  .lobby-nav { flex-wrap: wrap; }
  .lobby-nav > .lobby-nav-inline { display: contents; }
  .lobby-nav-inline > .btn {
    background: transparent; border: 0; box-shadow: none; color: var(--hg-ink-3);
    font-family: var(--hg-font-label); font-weight: 600; font-size: 14px;
    letter-spacing: .05em; text-transform: uppercase;
    display: inline-flex; align-items: center; gap: 8px;
    flex: 0 0 auto; padding: 6px 12px; min-height: 40px; width: auto; cursor: pointer;
  }
  .lobby-nav-inline > .btn:hover, .lobby-nav-item:hover { color: var(--hg-ink); }
  .lobby-nav-inline > .btn .hg-ico { width: 19px; height: 19px; }
  .lobby-nav-me { margin-left: auto; }
  .lobby-nav-plus { width: 28px; height: 28px; font-size: 18px; }
  .lobby-nav .tab-badge { position: static; margin-left: 2px; }
  #lobby > .guest-strip { order: 3; }
  #lobby > .tournament-banner { order: 4; }
  #lobby > .lobby-subhead { order: 5; }
  #lobby > #find-controls { order: 6; }
  /* A form always takes a row of its own: the right margin fills the rest
     of the line. */
  #lobby > .form-card { max-width: 760px; margin-right: max(0px, calc(100% - 760px)); }

  /* Others' games sit in their own full-width panel with the same grid. */
  #lobby-games, #lobby-games > .lobby-others {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 20px 24px; align-items: stretch;
  }
  #lobby-games > .lobby-section-label,
  #lobby-games > .lobby-empty,
  #lobby-games > .lobby-more,
  #lobby-games > .lobby-group-break,
  #lobby-games > .lobby-others,
  .lobby-others > .lobby-section-label { grid-column: 1 / -1; }
  #lobby-games .game-card { display: flex; flex-direction: column; border: 1px solid var(--hg-rule, var(--line)); padding: 14px 16px; margin: 0; }
  #lobby-games .game-card > .lobby-card-actions { margin-top: auto; padding-top: 12px; }
  .lobby-card-actions { justify-content: flex-start; }
  .lobby-card-actions .btn { flex: 0 0 auto; }

  /* ── Game: header with the actions, the map, a sidebar ──────────
     game.js shows #game-view with an inline display:flex; on desktop it
     is a grid. #panel stays absolute, now inside the map's grid cell. */
  #game-view:not([style*="none"]) {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) var(--dt-side);
    grid-template-rows: auto auto auto auto minmax(0, 1fr);
  }
  #game-view.side-collapsed { grid-template-columns: minmax(0, 1fr) 0; }
  #game-view > #header { grid-column: 1 / -1; grid-row: 1; }
  #game-view > #sandbox-switcher { grid-column: 1; grid-row: 2; }
  #game-view > #deadline-banner { grid-column: 1; grid-row: 3; }
  #game-view > #draw-banner { grid-column: 1; grid-row: 4; }
  #game-view > #map-wrap, #game-view > #panel { grid-column: 1; grid-row: 5; min-height: 0; }
  #game-view > #game-side {
    grid-column: 2; grid-row: 2 / -1; min-height: 0; min-width: 0;
    display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--bg);
  }
  #game-view.side-collapsed > #game-side { display: none; }

  /* Header: back · who/when · actions · Ready · sidebar toggle. */
  #game-view #header {
    flex-direction: row; justify-content: flex-start; align-items: center; text-align: left;
    gap: 8px; padding: 8px 16px; min-height: 56px;
  }
  #game-view #header .info {
    order: 1; flex: 1 1 auto; width: auto; display: flex; flex-direction: row; align-items: center;
    gap: 14px; min-width: 0;
  }
  #game-view #header .hdr-who, #game-view #header .hdr-when {
    display: flex; align-items: center; gap: 8px; white-space: nowrap; flex-wrap: nowrap;
    overflow: hidden; text-overflow: ellipsis; min-width: 0; justify-content: flex-start;
  }
  /* The power's name never shrinks. When the row is short the deadline plate
     drops under the phase whole (squeezed, it showed just its clock and a letter). */
  #game-view #header .hdr-who { flex: 0 0 auto; }
  #game-view #header .hdr-when { flex: 1 1 auto; flex-wrap: wrap; row-gap: 2px; }
  #game-view #header .hdr-who strong,
  #game-view #header .hdr-when #g-phase {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  #game-view #g-deadline {
    display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 10px;
    background: var(--fill, rgba(127, 127, 127, 0.15)); font-size: 12px; line-height: 1.3;
    font-weight: 600; white-space: nowrap; flex: none;
  }
  /* Wider than its row even on a line of its own ("deadline passed … ·
     resolving…"): the text ends in an ellipsis, so it is a block, not a flex box. */
  #game-view #g-deadline:not(:empty) {
    display: inline-block; max-width: 100%; margin-left: 0; overflow: hidden; text-overflow: ellipsis;
  }
  #game-view #g-deadline:not(:empty)::before { display: inline-block; margin-right: 4px; vertical-align: -0.15em; }
  #game-view #header #g-phase { flex: 0 1 auto; min-width: 0; }
  #game-view #header #g-quota { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  #game-view #g-deadline:empty { display: none; }
  #game-view #header > #btn-back {
    order: 0; position: static; width: auto; min-width: 0; padding: 0 14px 0 10px; gap: 6px;
  }
  #game-view #header > #btn-back::after { content: attr(aria-label); white-space: nowrap; }
  #game-view #header > .toolbar-group {
    order: 2; flex: 0 0 auto; flex-wrap: nowrap; gap: 6px; padding: 0; pointer-events: auto;
    background: transparent; border: 0; -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  #game-view #header > .toolbar-group .btn {
    width: auto; min-width: 0; height: 38px; min-height: 38px; padding: 0 12px; gap: 6px;
    border-radius: 24px; animation: none;
  }
  #game-view #header > .toolbar-group .btn::after { content: attr(data-label); white-space: nowrap; }
  /* Outlined secondary actions, so the filled Ready is the one that stands out. */
  #game-view #header > .toolbar-group .btn {
    background: transparent; color: var(--text); border: 1px solid var(--line);
  }
  #game-view #header #btn-surrender {
    order: -1; margin-left: 16px; margin-right: 16px; width: 38px; min-width: 38px; padding: 0;
  }
  #game-view #header #btn-surrender::after { content: none; }
  #game-view #header > #btn-ready {
    order: 3; flex: 0 0 auto; min-width: 120px; height: 38px; min-height: 38px;
  }
  #game-view #header > #btn-ready:not(.btn-ready-on) {
    background: var(--accent); color: var(--on-accent); border-color: transparent;
  }
  #game-view #header > #sandbox-save { order: 3; margin: 0; height: 38px; min-height: 38px; padding: 0 16px; }
  #game-view #header > #btn-side-toggle { order: 4; display: inline-flex; flex: 0 0 auto; }
  /* The tabs replace these keys; ☰ and the spectator roster are not needed. */
  #game-view #btn-menu, #game-view #observer-roster,
  #game-view #btn-history, #game-view #btn-info, #game-view #btn-chat,
  #chat-view #chat-map-btn { display: none !important; }
  /* Beside the map there is nothing to go back to: the tabs switch panes.
     In a thread ← still steps back to the list. */
  #game-side #chat-view.at-list #chat-back, #game-side #info-back { display: none; }
  #game-view #hint {
    top: auto; bottom: 16px; left: 50%; right: auto; transform: translateX(-50%);
  }

  /* The map on a mouse: zoom keys, hover name, cursors. */
  #game-view #map-zoom {
    position: absolute; right: 16px; bottom: 16px; z-index: 25;
    display: flex; flex-direction: column; gap: 6px;
  }
  #game-view #map-zoom .btn {
    width: 38px; min-width: 38px; height: 38px; min-height: 38px; padding: 0;
    font-size: 18px; line-height: 1;
  }
  #map-tip {
    position: absolute; z-index: 30; pointer-events: none; white-space: nowrap;
    padding: 4px 8px; border-radius: 6px; font-size: 13px; line-height: 1.3;
    background: var(--text); color: var(--bg);
  }
  #map svg { cursor: grab; }
  #map svg.over-target { cursor: pointer; }
  #map svg.is-panning { cursor: grabbing; }
  #map svg .prov-hover { filter: brightness(1.1) saturate(1.15); }

  /* Sidebar */
  #side-tabs { order: 1; display: flex; flex: 0 0 auto; border-bottom: 1px solid var(--line); }
  #side-tabs [role="tab"] {
    flex: 1 1 0; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    background: transparent; border: 0; border-bottom: 3px solid transparent; color: var(--dim);
    font: inherit; font-weight: 600; cursor: pointer;
  }
  #side-tabs [role="tab"][aria-selected="true"] { color: var(--text); border-bottom-color: currentColor; }
  #side-tabs [role="tab"][hidden] { display: none; }
  #side-tabs .chat-badge { position: static; }
  #game-side .side-pane {
    order: 2; display: none; flex: 1 1 auto; min-height: 0; flex-direction: column; overflow-y: auto;
  }
  #game-side .side-pane.is-on { display: flex; }
  /* Chat and info docked here drop their full-screen padding and deadzone. */
  #game-side #chat-view, #game-side #info-view { flex: 1 1 auto; height: auto; padding: 8px 12px; }
  #game-side .safe-area-deadzone { display: none; }
  /* History: a roomy card — large ◀ ▶, the slider, and
     every turn as a list (the phone's dropdown is hidden here). */
  #game-side #history-bar {
    margin: 0 12px 12px; width: auto; max-width: none; white-space: normal;
    grid-template-columns: 1fr 1fr; gap: 10px;
    padding: 14px; border-radius: 12px; font-size: 15px;
  }
  #game-side #history-bar[style*="flex"] { display: grid !important; }
  #game-side #hist-select { display: none; }
  #game-side #history-bar .hist-btn { min-height: 44px; font-size: 18px; border: 1px solid currentColor; border-radius: 10px; }
  #game-side #hist-range { grid-column: 1 / -1; grid-row: 2; margin: 4px 0; }
  #game-side #hist-list {
    display: flex; flex-direction: column; gap: 2px; grid-column: 1 / -1; grid-row: 3;
    max-height: 340px; overflow-y: auto;
  }
  #game-side #hist-list button {
    background: none; border: 0; border-radius: 8px; color: inherit; font: inherit;
    font-size: 14px; text-align: left; padding: 9px 12px; cursor: pointer;
  }
  #game-side #hist-list button:hover { background: rgba(127, 127, 127, 0.15); }
  #game-side #hist-list button[aria-selected="true"] { background: rgba(127, 127, 127, 0.28); font-weight: 700; }
  .side-list { display: grid; gap: 6px; padding: 12px; }
  .side-row {
    display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 10px;
    padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--r-card);
  }
  .side-row[role="button"] { cursor: pointer; }
  .side-row[role="button"]:hover { background: var(--fill); }
  .side-row.no-order .side-order { color: var(--red); font-style: italic; }
  .side-unit { font-weight: 600; white-space: nowrap; }
  /* Full province names (maps with full_name_labels): a wider column that may wrap. */
  .side-list.full-names .side-row { grid-template-columns: minmax(64px, 40%) minmax(0, 1fr) auto; }
  .side-list.full-names .side-unit { white-space: normal; overflow-wrap: anywhere; }
  .side-del { background: transparent; border: 0; color: var(--dim); cursor: pointer; padding: 4px 6px; font: inherit; }
  .side-note { margin: 0; padding: 12px; color: var(--dim); }
  #side-tabs [role="tab"] {
    font-family: var(--hg-font-label); letter-spacing: .07em; text-transform: uppercase;
  }
  .side-unit { font-family: var(--hg-font-mono); }

  /* ── Gazette, player profile, dialogs, controls ───────────────── */
  /* The Gazette reads as a newspaper page: a centred column of text. */
  #gazette-view {
    padding-left: max(24px, calc((100% - 760px) / 2));
    padding-right: max(24px, calc((100% - 760px) / 2));
  }
  /* The player profile: a dialog over the screen it was opened from
     (player_profile.js keeps that screen; desktop.js adds the scrim). */
  #player-profile-view:not([style*="none"]) {
    position: fixed; z-index: 150; top: 6vh; bottom: 6vh; left: 0; right: 0; margin: 0 auto;
    width: min(560px, calc(100% - 48px)); height: auto; padding: 16px 20px;
    border: 1px solid var(--line); border-radius: var(--r-card);
  }
  #player-profile-view .safe-area-deadzone { display: none; }
  #profile-scrim { position: fixed; inset: 0; z-index: 149; background: rgba(0, 0, 0, 0.55); }
  #profile-scrim[hidden] { display: none; }

  /* A mouse needs smaller targets than a thumb (16px text stays). */
  .btn { min-height: 38px; }
  .field-input { min-height: 40px; padding: 8px 12px; }

  /* Tournament, Award Room, Leaderboard: tables, not a page-wide stretch. */
  #tournament-view > *, #tournament-manage-view > *, #award-room-view > *, #leaderboard-view > * {
    max-width: 960px; margin-left: auto; margin-right: auto;
  }
}

/* ≥ 1440: a wider sidebar; the Gazette sets in two newspaper columns. */
@media (min-width: 1440px) and (hover: hover) and (pointer: fine) {
  :root { --dt-side: 400px; }
  #gazette-view {
    padding-left: max(24px, calc((100% - 1120px) / 2));
    padding-right: max(24px, calc((100% - 1120px) / 2));
  }
  /* Only a section's articles flow into columns, and an article never splits:
     a headline can't be stranded from its text, a block can't be cut short. */
  #gazette-body .gz-cols { column-count: 2; column-gap: 40px; column-rule: 1px solid var(--line); }
  #gazette-body .gz-cols:has(> .gz-article:only-child) { column-count: 1; }
  #gazette-body .gz-article { break-inside: avoid; }
}

