/* ============================================
   Connect Four - Styles
   ============================================ */

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

body {
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 77, 94, 0.14), transparent 45%),
    radial-gradient(circle at 80% 90%, rgba(255, 210, 63, 0.12), transparent 45%),
    linear-gradient(160deg, #10142a 0%, #0b0e1e 60%, #080a16 100%) fixed;
  color: #fff;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
  touch-action: pan-y;
}

#app {
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 40px;
}

/* ── HUD ── */

#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 520px;
  margin-bottom: 16px;
  gap: 12px;
}

.hud-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 80px;
}

.hud-disc {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 0;
  box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.3), inset 0 2px 3px rgba(255, 255, 255, 0.45), 0 3px 8px rgba(0, 0, 0, 0.35);
}

.hud-disc.red, .turn-disc.red, .ghost-disc.red { background: radial-gradient(circle at 35% 30%, #ff9aa3, #ff4d5e 45%, #c41e3a); }
.hud-disc.yellow, .turn-disc.yellow, .ghost-disc.yellow { background: radial-gradient(circle at 35% 30%, #fff1a8, #ffd23f 45%, #d9a300); }

.hud-name {
  font-size: 12px;
  color: #888;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.hud-score {
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

#hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
}

#turn-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #ccc;
  white-space: nowrap;
}

.turn-disc {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
  transition: background 0.3s;
}


#hud-buttons {
  display: flex;
  gap: 8px;
}

#hud-buttons button {
  padding: 5px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: #c4c8de;
  cursor: pointer;
  transition: all 0.2s;
}

#hud-buttons button:hover {
  border-color: #00d4ff;
  color: #00d4ff;
}

#hud-buttons button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ── Board ── */

#board-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

#ghost-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  width: 100%;
  max-width: 490px;
  height: 50px;
}

.ghost-cell {
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.ghost-disc {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.15s, transform 0.15s;
  box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.3), inset 0 2px 3px rgba(255, 255, 255, 0.45);
}

.ghost-cell:hover .ghost-disc,
.ghost-cell.touch-hover .ghost-disc,
.ghost-cell.kb-hover .ghost-disc {
  opacity: 0.85;
  transform: translateY(0);
  animation: ghost-bob 0.9s ease-in-out infinite alternate;
}

@keyframes ghost-bob {
  from { transform: translateY(-3px); }
  to { transform: translateY(3px); }
}

#board {
  --gap: 6px;
  --frame: #2a5bd7;
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: var(--gap);
  padding: 12px;
  background: linear-gradient(180deg, #3a6cf0, var(--frame) 30%, #1f47b8);
  border-radius: 18px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55), inset 0 2px 0 rgba(255, 255, 255, 0.35), inset 0 -4px 0 rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 490px;
  aspect-ratio: 7 / 6;
}

.cell {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #121733, #070914);
  cursor: pointer;
}

