* {
  box-sizing: border-box;
}

:root {
  --felt-900: #0d0f1a;
  --felt-800: #151829;
  --felt-700: #1c2038;
  --felt-600: #262b48;
  --line: rgba(232, 179, 76, 0.16);
  --line-soft: rgba(255, 255, 255, 0.08);
  --brass: #e8b34c;
  --brass-strong: #f4c766;
  --coral: #ff6b6b;
  --mint: #4fd1a5;
  --sky: #4fa3d1;
  --ink: #f4f1e8;
  --ink-dim: #a8adc4;
  --ink-faint: #6b7191;
  --p1: #2f9eea;
  --p2: #16b46a;
  --p3: #e8b34c;
  --p4: #ff5b5b;
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --shadow-deep: 0 24px 60px rgba(0, 0, 0, 0.5);
  --shadow-soft: 0 12px 30px rgba(0, 0, 0, 0.35);
  --font-display: 'Baloo 2', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Manrope', 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
}
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  min-height: 100vh;

  background:
    radial-gradient(
      circle at 12% 15%,
      rgba(47, 158, 234, 0.12),
      transparent 28%
    ),
    radial-gradient(
      circle at 88% 15%,
      rgba(255, 91, 91, 0.10),
      transparent 28%
    ),
    radial-gradient(
      circle at 15% 85%,
      rgba(22, 180, 106, 0.09),
      transparent 28%
    ),
    radial-gradient(
      circle at 85% 85%,
      rgba(232, 179, 76, 0.10),
      transparent 28%
    ),
    linear-gradient(
      135deg,
      #080b14 0%,
      #0d1220 45%,
      #11162a 70%,
      #090c16 100%
    );

  background-attachment: fixed;
  background-size: cover;

  display: flex;
  flex-direction: column;
  overflow-x: hidden;

  position: relative;
}

button {
  font-family: inherit;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem clamp(1rem, 4vw, 2.5rem);
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(13, 15, 26, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.3rem 0.4rem;
  color: var(--ink);
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 8px);
  grid-template-rows: repeat(2, 8px);
  gap: 3px;
  transform: rotate(-8deg);
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 3px;
}

.brand-dot--a { background: var(--brass); grid-column: 1; grid-row: 1; }
.brand-dot--b { background: var(--coral); grid-column: 2; grid-row: 1 / span 2; border-radius: 50%; }
.brand-dot--c { background: var(--mint); grid-column: 1; grid-row: 2; }

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: 0.01em;
}

.site-nav {
  display: flex;
  gap: 0.4rem;
  background: var(--felt-800);
  padding: 0.35rem;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
}

.nav-pill {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: none;
  background: transparent;
  color: var(--ink-dim);
  padding: 0.55rem 1.05rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  min-height: 44px;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-pill:hover {
  color: var(--ink);
}

.nav-pill.is-active {
  background: var(--brass);
  color: #241a05;
}

.site-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.view {
  display: none;
  flex: 1;
  width: 100%;
}

.view.is-active {
  display: flex;
  flex-direction: column;
}

.view--home {
  align-items: center;
  padding: clamp(2rem, 6vw, 4.5rem) clamp(1.25rem, 5vw, 2.5rem) 3rem;
  gap: clamp(2rem, 5vw, 3rem);
}

.home-intro {
  max-width: 640px;
  text-align: center;
}

.home-intro h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.15;
  margin: 0 0 0.75rem;
  font-weight: 700;
}

.home-intro p {
  color: var(--ink-dim);
  font-size: clamp(1rem, 2vw, 1.15rem);
  margin: 0;
  line-height: 1.55;
}

.game-tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: clamp(1.25rem, 3vw, 2rem);
  width: 100%;
  max-width: 920px;
}

.game-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.1rem;
  text-align: left;
  background: linear-gradient(165deg, var(--felt-700), var(--felt-800));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: clamp(1.5rem, 3vw, 2.2rem);
  cursor: pointer;
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
  overflow: hidden;
  min-height: 260px;
}

.game-tile:hover,
.game-tile:focus-visible {
  transform: translateY(-6px);
  box-shadow: var(--shadow-deep);
}

