/*
 * Punchess Arena - Chess Arena Theme Design System
 * Issue #45: Re-theme the Punchess site as a polished chess arena
 */

:root {
  --color-primary-500: #2c5aa0;
  --color-primary-600: #1f4276;
  --color-primary-700: #18355e;
  --color-wood-dark: #3d2817;
  --color-success-500: #1e7d4b;
  --color-warning-500: #9a6200;
  --color-error-500: #b3261e;

  --bg-base: #0d1219;
  --bg-surface-1: #141b25;
  --bg-surface-2: #1b2430;
  --bg-surface-3: #232e3c;
  --bg-focus: rgba(82, 130, 187, 0.25);

  --border-base: rgba(101, 118, 138, 0.25);
  --border-light: rgba(101, 118, 138, 0.15);

  --text-base: #e8edf3;
  --text-muted: #9aa7b5;
  --text-subtle: #6f7b8a;

  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.45);

  --brand: var(--color-primary-600);
  --brand-hover: var(--color-primary-700);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", Consolas, monospace;
  --font-display: "Playfair Display", Georgia, serif;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;

  --space-4: 0.5rem;
  --space-6: 0.75rem;
  --space-8: 1rem;
  --space-10: 1.25rem;
  --space-12: 1.5rem;
  --space-16: 2rem;
  --space-20: 2.5rem;

  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;

  --board-size: clamp(280px, 85vw, 640px);
  --board-light-sq: #f0d9b5;
  --board-dark-sq: #b58863;
  --board-move-highlight: rgba(68, 129, 68, 0.75);
  --board-check-highlight: rgba(200, 50, 50, 0.85);

  --header-height: 4rem;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-base: #f3f5f9;
    --bg-surface-1: #ffffff;
    --bg-surface-2: #eef1f6;
    --bg-surface-3: #e3e7f0;
    --border-base: rgba(28, 37, 48, 0.14);
    --border-light: rgba(28, 37, 48, 0.08);
    --text-base: #141b25;
    --text-muted: #5c6876;
    --text-subtle: #828d9a;
  }
}

[data-theme="light"] {
  --bg-base: #f3f5f9;
  --bg-surface-1: #ffffff;
  --bg-surface-2: #eef1f6;
  --bg-surface-3: #e3e7f0;
  --border-base: rgba(28, 37, 48, 0.14);
  --border-light: rgba(28, 37, 48, 0.08);
  --text-base: #141b25;
  --text-muted: #5c6876;
  --text-subtle: #828d9a;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text-base);
  background-color: var(--bg-base);
  min-height: 100vh;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-base);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

p { margin-bottom: var(--space-6); color: var(--text-muted); }

a {
  color: var(--color-primary-500);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: #83a4cf; }
a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--bg-focus);
}

strong { font-weight: 600; color: var(--text-base); }

code, kbd, pre { font-family: var(--font-mono); }

code {
  font-size: 0.875em;
  padding: 0.125em 0.375em;
  border-radius: 0.25rem;
  background: var(--bg-surface-3);
  color: #83a4cf;
}

pre {
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  background: var(--bg-surface-3);
  color: var(--text-base);
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: 1.75;
  margin: var(--space-6) 0;
}
pre code { padding: 0; background: transparent; color: inherit; }

/* Layout */
.punchess-container {
  width: 100%;
  max-width: 1344px;
  margin: 0 auto;
  padding: 0 var(--space-8);
}

.punchess-grid { display: grid; gap: var(--space-8); }
.punchess-grid--2 { grid-template-columns: repeat(2, 1fr); }
.punchess-grid--3 { grid-template-columns: repeat(3, 1fr); }
.punchess-grid--auto { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

@media (max-width: 1024px) {
  .punchess-grid--3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .punchess-grid--2, .punchess-grid--3, .punchess-grid--auto { grid-template-columns: 1fr; }
}

/* Header */
.ph-header {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--header-height);
  background: var(--bg-surface-1);
  border-bottom: 1px solid var(--border-base);
  backdrop-filter: saturate(180%) blur(12px);
}

.ph-header__inner {
  height: 100%;
  max-width: 1344px;
  margin: 0 auto;
  padding: 0 var(--space-8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
}

.ph-logo {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-base);
  text-decoration: none;
}

.ph-logo__icon {
  width: 2rem;
  height: 2rem;
  background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-700));
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
}

.ph-logo__text {
  background: linear-gradient(135deg, var(--text-base), #83a4cf);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Buttons */
.ph-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1.25rem;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  color: #fff;
  background-color: var(--brand);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.ph-btn:hover {
  background-color: var(--brand-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.ph-btn:active { transform: translateY(0); }
.ph-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--bg-focus); }
.ph-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.ph-btn--primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-hover));
  box-shadow: 0 2px 8px rgba(44, 90, 160, 0.3);
}

.ph-btn--secondary {
  background: var(--bg-surface-2);
  color: var(--text-base);
  border-color: var(--border-base);
}

.ph-btn--secondary:hover {
  background: var(--bg-surface-3);
}