.cell::after {
  content: '';
  position: absolute;
  inset: calc(var(--gap) / -2 - 0.5px);
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(circle closest-side, transparent calc(100% - var(--gap) / 2 - 1px), rgba(0, 0, 0, 0.35) calc(100% - var(--gap) / 2), rgba(255, 255, 255, 0.28) calc(100% - var(--gap) / 2 + 2px), transparent calc(100% - var(--gap) / 2 + 5px)),
    var(--frame);
  -webkit-mask: radial-gradient(circle closest-side, transparent calc(100% - var(--gap) / 2 - 0.5px), #000 calc(100% - var(--gap) / 2 + 0.5px));
  mask: radial-gradient(circle closest-side, transparent calc(100% - var(--gap) / 2 - 0.5px), #000 calc(100% - var(--gap) / 2 + 0.5px));
}

.cell:hover::after { background-color: #3266e6; }

.cell .disc {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  border-radius: 50%;
  transform: translateY(-700%);
  opacity: 0;
}

.cell .disc::after {
  content: '';
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.28), 0 1px 0 rgba(255, 255, 255, 0.3);
}

.cell .disc.dropped {
  opacity: 1;
  animation: dropDisc 0.45s linear forwards;
}

.cell .disc.lifted {
  opacity: 1;
  animation: liftDisc 0.26s ease-in forwards;
}

@keyframes liftDisc {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(calc(-1 * (var(--row, 0) + 1.3) * (100% + var(--gap)))); opacity: 0; }
}

.cell .disc.no-anim {
  opacity: 1;
  transform: translateY(0);
  animation: none;
}

.cell .disc.red {
  background: radial-gradient(circle at 35% 30%, #ffb3ba, #ff4d5e 42%, #c41e3a 78%, #8f1229);
  box-shadow: inset 0 -4px 7px rgba(0, 0, 0, 0.32), inset 0 3px 4px rgba(255, 255, 255, 0.45);
}

.cell .disc.yellow {
  background: radial-gradient(circle at 35% 30%, #fff6c2, #ffd23f 42%, #d9a300 78%, #9c7400);
  box-shadow: inset 0 -4px 7px rgba(0, 0, 0, 0.28), inset 0 3px 4px rgba(255, 255, 255, 0.55);
}

@keyframes dropDisc {
  0% { transform: translateY(calc(-1 * (var(--row, 0) + 1.2) * (100% + var(--gap)))); animation-timing-function: cubic-bezier(.55, 0, 1, .45); }
  62% { transform: translateY(0) scale(1.06, 0.88); animation-timing-function: ease-out; }
  76% { transform: translateY(-14%) scale(0.97, 1.03); animation-timing-function: ease-in; }
  88% { transform: translateY(0) scale(1.02, 0.96); animation-timing-function: ease-out; }
  94% { transform: translateY(-4%); animation-timing-function: ease-in; }
  100% { transform: translateY(0); }
}

#board.draw-shake { animation: draw-shake 0.6s ease-out; }

@keyframes draw-shake {
  15%, 55% { transform: rotate(-1deg); }
  35%, 75% { transform: rotate(1deg); }
}

#win-line {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  overflow: visible;
  opacity: 0;
}

#win-line line {
  stroke: rgba(255, 255, 255, 0.92);
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.9)) drop-shadow(0 0 14px rgba(120, 200, 255, 0.8));
}

#win-line.show { opacity: 1; }
#win-line.show line { animation: draw-line 0.5s ease-out 0.25s forwards; }

@keyframes draw-line {
  to { stroke-dashoffset: 0; }
}

#fx-layer { position: absolute; z-index: 4; pointer-events: none; overflow: visible; }

.fx-confetti {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  animation: confetti 1.8s cubic-bezier(.3, .6, .5, 1) both;
}

@keyframes confetti {
  from { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}

/* Winning glow */
.cell .disc.winner {
  opacity: 1;
  animation: winPulse 1s ease-in-out infinite alternate;
}

.cell .disc.winner.red {
  box-shadow: 0 0 16px 6px rgba(231, 76, 60, 0.7), inset 0 -3px 6px rgba(0,0,0,0.3), inset 0 2px 4px rgba(255,255,255,0.2);
}

.cell .disc.winner.yellow {
  box-shadow: 0 0 16px 6px rgba(241, 196, 15, 0.7), inset 0 -3px 6px rgba(0,0,0,0.3), inset 0 2px 4px rgba(255,255,255,0.2);
}

@keyframes winPulse {
  0% { transform: scale(1); filter: brightness(1); }
  100% { transform: scale(1.08); filter: brightness(1.25); }
}

/* ── Overlays ── */

#start-overlay,
#gameover-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 15, 26, 0.95);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
}

#start-overlay.hidden,
#gameover-overlay.hidden {
  display: none;
}

.overlay-box {
  text-align: center;
  padding: 36px 28px;
  max-width: 440px;
  width: 90%;
}