.game-tile--ludo:hover { border-color: rgba(47, 158, 234, 0.5); }
.game-tile--ttt:hover { border-color: rgba(255, 107, 107, 0.5); }

.game-tile-swatches {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  width: 68px;
  height: 68px;
  border-radius: 18px;
  overflow: hidden;
  border: 3px solid rgba(0, 0, 0, 0.25);
}

.swatch--p1 { background: var(--p1); }
.swatch--p2 { background: var(--p2); }
.swatch--p3 { background: var(--p3); }
.swatch--p4 { background: var(--p4); }

.game-tile-grid {
  position: relative;
  width: 68px;
  height: 68px;
  flex-shrink: 0;
}

.grid-line {
  position: absolute;
  background: var(--ink-faint);
}

.grid-line--v1 { left: 33%; top: 4%; width: 2px; height: 92%; }
.grid-line--v2 { left: 66%; top: 4%; width: 2px; height: 92%; }
.grid-line--h1 { top: 33%; left: 4%; height: 2px; width: 92%; }
.grid-line--h2 { top: 66%; left: 4%; height: 2px; width: 92%; }

.grid-mark {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1;
}

.grid-mark--x { top: 8%; left: 10%; color: var(--sky); }
.grid-mark--o { bottom: 6%; right: 12%; color: var(--coral); }

.game-tile-body {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.game-tile-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
}

.game-tile-desc {
  color: var(--ink-dim);
  font-size: 0.95rem;
  line-height: 1.5;
}

.game-tile-cta {
  margin-top: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  color: var(--brass-strong);
  font-size: 0.95rem;
}

.cta-arrow {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.game-tile:hover .cta-arrow {
  transform: translateX(4px);
}

.view--game {
  padding: clamp(1.25rem, 4vw, 2rem) clamp(1rem, 4vw, 2rem) 2.5rem;
  align-items: center;
}

.game-shell {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(1rem, 3vw, 1.5rem);
  flex: 1;
}

.turn-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--felt-800);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 0.7rem 1.4rem;
  box-shadow: var(--shadow-soft);
}

.turn-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--brass);
  flex-shrink: 0;
  box-shadow: 0 0 0 4px rgba(232, 179, 76, 0.18);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.turn-text {
  font-size: clamp(1rem, 2.4vw, 1.2rem);
}

.turn-player {
  font-family: var(--font-display);
  font-weight: 700;
}

.turn-sub {
  color: var(--ink-dim);
}

.player-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
}

.player-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--felt-700);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-dim);
  transition: transform 0.18s ease, box-shadow 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.player-pill.is-active {
  color: var(--ink);
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
  border-color: var(--line);
}

.pill-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pill-dot--x { background: var(--sky); }
.pill-dot--o { background: var(--coral); }

.player-pill[data-player-id="P1"] .pill-dot { background: var(--p1); }
.player-pill[data-player-id="P2"] .pill-dot { background: var(--p2); }
.player-pill[data-player-id="P3"] .pill-dot { background: var(--p3); }
.player-pill[data-player-id="P4"] .pill-dot { background: var(--p4); }

.board-stage {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0.5rem 0;
}

.ludo-container {
  width: min(88vw, 480px);
  container-type: inline-size;
}

.ludo {
  width: 100%;
  aspect-ratio: 1 / 1;
  background-image: url('../assets/ludo-bg.jpg');
  background-size: cover;
  background-position: center;
  position: relative;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-deep);
  border: 1px solid var(--line-soft);
}

.player-pieces {
  height: 100%;
  width: 100%;
  position: relative;
}

.player-piece {
  width: 3%;
  height: 3%;
  border: 2px solid;
  border-radius: 30%;
  position: absolute;
  transform: translate(50%, 50%);
  transition: top 0.2s ease, left 0.2s ease;
  z-index: 1;
}

.player-piece.highlight {
  cursor: pointer;
  border: 2px dashed;
  animation: piece-spin 1s infinite linear;
}

@keyframes piece-spin {
  0% { transform: translate(50%, 50%) rotate(0deg); }
  50% { transform: translate(50%, 50%) rotate(180deg) scale(1.4); }
  100% { transform: translate(50%, 50%) rotate(360deg); }
}

