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

html,
body {
  touch-action: none;
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #4a3520;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(ellipse at 50% 0%, #fff6d0 0%, rgba(255, 246, 208, 0) 60%),
    radial-gradient(ellipse at 0% 100%, #ffe9a8 0%, rgba(255, 233, 168, 0) 55%),
    radial-gradient(ellipse at 100% 100%, #ffd97a 0%, rgba(255, 217, 122, 0) 55%),
    linear-gradient(180deg, #fff4cc 0%, #ffeab5 100%);
  background-attachment: fixed;
}

/* ===== Turn Indicator ===== */
.turn-indicator {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 22px 10px 10px;
  margin: 14px 64px 8px 64px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(180, 130, 50, 0.18), inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.turn-avatar {
  width: 48px;
  height: 48px;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
}

.turn-label {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #5a3a1a;
}

/* ===== Board (intersection-based Gomoku style) =====
 * Grid lines: inline SVG (.board-grid) generated by game.js rebuildBoard().
 * .cell = intersection point (name kept for continuity). Stones sit ON lines. */
.board-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 20px 2px;
  min-height: 0;
  container-type: size;
  position: relative;
}

.board {
  --board-size: 13;
  --total-size: min(100cqw, 100cqh);
  --pad: calc(var(--total-size) * 0.04);
  --inner-size: calc(var(--total-size) - var(--pad) * 2);
  --spacing: calc(var(--inner-size) / (var(--board-size) - 1));
  width: var(--total-size);
  height: var(--total-size);
  position: relative;
  background: #fdf3d3;
  border-radius: 14px;
  /* Frame via inset shadows (not border) so the box stays exactly
   * --total-size — keeps grid lines and cell centers pixel-aligned. */
  box-shadow:
    0 12px 32px rgba(160, 110, 30, 0.28),
    inset 0 0 0 3px #c9933e,
    inset 0 0 0 5px rgba(255, 255, 255, 0.4);
  overflow: hidden;
}

.board-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.board-grid line {
  stroke: #c9933e;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.board-grid circle {
  fill: #c9933e;
  fill-opacity: 0.4;
}

.board-grid .star {
  fill: #c9933e;
  stroke: none;
}

/* Each .cell is an intersection point (class name kept for code continuity). */
.cell {
  position: absolute;
  width: var(--spacing);
  height: var(--spacing);
  left: calc(var(--pad) + var(--col) * var(--spacing));
  top: calc(var(--pad) + var(--row) * var(--spacing));
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

.cell.pressed {
  background: radial-gradient(circle, rgba(255, 224, 130, 0.55) 38%, transparent 42%);
}

.cell.hint-glow {
  /* hint.js injects the pulse animation; just raise stacking. */
  z-index: 5;
}

/* Stones — circular disks with the character image inside. */
.cell .stone {
  width: 80%;
  height: 80%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
  border: 2px solid;
  box-shadow:
    0 3px 6px rgba(0, 0, 0, 0.25),
    inset 0 2px 4px rgba(255, 255, 255, 0.4);
  animation: drop-in 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cell .stone.family {
  background: radial-gradient(circle at 35% 30%, #fff8d0, #ffd97a 70%, #f5b820 100%);
  border-color: #c9933e;
}

.cell .stone.wolf {
  background: radial-gradient(circle at 35% 30%, #f0f0f5, #b8b8c8 70%, #707080 100%);
  border-color: #505060;
}

.cell .stone img {
  width: 88%;
  height: 88%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

@keyframes drop-in {
  0%   { transform: scale(0.2) translateY(-6px); opacity: 0; }
  60%  { transform: scale(1.12) translateY(0);   opacity: 1; }
  100% { transform: scale(1) translateY(0);      opacity: 1; }
}

/* ===== Controls ===== */
.controls {
  display: flex;
  gap: 16px;
  padding: 14px 12px 22px;
  justify-content: center;
  width: 100%;
}

.controls button {
  min-height: 60px;
  min-width: 110px;
  padding: 0 24px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #fff;
  background: linear-gradient(180deg, #ffb04a 0%, #ff8c1a 100%);
  border: none;
  border-radius: 18px;
  box-shadow: 0 5px 0 #c96b00, 0 8px 18px rgba(200, 110, 0, 0.3);
  transition: transform 80ms ease, box-shadow 80ms ease;
  font-family: inherit;
}

.controls button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c96b00, 0 4px 10px rgba(200, 110, 0, 0.3);
}

.reset-btn {
  background: linear-gradient(180deg, #8a9bf0 0%, #6173d8 100%) !important;
  box-shadow: 0 5px 0 #3a4ba8, 0 8px 18px rgba(60, 70, 160, 0.3) !important;
}

.reset-btn:active {
  box-shadow: 0 2px 0 #3a4ba8, 0 4px 10px rgba(60, 70, 160, 0.3) !important;
}

.controls button:disabled,
.controls button.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ===== Settings Button (in controls footer) ===== */
.settings-btn {
  background: linear-gradient(180deg, #8ac24a 0%, #5fa831 100%) !important;
  box-shadow: 0 5px 0 #3d7a1c, 0 8px 18px rgba(60, 120, 30, 0.3) !important;
}

.settings-btn:active {
  box-shadow: 0 2px 0 #3d7a1c, 0 4px 10px rgba(60, 120, 30, 0.3) !important;
}

/* ===== Back-to-Home Button ===== */
.back-home-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 14px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  color: #8a6a4a;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 8px 14px;
  border-radius: 999px;
  text-decoration: none;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(180, 130, 50, 0.15);
  transition: transform 80ms ease, background 80ms ease;
}

.back-home-btn:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.9);
}

/* ===== Victory Overlay ===== */
.victory-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 25, 10, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fade-in 200ms ease-out;
}

.victory-overlay[hidden] {
  display: none;
}

.victory-card {
  background: linear-gradient(180deg, #fffaf0 0%, #fff0d0 100%);
  padding: 34px 40px 28px;
  border-radius: 28px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(80, 50, 10, 0.4);
  border: 3px solid #ffd97a;
  animation: pop-in 600ms cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 80vw;
}

.victory-avatar {
  width: 130px;
  height: 130px;
  object-fit: contain;
  margin: 0 auto 12px;
  display: block;
  animation: bounce 1.2s ease-in-out infinite;
}

.victory-text {
  font-size: 32px;
  font-weight: 800;
  color: #c44a00;
  margin-bottom: 22px;
  letter-spacing: 1px;
}

.play-again-btn {
  min-height: 60px;
  min-width: 160px;
  padding: 0 28px;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #ffb04a 0%, #ff8c1a 100%);
  border: none;
  border-radius: 18px;
  box-shadow: 0 5px 0 #c96b00, 0 8px 18px rgba(200, 110, 0, 0.3);
  font-family: inherit;
  transition: transform 80ms ease, box-shadow 80ms ease;
}

.play-again-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c96b00, 0 4px 10px rgba(200, 110, 0, 0.3);
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes pop-in {
  0%   { transform: scale(0.3) rotate(-6deg); opacity: 0; }
  55%  { transform: scale(1.1) rotate(2deg);  opacity: 1; }
  75%  { transform: scale(0.95) rotate(-1deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}

/* ===== Orientation Adaptive ===== */
@media (orientation: portrait) {
  body {
    flex-direction: column;
  }
}

@media (orientation: landscape) {
  body {
    flex-direction: column;
    justify-content: center;
  }
  .turn-indicator {
    margin: 8px 64px 6px 64px;
    padding: 6px 18px 6px 6px;
  }
  .turn-avatar {
    width: 40px;
    height: 40px;
  }
  .turn-label {
    font-size: 20px;
  }
  .controls {
    padding: 8px 12px 12px;
  }
  .controls button {
    min-height: 56px;
    min-width: 100px;
    font-size: 18px;
  }
}