.overlay-box h1 {
  font-size: 42px;
  font-weight: 900;
  margin-bottom: 6px;
  background: linear-gradient(135deg, #ff4d5e, #ffd23f);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.overlay-box h2 {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 8px;
}

.overlay-box .subtitle {
  color: #888;
  font-size: 14px;
  margin-bottom: 20px;
}

.how-to-play {
  text-align: left;
  padding: 14px 18px;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.7;
  color: #aaa;
  margin-bottom: 24px;
}

.how-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #666;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mode-btn,
#btn-play-again,
#btn-change-mode {
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 800;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #3a6cf0, #2a5bd7);
  color: #fff;
  cursor: pointer;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 0 #1a3a99, 0 8px 18px rgba(42, 91, 215, 0.35);
  transition: all 0.2s;
}

.mode-btn:hover,
#btn-play-again:hover,
#btn-change-mode:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

#btn-change-mode {
  background: rgba(255, 255, 255, 0.08);
  color: #c4c8de;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

#btn-change-mode:hover {
  color: #fff;
  background: rgba(255,255,255,0.12);
}

#gameover-overlay .overlay-box h2.win-red {
  color: #ff4d5e;
}

#gameover-overlay .overlay-box h2.win-yellow {
  color: #ffd23f;
}

#gameover-overlay .overlay-box h2.draw {
  color: #888;
}

#gameover-msg {
  color: #888;
  font-size: 14px;
  margin-bottom: 20px;
}

/* ── AI Thinking indicator ── */
.thinking-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 4px;
}

.thinking-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffd23f;
  animation: thinkBounce 1s infinite;
}

.thinking-dot:nth-child(2) { animation-delay: 0.15s; }
.thinking-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinkBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Column full indicator ── */
.cell.col-full {
  cursor: not-allowed;
}

.ghost-cell.col-full {
  cursor: not-allowed;
}

.ghost-cell.col-full .ghost-disc {
  opacity: 0 !important;
}

/* ── Responsive ── */

@media (max-width: 520px) {
  #app { padding-top: 12px; }

  #hud {
    gap: 6px;
  }

  .hud-player {
    min-width: 60px;
  }

  .hud-disc {
    width: 22px;
    height: 22px;
  }

  .hud-name {
    font-size: 10px;
  }

  .hud-score {
    font-size: 20px;
  }

  #turn-indicator {
    font-size: 11px;
    padding: 4px 10px;
  }

  .turn-disc {
    width: 14px;
    height: 14px;
  }

  #board {
    --gap: 4px;
    padding: 8px;
    border-radius: 14px;
  }

  #ghost-row {
    height: 40px;
  }

  .ghost-disc {
    width: 38px;
    height: 38px;
  }

  #hud-buttons button {
    padding: 4px 10px;
    font-size: 10px;
  }

  .overlay-box h1 {
    font-size: 32px;
  }
}

@media (max-width: 380px) {
  #board {
    --gap: 3px;
    padding: 6px;
  }

  #ghost-row {
    height: 34px;
  }

  .ghost-disc {
    width: 32px;
    height: 32px;
  }

  .hud-player { min-width: 50px; }
  .hud-score { font-size: 18px; }
}

#board,
#ghost-row {
  max-width: min(490px, max(240px, calc((100vh - var(--gp-header-h, 80px) - 170px) * 7 / 6)));
  max-width: min(490px, max(240px, calc((100dvh - var(--gp-header-h, 80px) - 170px) * 7 / 6)));
}

#start-overlay,
#gameover-overlay {
  top: var(--gp-header-h, 80px);
  height: auto;
  bottom: 0;
  overflow-y: auto;
  align-items: safe center;
}