.player-piece.player-inactive {
  display: none;
}

[player-id="P1"].player-piece { background-color: var(--p1); border-color: #0a4f7a; }
[player-id="P2"].player-piece { background-color: var(--p2); border-color: #0a5c34; }
[player-id="P3"].player-piece { background-color: var(--p3); border-color: #7a5a12; }
[player-id="P4"].player-piece { background-color: var(--p4); border-color: #7a1f1f; }

.player-base {
  width: 40%;
  height: 40%;
  border-style: solid;
  border-width: 7cqw;
  position: absolute;
}

.player-bases [player-id="P1"].player-base { bottom: 0; left: 0; border-color: var(--p1); }
.player-bases [player-id="P2"].player-base { top: 0; right: 0; border-color: var(--p2); }
.player-bases [player-id="P3"].player-base { top: 0; left: 0; border-color: var(--p3); }
.player-bases [player-id="P4"].player-base { bottom: 0; right: 0; border-color: var(--p4); }

.player-base.player-inactive {
  opacity: 0.25;
}

.player-base.highlight {
  animation: base-blink 0.9s infinite ease-in-out;
}

@keyframes base-blink {
  50% { border-color: rgba(255, 255, 255, 0.85); }
}

.dice-widget {
  position: absolute;
  width: 15cqw;
  height: 15cqw;
  max-width: 62px;
  max-height: 62px;
  min-width: 34px;
  min-height: 34px;
  padding: 3cqw;
  border-radius: 26%;
  background: rgba(10, 12, 20, 0.6);
  z-index: 2;
}

.dice-widget.player-inactive {
  display: none;
}

.dice-widget[player-id="P3"] { top: -3cqw; left: -3cqw; border: 3px solid var(--p3); }
.dice-widget[player-id="P2"] { top: -3cqw; right: -3cqw; border: 3px solid var(--p2); }
.dice-widget[player-id="P1"] { bottom: -3cqw; left: -3cqw; border: 3px solid var(--p1); }
.dice-widget[player-id="P4"] { bottom: -3cqw; right: -3cqw; border: 3px solid var(--p4); }

.btn-dice {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 22%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-dice::before {
  content: '\1F3B2';
  font-size: 7cqw;
  line-height: 1;
}

.btn-dice:disabled {
  opacity: 0.45;
  cursor: default;
}

[player-id="P1"].btn-dice { background-color: var(--p1); }
[player-id="P2"].btn-dice { background-color: var(--p2); }
[player-id="P3"].btn-dice { background-color: var(--p3); }
[player-id="P4"].btn-dice { background-color: var(--p4); }

.btn-dice:not(:disabled) {
  box-shadow: 0 0 0 3px rgba(244, 199, 102, 0.85);
}

.btn-dice.rolling {
  animation: dice-spin 0.6s ease-out;
}

@keyframes dice-spin {
  from { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.2); }
  to { transform: rotate(360deg) scale(1); }
}

.dice-value {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 3px;
  border-radius: 50%;
  background: #1a1c26;
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
  border: 2px solid var(--felt-900);
}

.ttt-board {
  position: relative;
  width: min(84vw, 380px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(6px, 2vw, 12px);
  padding: clamp(10px, 2.5vw, 16px);
  background: var(--felt-800);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-deep);
  container-type: inline-size;
}

.ttt-cell {
  background: var(--felt-700);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-size: 15cqw;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.ttt-cell:not(:disabled):hover {
  background: var(--felt-600);
}

.ttt-cell:disabled {
  cursor: default;
}

.ttt-cell.mark-x { color: var(--sky); }
.ttt-cell.mark-o { color: var(--coral); }

.ttt-cell.mark-x, .ttt-cell.mark-o {
  animation: mark-pop 0.18s ease;
}

@keyframes mark-pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.ttt-line {
  position: absolute;
  height: 4px;
  background: var(--brass-strong);
  border-radius: 4px;
  display: none;
  transform-origin: 0 50%;
  box-shadow: 0 0 12px rgba(244, 199, 102, 0.7);
}

.ttt-line.is-visible {
  display: block;
}

.game-actions {
  display: flex;
  gap: 0.75rem;
}

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.5rem;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  min-height: 46px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--brass);
  color: #241a05;
  box-shadow: var(--shadow-soft);
}

.btn-primary:hover {
  background: var(--brass-strong);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--line-soft);
  color: var(--ink-dim);
}

.btn-outline:hover {
  color: var(--ink);
  border-color: var(--line);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 13, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 100;
}

.modal-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: linear-gradient(165deg, var(--felt-700), var(--felt-800));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: clamp(1.75rem, 4vw, 2.5rem);
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-deep);
  transform: translateY(12px) scale(0.97);
  transition: transform 0.2s ease;
}