.ph-btn--ghost {
  background: transparent;
  color: var(--text-base);
}

.ph-btn--danger {
  background: linear-gradient(135deg, var(--color-error-500), #911d17);
}

.ph-btn--size-sm { padding: 0.375rem 1rem; font-size: var(--text-xs); }
.ph-btn--size-lg { padding: 0.75rem 1.75rem; font-size: var(--text-base); }

/* Cards */
.ph-card {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  transition: all var(--transition-fast);
}

.ph-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.ph-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}

.ph-card__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-base);
  margin: 0;
}

/* Forms */
.ph-field { margin-bottom: var(--space-8); }

.ph-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-base);
  margin-bottom: 0.25rem;
}

.ph-label--required::after {
  content: " *";
  color: var(--color-error-500);
}

.ph-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-base);
  background: var(--bg-surface-3);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.ph-input::placeholder { color: var(--text-subtle); }
.ph-input:hover { border-color: var(--border-light); }
.ph-input:focus {
  outline: none;
  border-color: #5280bb;
  box-shadow: 0 0 0 3px var(--bg-focus);
}
.ph-input:disabled { opacity: 0.5; cursor: not-allowed; }

/* Badges */
.ph-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1875rem 0.625rem;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  background: var(--bg-surface-3);
  color: var(--text-base);
  border: 1px solid var(--border-base);
}

.ph-badge--active {
  background: rgba(30, 125, 75, 0.15);
  color: #37a86a;
  border-color: rgba(30, 125, 75, 0.3);
}

.ph-badge--warning {
  background: rgba(154, 98, 0, 0.15);
  color: #c48a00;
  border-color: rgba(154, 98, 0, 0.3);
}

.ph-badge--error {
  background: rgba(179, 38, 30, 0.15);
  color: #d94840;
  border-color: rgba(179, 38, 30, 0.3);
}

/* Tables */
.ph-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }

.ph-table th, .ph-table td {
  padding: var(--space-4) var(--space-6);
  text-align: left;
  border-bottom: 1px solid var(--border-base);
}

.ph-table th {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  background: var(--bg-surface-2);
}

.ph-table tr { transition: background-color var(--transition-fast); }
.ph-table tr:hover { background: rgba(255, 255, 255, 0.03); }
.ph-table tr:last-child td { border-bottom: none; }

/* Lobby */
.ph-lobby {
  max-width: 1120px;
  margin: 0 auto;
  padding: var(--space-10) var(--space-8);
}

.ph-lobby__hero {
  text-align: center;
  padding: var(--space-20) var(--space-10);
  background: linear-gradient(180deg, var(--bg-surface-2) 0%, var(--bg-base) 100%);
  border-radius: var(--radius-2xl);
  border: 1px solid var(--border-base);
  margin-bottom: var(--space-16);
}

.ph-lobby__title {
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  font-weight: 700;
  background: linear-gradient(135deg, var(--text-base), #83a4cf);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-6);
}

.ph-lobby__subtitle {
  font-size: var(--text-lg);
  color: var(--text-muted);
  max-width: 560px;
  margin: 0 auto var(--space-10);
}

.ph-lobby__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  justify-content: center;
}

/* Game view */
.ph-game {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: var(--space-10);
  max-width: 1344px;
  margin: 0 auto;
  padding: var(--space-10);
}

@media (max-width: 1100px) {
  .ph-game { grid-template-columns: 1fr; }
}

.ph-game__board {
  background: var(--bg-surface-2);
  padding: var(--space-8);
  border-radius: var(--radius-2xl);
  border: 1px solid var(--border-base);
}

/* Board */
.ph-chessboard {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: var(--board-size);
  height: var(--board-size);
  margin: 0 auto;
  border: 3px solid var(--color-wood-dark);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.ph-square {
  display: grid;
  place-items: center;
  position: relative;
  font-size: calc(var(--board-size) / 18);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.ph-square--light { background-color: var(--board-light-sq); }
.ph-square--dark { background-color: var(--board-dark-sq); }
.ph-square--last-move { box-shadow: inset 0 0 0 4px var(--board-move-highlight); }
.ph-square--check { box-shadow: inset 0 0 0 4px var(--board-check-highlight); }

.ph-coord {
  position: absolute;
  font-size: calc(var(--board-size) / 24);
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-subtle);
  pointer-events: none;
}
.ph-coord--rank { top: 2px; left: 2px; }
.ph-coord--file { bottom: 2px; right: 2px; }

/* Player cards */
.ph-player-card {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  transition: all var(--transition-fast);
}

.ph-player-card--active {
  border-color: var(--brand);
  background: var(--bg-focus);
}

.ph-player-card--winner {
  border-color: var(--color-success-500);
  box-shadow: 0 0 0 2px rgba(30, 125, 75, 0.4);
}

.ph-player-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-700));
  display: grid;
  place-items: center;
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-lg);
}

.ph-player-name {
  font-weight: 600;
  color: var(--text-base);
  margin-bottom: 0.125rem;
}

