:root {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

body {
  margin: 0;
  background: #0b0f14;
  color: #e9eef5;
}

.top {
  padding: 14px 16px;
  border-bottom: 1px solid #1d2a3a;
  background: #0e141c;
  display: grid;
  gap: 10px;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.4px;
}

.roombar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.roombar input {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #223247;
  background: #0b0f14;
  color: #e9eef5;
  outline: none;
}

button {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #223247;
  background: #111a25;
  color: #e9eef5;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 14px;
  color: #b9c7d9;
}

main {
  padding: 18px 16px 24px;
}

.ultimate {
  margin: 0 auto;
  width: min(92vw, 720px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.ultimate.turn-me {
  --hl: #2ecc71;
  --hl-glow: rgba(46, 204, 113, 0.6);
}

.ultimate.turn-them {
  --hl: #ff4d4d;
  --hl-glow: rgba(255, 77, 77, 0.6);
}

.ultimate.free-move {
  position: relative;
}

.ultimate.free-move::after {
  content: "";
  position: absolute;
  inset: -16px;
  border-radius: 24px;
  pointer-events: none;

  box-shadow:
    0 0 0 3px var(--hl),
    0 0 30px var(--hl-glow),
    0 0 60px var(--hl-glow);

  animation: pulseBoard 2s infinite ease-in-out;
}

@keyframes pulseBoard {
  0% {
    box-shadow:
      0 0 0 3px var(--hl),
      0 0 20px var(--hl-glow),
      0 0 50px var(--hl-glow);
  }
  50% {
    box-shadow:
      0 0 0 4px var(--hl),
      0 0 40px var(--hl-glow),
      0 0 80px var(--hl-glow);
  }
  100% {
    box-shadow:
      0 0 0 3px var(--hl),
      0 0 20px var(--hl-glow),
      0 0 50px var(--hl-glow);
  }
}

.mini {
  border: 2px solid #223247;
  border-radius: 14px;
  background: #0e141c;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  position: relative;
}

.mini.forced {
  position: relative;
  z-index: 1;
  box-shadow:
    0 0 0 2px var(--hl),
    0 0 18px var(--hl-glow),
    0 0 35px var(--hl-glow);
  animation: pulseMini 1.8s infinite ease-in-out;
}

@keyframes pulseMini {
  0% {
    box-shadow:
      0 0 0 2px var(--hl),
      0 0 10px var(--hl-glow),
      0 0 25px var(--hl-glow);
  }
  50% {
    box-shadow:
      0 0 0 3px var(--hl),
      0 0 25px var(--hl-glow),
      0 0 50px var(--hl-glow);
  }
  100% {
    box-shadow:
      0 0 0 2px var(--hl),
      0 0 10px var(--hl-glow),
      0 0 25px var(--hl-glow);
  }
}

.cell {
  border: 1px solid #223247;
  border-radius: 12px;
  background: #0b0f14;

  /* tärkeimmät fixit */
  aspect-ratio: 1 / 1;
  width: 100%;
  line-height: 1;

  display: grid;
  place-items: center;

  font-size: clamp(18px, 3.2vw, 34px);
  user-select: none;
  cursor: pointer;

  /* poista min-height: 0 - ei tarvita enää */
}

.cell.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.badge {
  position: absolute;
  inset: 10px;
  display: grid;
  place-items: center;
  font-size: clamp(40px, 8vw, 82px);
  font-weight: 800;
  opacity: 0.18;
  pointer-events: none;
}

.foot {
  padding: 12px 16px;
  border-top: 1px solid #1d2a3a;
  color: #9fb1c8;
  font-size: 13px;
}

/* =========================================
   MINI BOARD COVER (overlay)
========================================= */

.mini {
  position: relative; /* tärkeä overlaylle */
}

.mini.locked {
  /* ei pakko, mutta tekee "lukitun" fiiliksen */
  filter: saturate(0.9) brightness(0.95);
}

/* Cover on aina päällä ja blokkaa klikit */
.mini-cover {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  display: grid;
  place-items: center;
  pointer-events: auto; /* varmistaa että se nappaa klikit */
  z-index: 5;

  /* “kansi”: vähän blur + tumma lasi */
  background: rgba(10, 15, 20, 0.58);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);

  /* reunat ja varjo */
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,0.06),
    inset 0 0 25px rgba(0,0,0,0.35);

  animation: coverIn 180ms ease-out;
}

@keyframes coverIn {
  from { opacity: 0; transform: scale(0.98); }
  to   { opacity: 1; transform: scale(1); }
}

.mini-cover-label {
  font-weight: 900;
  letter-spacing: 2px;
  font-size: clamp(28px, 6vw, 64px);
  text-shadow:
    0 0 18px rgba(0,0,0,0.55),
    0 0 35px rgba(0,0,0,0.35);
}

/* X voitti */
.mini-cover.won-x {
  background:
    radial-gradient(circle at 50% 45%, rgba(46,204,113,0.28), rgba(10,15,20,0.65) 70%),
    rgba(10, 15, 20, 0.45);
}
.mini-cover.won-x .mini-cover-label {
  color: #2ecc71;
  text-shadow:
    0 0 16px rgba(46,204,113,0.55),
    0 0 38px rgba(46,204,113,0.35),
    0 0 10px rgba(0,0,0,0.6);
}

/* O voitti */
.mini-cover.won-o {
  background:
    radial-gradient(circle at 50% 45%, rgba(255,77,77,0.26), rgba(10,15,20,0.65) 70%),
    rgba(10, 15, 20, 0.45);
}
.mini-cover.won-o .mini-cover-label {
  color: #ff4d4d;
  text-shadow:
    0 0 16px rgba(255,77,77,0.55),
    0 0 38px rgba(255,77,77,0.35),
    0 0 10px rgba(0,0,0,0.6);
}

/* =========================================
   PLAYER RELATIVE COLORS
========================================= */

.mini-cover.won-me {
  background:
    radial-gradient(circle at 50% 45%, rgba(46,204,113,0.28), rgba(10,15,20,0.65) 70%),
    rgba(10, 15, 20, 0.45);
}

.mini-cover.won-me .mini-cover-label {
  color: #2ecc71;
  text-shadow:
    0 0 16px rgba(46,204,113,0.55),
    0 0 38px rgba(46,204,113,0.35),
    0 0 10px rgba(0,0,0,0.6);
}

.mini-cover.won-them {
  background:
    radial-gradient(circle at 50% 45%, rgba(255,77,77,0.26), rgba(10,15,20,0.65) 70%),
    rgba(10, 15, 20, 0.45);
}

.mini-cover.won-them .mini-cover-label {
  color: #ff4d4d;
  text-shadow:
    0 0 16px rgba(255,77,77,0.55),
    0 0 38px rgba(255,77,77,0.35),
    0 0 10px rgba(0,0,0,0.6);
}


/* Tasapeli */
.mini-cover.draw {
  background:
    radial-gradient(circle at 50% 45%, rgba(200,200,200,0.16), rgba(10,15,20,0.68) 70%),
    rgba(10, 15, 20, 0.45);
}
.mini-cover.draw .mini-cover-label {
  color: #c9d2df;
  font-size: clamp(14px, 2.6vw, 22px);
  letter-spacing: 3px;
}

.mark {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.mark svg {
  width: 70%;
  height: 70%;
  stroke: currentColor;
  stroke-width: 10;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.mark.x { color: #e9eef5; }
.mark.o { color: #e9eef5; }

.mini.boom::before,
.mini.boom::after {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 18px;
  pointer-events: none;
  z-index: 6;
}

.mini.boom::before {
  background:
    radial-gradient(circle, rgba(255,255,255,0.35) 0 8%, transparent 10% 100%),
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.18), transparent 60%),
    radial-gradient(circle at 80% 70%, rgba(255,255,255,0.18), transparent 60%);
  filter: blur(0.2px);
  animation: boomFlash 520ms ease-out;
}

.mini.boom::after {
  background:
    radial-gradient(circle at 15% 50%, rgba(255,255,255,0.35), transparent 60%),
    radial-gradient(circle at 85% 50%, rgba(255,255,255,0.35), transparent 60%),
    radial-gradient(circle at 50% 15%, rgba(255,255,255,0.35), transparent 60%),
    radial-gradient(circle at 50% 85%, rgba(255,255,255,0.35), transparent 60%);
  opacity: 0.9;
  animation: boomRing 650ms ease-out;
}

@keyframes boomFlash {
  from { opacity: 0; transform: scale(0.92); }
  20% { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(1.06); }
}

@keyframes boomRing {
  from { opacity: 0.0; transform: scale(0.85); }
  35% { opacity: 0.9; transform: scale(1.02); }
  to { opacity: 0; transform: scale(1.18); }
}

#winOverlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.0);
  pointer-events: none;
  opacity: 0;
  z-index: 9999;
}

#winOverlay.show {
  opacity: 1;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#winOverlay .winCard {
  width: min(86vw, 460px);
  border-radius: 22px;
  padding: 18px 18px 16px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(12, 18, 26, 0.78);
  box-shadow:
    0 20px 70px rgba(0,0,0,0.55),
    inset 0 0 0 1px rgba(255,255,255,0.06);
  transform: translateY(10px) scale(0.96);
}

#winOverlay.show .winCard {
  animation: winIn 520ms ease-out;
  transform: none;
}

@keyframes winIn {
  from { transform: translateY(16px) scale(0.94); opacity: 0; }
  55% { transform: translateY(-2px) scale(1.02); opacity: 1; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

#winOverlay .winTitle {
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #dbe6f5;
  margin-bottom: 10px;
}

#winOverlay .winMark {
  display: grid;
  place-items: center;
  height: 140px;
}

#winOverlay .winMark svg {
  width: 120px;
  height: 120px;
  stroke: currentColor;
  stroke-width: 10;
  fill: none;
}

#winOverlay .winSub {
  margin-top: 6px;
  color: #b9c7d9;
  font-size: 14px;
}

/* Winner themes + glow */
#winOverlay.x .winCard { color: #2ecc71; box-shadow: 0 20px 80px rgba(46,204,113,0.18), 0 20px 70px rgba(0,0,0,0.55); }
#winOverlay.o .winCard { color: #ff4d4d; box-shadow: 0 20px 80px rgba(255,77,77,0.18), 0 20px 70px rgba(0,0,0,0.55); }
#winOverlay.draw .winCard { color: #c9d2df; }