.modal-overlay.is-visible .modal-card {
  transform: translateY(0) scale(1);
}

.modal-icon {
  font-size: 2.75rem;
  margin-bottom: 0.5rem;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0 0 0.5rem;
}

.modal-message {
  color: var(--ink-dim);
  margin: 0 0 1.5rem;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

@media (max-width: 720px) {
  .game-tiles {
    grid-template-columns: 1fr;
    max-width: 420px;
  }

  .game-tile {
    min-height: 200px;
  }
}

@media (max-width: 560px) {
  .site-header {
    padding: 0.85rem 1rem;
  }

  .brand-name {
    font-size: 1.1rem;
  }

  .nav-pill span:last-child {
    display: none;
  }

  .nav-pill {
    padding: 0.6rem 0.7rem;
  }

  .nav-icon {
    width: 20px;
    height: 20px;
  }

  .turn-banner {
    width: 100%;
    justify-content: center;
  }

  .player-strip {
    width: 100%;
  }
}

@media (max-width: 380px) {
  .ludo-container {
    width: 92vw;
  }

  .ttt-board {
    width: 88vw;
  }
}

@media (min-width: 900px) {
  .ludo-container {
    width: min(46vw, 520px);
  }

  .ttt-board {
    width: min(38vw, 440px);
  }
}

.is-hidden {
  display: none !important;
}

.ludo-setup {
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.ludo-setup-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(165deg, var(--felt-700), var(--felt-800));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: clamp(1.5rem, 4vw, 2.25rem);
  box-shadow: var(--shadow-deep);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.ludo-setup-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin: 0;
  text-align: center;
}

.ludo-setup-count {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
}

.count-btn {
  flex: 1;
  min-width: 100px;
  border: 1px solid var(--line-soft);
  background: var(--felt-600);
  color: var(--ink-dim);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 46px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.count-btn:hover {
  color: var(--ink);
  border-color: var(--line);
}

.count-btn.is-active {
  background: var(--brass);
  color: #241a05;
  border-color: var(--brass);
  box-shadow: var(--shadow-soft);
}

.ludo-setup-names {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.setup-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.setup-field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-dim);
}

.setup-field input {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--felt-600);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  min-height: 46px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.setup-field input:focus {
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(232, 179, 76, 0.18);
}

.ludo-setup-start {
  width: 100%;
}

body.app-fullscreen {
  overflow: hidden;
}

body.app-fullscreen .site-header {
  display: none;
}

body.app-fullscreen .site-main {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--felt-900);
  display: flex;
}

body.app-fullscreen .view--home,
body.app-fullscreen #view-ludo:not(.is-active),
body.app-fullscreen #view-ttt:not(.is-active) {
  display: none !important;
}

body.app-fullscreen .view--game.is-active {
  flex: 1;
  display: flex;
  padding: clamp(0.5rem, 2vh, 1.25rem);
  overflow-y: auto;
}

body.app-fullscreen .game-shell {
  max-width: none;
  width: 100%;
  height: 100%;
  justify-content: center;
}

body.app-fullscreen .ludo-container {
  width: min(88vh, 92vw, 640px);
}

body.app-fullscreen .ttt-board {
  width: min(78vh, 92vw, 480px);
}

body.app-fullscreen .board-stage {
  flex: 1 1 auto;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

.footer {
    margin-top: auto;
    padding: 22px 20px;
    text-align: center;
    color: var(--ink-faint);
    font-size: 14px;
}

.footer span {
    color: var(--brass);
    font-weight: 700;
}