.ph-player-clock {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-base);
  text-align: center;
  min-width: 96px;
  padding: var(--space-4);
  background: var(--bg-surface-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-base);
}

.ph-player-clock--active {
  border-color: var(--brand);
  color: var(--brand);
}

.ph-player-clock--time-warning { color: var(--color-warning-500); }
.ph-player-clock--time-critical { color: var(--color-error-500); }

/* Game info panel */
.ph-game__info {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
}

.ph-game-status {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 600;
}

.ph-game-status--active {
  background: rgba(30, 125, 75, 0.12);
  color: var(--color-success-500);
}

.ph-game-status--pending {
  background: rgba(154, 98, 0, 0.12);
  color: #c48a00;
}

/* Move list */
.ph-moves {
  display: grid;
  grid-template-columns: 56px 1fr 1fr;
  gap: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  max-height: 280px;
  overflow-y: auto;
  padding-right: var(--space-4);
}

.ph-moves__number { color: var(--text-subtle); text-align: right; }

.ph-moves__move {
  padding: 0.25rem 0.375rem;
  border-radius: 0.25rem;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.ph-moves__move:hover { background: var(--bg-surface-3); }
.ph-moves__move--last {
  background: var(--bg-surface-3);
  color: var(--text-base);
  font-weight: 600;
}

/* Result banner */
.ph-result-banner {
  text-align: center;
  padding: var(--space-12);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-2xl);
  margin-bottom: var(--space-12);
}

.ph-result-banner__result {
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  font-weight: 700;
  margin-bottom: var(--space-4);
}

/* Loading / Empty */
.ph-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.ph-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-light);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.ph-empty {
  text-align: center;
  padding: var(--space-20);
  background: var(--bg-surface-2);
  border: 1px dashed var(--border-base);
  border-radius: var(--radius-xl);
}

.ph-empty__icon {
  font-size: var(--text-4xl);
  color: var(--text-subtle);
  margin-bottom: var(--space-6);
}

.ph-empty__title {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-2);
}

/* Error */
.ph-error {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-6);
  background: rgba(179, 38, 30, 0.08);
  border: 1px solid rgba(179, 38, 30, 0.25);
  border-radius: var(--radius-md);
  color: #d94840;
}

/* Utilities */
.ph-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ph-text-center { text-align: center; }
.ph-text-muted { color: var(--text-muted); }
.ph-text-subtle { color: var(--text-subtle); }
.ph-mono { font-family: var(--font-mono); }
.ph-bold { font-weight: 700; }
.ph-mb-0 { margin-bottom: 0; }
.ph-mb-4 { margin-bottom: var(--space-4); }
.ph-mb-6 { margin-bottom: var(--space-6); }
.ph-mb-8 { margin-bottom: var(--space-8); }
.ph-mt-4 { margin-top: var(--space-4); }
.ph-pb-6 { padding-bottom: var(--space-6); }
.ph-flex { display: flex; }
.ph-flex-center { display: flex; align-items: center; justify-content: center; }
.ph-flex-between { display: flex; align-items: center; justify-content: space-between; }
.ph-flex-wrap { flex-wrap: wrap; }
.ph-grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.ph-border { border: 1px solid var(--border-base); }
.ph-border-b { border-bottom: 1px solid var(--border-base); }
.ph-radius-md { border-radius: var(--radius-md); }
.ph-radius-xl { border-radius: var(--radius-xl); }
.ph-shadow-md { box-shadow: var(--shadow-md); }

/* Accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--bg-focus);
}

@media (forced-colors: active) {
  .ph-btn, .ph-card, .ph-square {
    border: 2px solid currentColor;
  }
}

@media print {
  .ph-header, .ph-game-controls { display: none; }
  .ph-game { grid-template-columns: 1fr; }
  body { background: white; color: black; }
}

.broadcast-frame { position: relative; width: 100%; max-width: 100%; aspect-ratio: 16 / 9; background: #000; }
.broadcast-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Chess board table */
#board {
  border-collapse: collapse;
  border: 3px solid var(--color-wood-dark);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  width: var(--board-size);
  height: var(--board-size);
  margin: 0 auto;
}
#board td {
  width: 12.5%;
  height: 12.5%;
  text-align: center;
  vertical-align: middle;
  font-size: calc(var(--board-size) / 18);
  padding: 0;
  line-height: 1;
}
#board td.light { background-color: var(--board-light-sq); color: inherit; }
#board td.dark  { background-color: var(--board-dark-sq); color: inherit; }

/* Reports list */
#reports {
  list-style: none;
  padding: 0;
  margin: 0;
}
#reports li {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-base);
  font-size: var(--text-sm);
  color: var(--text-muted);
}
#reports li:last-child { border-bottom: none; }

/* Select styling */
select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-base);
  background: var(--bg-surface-3);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236f7b8a' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}
select:focus {
  outline: none;
  border-color: #5280bb;
  box-shadow: 0 0 0 3px var(--bg-focus);
}

/* Footer */
.ph-footer {
  background: var(--bg-surface-1);
  border-top: 1px solid var(--border-base);
}