@media (pointer: coarse) {
  #hud-buttons button { padding: 10px 14px; font-size: 12px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #app {
    max-width: 860px;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 6px 12px;
  }
  #hud {
    width: 220px;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 0;
  }
  #board-container { flex: 0 0 auto; width: auto; }
  #board,
  #ghost-row {
    width: calc((100vh - var(--gp-header-h, 48px) - 56px) * 7 / 6);
    width: calc((100dvh - var(--gp-header-h, 48px) - 56px) * 7 / 6);
    max-width: none;
  }
  #ghost-row { height: 34px; }
  .ghost-disc { width: 26px; height: 26px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #start-overlay .overlay-box { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 24px; align-items: center; align-content: center; justify-items: center; width: min(780px, calc(100% - 24px)); max-width: none; }
  #start-overlay .overlay-box > * { grid-column: 2; }
  #start-overlay .overlay-box > .how-to-play { grid-column: 1; grid-row: 1 / span 6; margin: 0; max-width: 340px; width: 100%; }
}

@media (max-height: 700px) {
  .overlay-box { padding: 16px 20px; }
  .overlay-box h1 { font-size: 32px; }
  .overlay-box .how-to-play { margin: 10px 0; padding: 10px 14px; line-height: 1.5; }
  .mode-buttons { gap: 8px; }
  .mode-btn { padding-top: 10px; padding-bottom: 10px; }
}

@media (pointer: coarse) and (min-width: 700px) and (min-height: 700px) {
  #app { max-width: 720px; }
  #hud { max-width: 660px; }
  #board,
  #ghost-row {
    max-width: min(640px, max(240px, calc((100vh - var(--gp-header-h, 80px) - 170px) * 7 / 6)));
    max-width: min(640px, max(240px, calc((100dvh - var(--gp-header-h, 80px) - 170px) * 7 / 6)));
  }
}

[data-theme="light"] html,
[data-theme="light"] body { background: var(--gp-page-grad) fixed; color: var(--gp-ink); }
[data-theme="light"] .hud-name, [data-theme="light"] #turn-indicator { color: var(--gp-ink-2); }
[data-theme="light"] .hud-score { color: var(--gp-ink); }
[data-theme="light"] #hud-buttons button { color: var(--gp-ink-2); }
[data-theme="light"] #hud-buttons button:hover { color: #0a84b8; }
[data-theme="light"] #start-overlay, [data-theme="light"] #gameover-overlay { background: var(--gp-overlay); color: var(--gp-ink); }
[data-theme="light"] .overlay-box .subtitle, [data-theme="light"] #gameover-msg, [data-theme="light"] #btn-change-mode { color: var(--gp-ink-2); }
[data-theme="light"] .how-to-play { background: rgba(31, 27, 69, 0.05); border-color: var(--gp-line); color: var(--gp-ink-2); }
[data-theme="light"] .mode-btn, [data-theme="light"] #btn-play-again { color: #fff; }
[data-theme="light"] #board { --frame: #3b6ff2; background: linear-gradient(180deg, #5a88ff, var(--frame) 30%, #2f5fe0); box-shadow: 0 16px 36px rgba(40, 70, 170, 0.28), inset 0 2px 0 rgba(255, 255, 255, 0.45), inset 0 -4px 0 rgba(0, 0, 0, 0.18); }
[data-theme="light"] .cell { background: radial-gradient(circle at 50% 40%, #f4f6fd, #dfe5f6); }
[data-theme="light"] .cell:hover::after { background-color: #4a7cff; }
[data-theme="light"] #turn-indicator { background: var(--gp-surface); border-color: var(--gp-line); }
[data-theme="light"] #hud-buttons button { background: var(--gp-surface); border-color: var(--gp-line); }
[data-theme="light"] #btn-change-mode { background: var(--gp-surface-2); }
[data-theme="light"] #btn-change-mode:hover { color: var(--gp-ink); }
[data-theme="light"] #gameover-overlay .overlay-box h2.win-yellow { color: #b7791f; }
[data-theme="light"] #gameover-overlay .overlay-box h2.draw { color: var(--gp-ink-2); }

.gp-btn-music.off { opacity: .4; }
