:root {
  --bg: #090d12;
  --panel: #11171f;
  --card: #1b232d;
  --card-2: #202a35;
  --border: rgba(255,255,255,.14);
  --text: #f6f8fb;
  --muted: #aeb9c7;
  --p1: #38a0ff;
  --p2: #ff6957;
  --open: #cfd7e2;
  --warn: #ffd35c;
  --max-width: 1500px;
}

* { box-sizing: border-box; }

html { background: var(--bg); color-scheme: dark; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 0%, rgba(56,160,255,.08), transparent 32rem),
    radial-gradient(circle at 85% 0%, rgba(255,105,87,.08), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button { font: inherit; }
[hidden] { display: none !important; }

.page-shell {
  width: min(calc(100% - 32px), var(--max-width));
  margin: 0 auto;
  padding: 24px 0 28px;
}

.site-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 0 4px 18px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 2px;
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(28px, 4vw, 52px);
  line-height: .95;
  letter-spacing: .5px;
}

.connection-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.connection-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #8a94a3;
  box-shadow: 0 0 0 4px rgba(138,148,163,.12);
}

.connection-dot.live {
  background: #42d77d;
  box-shadow: 0 0 0 4px rgba(66,215,125,.12);
}

.connection-dot.error {
  background: #ff6957;
  box-shadow: 0 0 0 4px rgba(255,105,87,.12);
}

.scorebar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(17,23,31,.88);
  backdrop-filter: blur(10px);
}

.score-team {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  font-weight: 900;
}

.score-team span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(14px, 2vw, 20px);
}

.score-team strong {
  flex: 0 0 auto;
  font-size: clamp(30px, 4vw, 48px);
  color: #fff;
  line-height: 1;
}

.score-team.p1 { justify-content: flex-end; color: var(--p1); }
.score-team.p2 { justify-content: flex-start; color: var(--p2); }

.score-center {
  min-width: 100px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 390px);
  gap: 18px;
  align-items: start;
}

.board-panel,
.details-panel {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(17,23,31,.94);
}

.board-panel { padding: 16px; }

.board-grid {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: clamp(4px, .55vw, 8px);
}

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  border: 2px solid rgba(255,255,255,.18);
  border-radius: clamp(6px, .8vw, 10px);
  background: var(--card-2);
  color: white;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tile:hover,
.tile:focus-visible,
.tile.selected {
  outline: none;
  border-color: #fff;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.22);
}

.tile.owner-p1 { border-color: var(--p1); }
.tile.owner-p2 { border-color: var(--p2); }
.tile.owner-other { border-color: var(--warn); }
.tile.selected { border-color: #fff; }

.tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.02) 35%, rgba(0,0,0,.75) 100%);
}

.tile.owner-p1 .tile-shade {
  background: linear-gradient(to bottom, rgba(56,160,255,.12), rgba(16,74,121,.66));
}

.tile.owner-p2 .tile-shade {
  background: linear-gradient(to bottom, rgba(255,105,87,.12), rgba(117,39,31,.66));
}

.tile-number {
  position: absolute;
  top: 6px;
  left: 6px;
  min-width: 27px;
  height: 27px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: rgba(0,0,0,.78);
  font-size: clamp(10px, 1.2vw, 13px);
  font-weight: 900;
}

.tile-owner {
  position: absolute;
  top: 6px;
  right: 6px;
  max-width: 62%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 5px 7px;
  border-radius: 7px;
  background: rgba(0,0,0,.76);
  font-size: clamp(8px, .95vw, 11px);
  font-weight: 900;
}

.tile-title {
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  font-size: clamp(9px, 1vw, 12px);
  font-weight: 900;
  text-shadow: 0 1px 4px #000;
}

.board-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.board-legend > span { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend-dot.p1 { background: var(--p1); }
.legend-dot.p2 { background: var(--p2); }
.legend-dot.open { background: var(--open); }

.details-panel {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 18px;
}

.details-empty {
  min-height: 430px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
}

.details-empty-number {
  font-size: 86px;
  line-height: .9;
  font-weight: 900;
  color: rgba(255,255,255,.08);
}

.details-empty h2,
#details-content h2 {
  margin: 14px 0 7px;
  color: var(--text);
}

.details-empty p,
#details-description {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.details-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.details-number,
.details-status {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1px;
}

.details-status {
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--open);
}

.details-image-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 12px;
  background: #202832;
}

#details-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#details-image-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 28px;
  font-weight: 900;
}

#details-content h2 {
  font-size: 22px;
  line-height: 1.2;
}

#details-description {
  font-size: 14px;
}

.details-list {
  margin: 18px 0 0;
}

.details-list > div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid rgba(255,255,255,.09);
}

.details-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.details-list dd {
  margin: 0;
  text-align: right;
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 900;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 4px 0;
  color: var(--muted);
  font-size: 12px;
}

.mobile-backdrop { display: none; }

@media (max-width: 900px) {
  .page-shell {
    width: min(calc(100% - 20px), var(--max-width));
    padding-top: 14px;
  }

  .site-header { padding-bottom: 12px; }

  .connection-wrap { font-size: 11px; }

  .scorebar {
    gap: 8px;
    padding: 10px 12px;
  }

  .score-team { gap: 7px; }
  .score-center { min-width: 62px; font-size: 9px; }

  .content-grid { display: block; }
  .board-panel { padding: 8px; }
  .board-grid { gap: 4px; }
  .board-legend { margin: 10px 0 2px; font-size: 10px; gap: 10px; }

  .tile-number {
    top: 3px;
    left: 3px;
    min-width: 20px;
    height: 20px;
    padding: 0 4px;
    border-radius: 5px;
    font-size: 9px;
  }

  .tile-owner {
    top: 3px;
    right: 3px;
    padding: 3px 4px;
    border-radius: 4px;
    font-size: 7px;
  }

  .tile-title {
    left: 4px;
    right: 4px;
    bottom: 4px;
    font-size: 7px;
  }

  .details-panel {
    position: fixed;
    z-index: 30;
    left: 10px;
    right: 10px;
    bottom: 10px;
    top: auto;
    max-height: min(78vh, 720px);
    transform: translateY(calc(100% + 20px));
    transition: transform 180ms ease;
    box-shadow: 0 -12px 45px rgba(0,0,0,.55);
  }

  .details-panel.mobile-open { transform: translateY(0); }

  .details-empty { display: none; }

  .mobile-backdrop {
    position: fixed;
    z-index: 20;
    inset: 0;
    background: rgba(0,0,0,.64);
  }

  .mobile-backdrop:not([hidden]) { display: block; }

  .details-image-wrap {
    width: min(100%, 340px);
    margin: 0 auto;
  }

  .site-footer {
    flex-direction: column;
    gap: 4px;
  }
}

@media (max-width: 520px) {
  .site-header { align-items: flex-start; }
  .connection-wrap { margin-top: 5px; }
  .scorebar { grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); }
  .score-team span { font-size: 11px; }
  .score-team strong { font-size: 28px; }
  .score-center { font-size: 8px; }
  .board-legend { justify-content: space-between; }
  .tile-title { display: none; }
  .tile-owner { max-width: 56%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
