/* ==========================================================
   木紋五子棋 — 3D 立體禪風對弈模式版面（style3d.css）
   body.mode-3d：3D 畫面全螢幕置底，面板以磨砂木質半透明浮於上方。
   ========================================================== */

/* ---------- 2D / 3D view toggle (both modes) ---------- */
.view-toggle {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background:
    repeating-linear-gradient(90deg,
      rgba(0, 0, 0, 0.08) 0px, transparent 2px, rgba(255, 220, 170, 0.04) 5px, transparent 8px),
    linear-gradient(180deg, rgba(78, 49, 29, 0.92), rgba(42, 26, 16, 0.92));
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 170, 0.22),
    inset 0 0 0 1px rgba(210, 166, 86, 0.45),
    0 6px 16px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

.view-toggle button {
  appearance: none;
  -webkit-appearance: none;
  padding: 7px 14px;
  font: inherit;
  font-size: 0.86rem;
  letter-spacing: 0.12em;
  color: var(--kaya-200);
  border: none;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.view-toggle button:hover:not(.active) {
  color: var(--kaya-100);
  background: rgba(240, 214, 166, 0.1);
}

.view-toggle button.active {
  color: #2e1a07;
  text-shadow: 0 1px 0 rgba(255, 240, 200, 0.5);
  background: linear-gradient(180deg, var(--brass-300) 0%, var(--brass-400) 50%, var(--brass-500) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 250, 225, 0.7),
    inset 0 0 0 1px rgba(100, 62, 14, 0.6),
    0 2px 4px rgba(0, 0, 0, 0.35);
  cursor: default;
}

.view-toggle button:focus-visible {
  outline: 2px solid var(--brass-300);
  outline-offset: 2px;
}

.view-toggle .hint {
  padding: 0 8px 0 6px;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  color: var(--muted);
  opacity: 0.8;
}

/* ---------- 3D stage ---------- */
.board3d-stage {
  display: none;
}

.view3d-hint {
  display: none;
}

body.mode-3d {
  overflow: hidden;
}

body.mode-3d .board3d-stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(255, 196, 130, 0.16), transparent 62%),
    radial-gradient(ellipse at 50% 115%, rgba(0, 0, 0, 0.6), transparent 60%),
    linear-gradient(180deg, #3a2415 0%, #24160d 55%, #120a05 100%);
  touch-action: none;
}

body.mode-3d .board3d-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* Loading caption */
body.loading-3d .board3d-stage::after {
  content: "載入 3D 場景中…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  letter-spacing: 0.3em;
  color: var(--kaya-200);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: load3d-pulse 1.6s ease-in-out infinite;
}

@keyframes load3d-pulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 1; }
}

/* ---------- App overlay in 3D mode ---------- */
body.mode-3d .app {
  position: relative;
  z-index: 1;
  max-width: none;
  margin: 0;
  padding: 0;
  pointer-events: none;
}

body.mode-3d .board-frame,
body.mode-3d .app-footer {
  display: none;
}

/* Interactive islands receive pointer events */
body.mode-3d .panel,
body.mode-3d .side-panel,
body.mode-3d .board-info,
body.mode-3d .status,
body.mode-3d .view-toggle,
body.mode-3d #result-overlay.show {
  pointer-events: auto;
}

/* Compact header, top-left */
body.mode-3d .app-header {
  position: fixed;
  top: 12px;
  left: 16px;
  z-index: 2;
  margin: 0;
  text-align: left;
  pointer-events: none;
}

body.mode-3d .title {
  gap: 10px;
  font-size: 1.35rem;
  letter-spacing: 0.18em;
}

body.mode-3d .subtitle {
  margin-top: 4px;
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  opacity: 0.7;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

body.mode-3d .layout {
  display: block;
}

body.mode-3d .board-area {
  display: block;
}

/* Status / move-count floating pill, bottom-center */
body.mode-3d .board-info {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 3;
  width: auto;
  min-width: 260px;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  gap: 18px;
  padding: 9px 20px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(30, 17, 8, 0.72), rgba(20, 11, 5, 0.6));
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 170, 0.12),
    inset 0 0 0 1px rgba(210, 166, 86, 0.3),
    0 8px 22px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

/* Floating frosted side panel on the right (below the toggle) */
body.mode-3d .side-panel {
  position: fixed;
  top: 70px;
  right: 16px;
  z-index: 3;
  width: 260px;
  min-width: 0;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 2px 2px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(210, 166, 86, 0.5) transparent;
}

body.mode-3d .panel {
  padding: 13px 15px 15px;
  background:
    repeating-linear-gradient(178deg,
      rgba(120, 72, 30, 0.06) 0px, transparent 2px, rgba(120, 72, 30, 0.035) 5px, transparent 9px),
    linear-gradient(170deg, rgba(236, 211, 164, 0.78) 0%, rgba(224, 189, 133, 0.72) 55%, rgba(212, 171, 112, 0.7) 100%);
  -webkit-backdrop-filter: blur(12px) saturate(1.1);
  backdrop-filter: blur(12px) saturate(1.1);
  box-shadow:
    inset 0 1px 0 rgba(255, 245, 225, 0.55),
    inset 0 0 0 1px rgba(110, 64, 28, 0.25),
    0 10px 24px rgba(0, 0, 0, 0.4);
}

body.mode-3d .panel-title {
  margin-bottom: 10px;
  font-size: 0.98rem;
}

/* Bottom-left operation hint */
body.mode-3d .view3d-hint {
  display: block;
  position: fixed;
  left: 16px;
  bottom: 22px;
  z-index: 2;
  font-size: 0.76rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  opacity: 0.75;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  body.mode-3d .side-panel {
    grid-template-columns: none;
    max-width: none;
  }
}

@media (max-width: 760px) {
  body.mode-3d .app-header { top: 10px; left: 10px; }
  body.mode-3d .title { font-size: 1.1rem; }
  body.mode-3d .subtitle { display: none; }

  body.mode-3d .view-toggle { top: 10px; right: 10px; }
  body.mode-3d .view-toggle button { padding: 6px 11px; font-size: 0.8rem; letter-spacing: 0.08em; }

  /* Side panel → bottom sheet */
  body.mode-3d .side-panel {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: 40vh;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px;
    padding: 0;
    border-radius: var(--radius);
  }

  body.mode-3d .panel { padding: 10px 12px 12px; }

  /* Status pill sits above the bottom sheet */
  body.mode-3d .board-info {
    bottom: calc(40vh + 18px);
    min-width: 0;
    padding: 7px 16px;
  }

  body.mode-3d .status { font-size: 0.95rem; }

  body.mode-3d .view3d-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  body.loading-3d .board3d-stage::after { animation: none; }
}
