/* ── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0d1117;
  --surface:      #161b22;
  --surface-hover:#1c2330;
  --border:       #30363d;
  --text-primary: #e6edf3;
  --text-muted:   #8b949e;
  --green:        #2ea043;
  --green-glow:   #2ea04366;
  --red:          #da3633;
  --red-glow:     #da363366;
  --accent:       #388bfd;

  /* 4K portrait: default sizes */
  --gap:       36px;
  --pad:       48px;
  --radius:    16px;
  --dot-size:  28px;
}

html, body {
  width: 100%;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 28px;
  line-height: 1.45;
  overflow-x: hidden;
}

@-webkit-keyframes spin { to { -webkit-transform: rotate(360deg); transform: rotate(360deg); } }
@keyframes spin { to { -webkit-transform: rotate(360deg); transform: rotate(360deg); } }

/* ── Grid (flexbox — no CSS Grid, works in Chrome 49+) ── */
.screen-grid {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  padding: var(--pad);
  /* Negative right margin cancels the last tile's right gap in each row */
  margin-right: calc(-1 * var(--gap));
}

/* ── Screen tile ──────────────────────────────────────── */
.screen-tile {
  -webkit-flex: 0 0 calc(20% - var(--gap));
  flex: 0 0 calc(20% - var(--gap));
  margin-right: var(--gap);
  margin-bottom: var(--gap);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  overflow: hidden;
  -webkit-transition: border-color 0.2s, -webkit-transform 0.2s;
  transition: border-color 0.2s, transform 0.2s;
}

/* Auto-adjust columns based on tile count */
.screen-grid[data-count="1"] .screen-tile  { -webkit-flex: 0 0 calc(100% - var(--gap)); flex: 0 0 calc(100% - var(--gap)); }
.screen-grid[data-count="2"] .screen-tile  { -webkit-flex: 0 0 calc(50% - var(--gap)); flex: 0 0 calc(50% - var(--gap)); }
.screen-grid[data-count="3"] .screen-tile  { -webkit-flex: 0 0 calc(33.333% - var(--gap)); flex: 0 0 calc(33.333% - var(--gap)); }
.screen-grid[data-count="4"] .screen-tile  { -webkit-flex: 0 0 calc(25% - var(--gap)); flex: 0 0 calc(25% - var(--gap)); }

.screen-tile:hover {
  border-color: var(--accent);
  -webkit-transform: translateY(-3px);
  transform: translateY(-3px);
}

/* Tile header */
.tile-header {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  padding: 24px 30px;
  border-bottom: 2px solid var(--border);
  background: var(--surface-hover);
}

.status-dot {
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
  width: var(--dot-size);
  height: var(--dot-size);
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 10px var(--red-glow);
  -webkit-transition: background 0.4s, box-shadow 0.4s;
  transition: background 0.4s, box-shadow 0.4s;
  margin-right: 20px;
}

.status-dot[data-online="true"] {
  background: var(--green);
  box-shadow: 0 0 14px var(--green-glow);
  -webkit-animation: pulse-green 2.5s ease-in-out infinite;
  animation: pulse-green 2.5s ease-in-out infinite;
}

@-webkit-keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 10px var(--green-glow); }
  50%       { box-shadow: 0 0 22px #2ea04388; }
}
@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 10px var(--green-glow); }
  50%       { box-shadow: 0 0 22px #2ea04388; }
}

.tile-name {
  font-size: 32px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Screenshot area — padding-bottom trick instead of aspect-ratio */
.tile-screenshot {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%; /* 16:9 */
  background: #0a0d12;
  overflow: hidden;
}

.screenshot-img {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  -o-object-fit: contain;
  object-fit: contain;
  display: none;
}

.screenshot-img.loaded {
  display: block;
}

.screenshot-placeholder {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 26px;
}

.screenshot-placeholder svg {
  width: 80px;
  height: 80px;
  opacity: 0.35;
  margin-bottom: 20px;
}

.screenshot-placeholder.hidden { display: none; }

/* Tile footer */
.tile-footer {
  padding: 16px 30px;
  border-top: 2px solid var(--border);
  background: var(--surface-hover);
}

.tile-updated {
  font-size: 22px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Offline overlay on tile */
.screen-tile[data-online="false"] .tile-screenshot::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(218, 54, 51, 0.07);
  pointer-events: none;
}

/* ── Loading state ────────────────────────────────────── */
.loading-state {
  -webkit-flex: 0 0 calc(100% - var(--gap));
  flex: 0 0 calc(100% - var(--gap));
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  min-height: 400px;
  color: var(--text-muted);
  font-size: 30px;
}

.loading-state p {
  margin-top: 32px;
}

.spinner {
  width: 72px;
  height: 72px;
  border: 6px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  -webkit-animation: spin 0.8s linear infinite;
  animation: spin 0.8s linear infinite;
}

/* ── Status summary bar (bottom) ──────────────────────── */
.status-summary {
  position: -webkit-sticky;
  position: sticky;
  bottom: 0;
  width: 100%;
  height: 80px;
  background: var(--surface);
  border-top: 2px solid var(--border);
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  font-size: 26px;
  color: var(--text-muted);
}

.status-summary strong {
  margin: 0 8px;
}

.summary-online  { color: var(--green); font-weight: 700; margin: 0 30px; }
.summary-offline { color: var(--red);   font-weight: 700; margin: 0 30px; }

/* ── Full HD (≤ 1920px) ───────────────────────────────── */
@media (max-width: 1920px) {
  :root {
    --gap:      16px;
    --pad:      20px;
    --radius:   8px;
    --dot-size: 12px;
  }

  html, body { font-size: 13px; }

  .tile-name        { font-size: 14px; }
  .tile-updated     { font-size: 10px; }
  .tile-header      { padding: 10px 14px; }
  .tile-footer      { padding: 7px 14px; }
  .status-dot       { margin-right: 10px; }

  .screenshot-placeholder            { font-size: 12px; }
  .screenshot-placeholder svg        { width: 36px; height: 36px; margin-bottom: 8px; }

  .loading-state    { font-size: 14px; }
  .loading-state p  { margin-top: 16px; }
  .spinner          { width: 32px; height: 32px; border-width: 3px; }

  .status-summary          { height: 40px; font-size: 12px; }
  .summary-online,
  .summary-offline         { margin: 0 14px; }
}
