/* ---------------------------------------------------------------------- *
 * Mühle — light honey oak & brass game table                             *
 * ---------------------------------------------------------------------- */

:root {
  --wood-0: #4a3420;
  --wood-1: #6b4a2a;
  --wood-2: #8a6238;
  --wood-3: #a67c47;
  --brass-0: #f0d29a;
  --brass-1: #dcb571;
  --brass-2: #b08a4e;
  --parchment: #f7efdc;
  --parchment-dim: #d8c7a3;
  --ivory-hi: #fdfaf1;
  --ivory-lo: #d9c095;
  --onyx-hi: #6b665c;
  --onyx-lo: #201c17;
  --glow: #ffc766;
  --mill-glow: #ff6a4d;
  --error: #e2604f;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family: "Vollkorn", Georgia, serif;
  color: var(--parchment);
  background:
    radial-gradient(ellipse 70% 50% at 20% 15%, rgba(130, 100, 210, 0.16), transparent 60%),
    radial-gradient(ellipse 60% 45% at 80% 10%, rgba(80, 160, 210, 0.12), transparent 60%),
    radial-gradient(ellipse 90% 70% at 50% 100%, #0d1840 0%, transparent 60%),
    linear-gradient(180deg, #05070f 0%, #0a1130 45%, #05070f 100%);
  padding: 0;
}

.app {
  width: 100vw;
  height: 100vh;
  max-width: none;
  position: relative;
  overflow: hidden;
}

.app__header {
  position: absolute;
  top: 1rem;
  left: 1.25rem;
  z-index: 5;
  margin: 0;
  padding: 0.35rem 1rem;
  background: rgba(74, 52, 32, 0.45);
  border: 1px solid rgba(240, 210, 154, 0.22);
  border-radius: 12px;
  backdrop-filter: blur(2px);
  pointer-events: none;
}

.app__header h1 {
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: clamp(1.3rem, 2.4vw, 1.8rem);
  letter-spacing: 0.06em;
  margin: 0;
  color: var(--brass-0);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4), 0 0 24px rgba(240, 210, 154, 0.3);
}

[hidden] { display: none !important; }

/* -------------------------------------------------- 3D-embedded controls --
 * These panels (header actions, settings, status, network panel, player
 * stocks) are detached from #controls-src by game.js and mounted as
 * CSS3DObjects inside the WebGL scene, so they need their own visual
 * grounding (a floating "plaque") rather than relying on page layout. */

.header__actions,
.settings,
.network-panel,
.status,
.player {
  background: rgba(74, 52, 32, 0.55);
  border: 1px solid rgba(240, 210, 154, 0.25);
  border-radius: 12px;
  backdrop-filter: blur(2px);
}

.header__actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.7rem 1rem;
  width: max-content;
}

.icon-btn {
  width: 3.3rem;
  height: 3.3rem;
  border-radius: 50%;
  border: 1px solid var(--brass-2);
  background: linear-gradient(180deg, #a67c47, #8a6238);
  color: var(--brass-0);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.12s ease, transform 0.12s ease;
}

.icon-btn:hover { filter: brightness(1.15); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn[aria-pressed="true"] { color: var(--parchment-dim); opacity: 0.75; }

.settings {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.9rem 1.4rem;
  padding: 1rem 1.4rem;
  width: max-content;
}

.settings__group[hidden] {
  display: none;
}

.settings__group {
  display: inline-flex;
  gap: 0.4rem;
  padding: 0.25rem;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(240, 210, 154, 0.2);
  border-radius: 999px;
}

.chip {
  font-family: "Vollkorn", serif;
  font-size: 1.15rem;
  color: var(--parchment-dim);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1.3rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.chip:hover { color: var(--parchment); }

.chip.is-active {
  background: linear-gradient(180deg, var(--brass-0), var(--brass-1));
  color: var(--wood-0);
  font-weight: 600;
}

.btn {
  font-family: "Cinzel", serif;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--wood-0);
  background: linear-gradient(180deg, var(--brass-0), var(--brass-1));
  border: 1px solid var(--brass-2);
  border-radius: 8px;
  padding: 0.85rem 1.5rem;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 3px 0 var(--brass-2), 0 8px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.btn:hover { filter: brightness(1.08); }

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--brass-2), 0 4px 10px rgba(0, 0, 0, 0.3);
}

.btn--ghost {
  background: transparent;
  color: var(--brass-0);
  box-shadow: none;
  border: 1px solid var(--brass-2);
}

.btn--ghost:hover { background: rgba(240, 210, 154, 0.12); }

.btn--small {
  padding: 0.6rem 1.1rem;
  font-size: 0.95rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}

.network-panel {
  text-align: center;
  padding: 1.1rem 1.3rem;
  width: max-content;
  max-width: 34rem;
}

.network-panel p {
  margin: 0 0 0.8rem;
  font-size: 1.15rem;
  color: var(--parchment-dim);
}

.network-panel strong {
  color: var(--brass-0);
}

.invite {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
}

#invite-link-input {
  flex: 1 1 260px;
  min-width: 0;
  max-width: 420px;
  font-family: "Vollkorn", serif;
  font-size: 1.05rem;
  color: var(--parchment);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--brass-2);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
}

#invite-link-input:focus {
  outline: 1px solid var(--brass-0);
}

.status {
  margin: 0;
  text-align: center;
  font-size: 1.5rem;
  font-style: italic;
  color: var(--parchment-dim);
  min-height: 1.6em;
  padding: 0.7rem 1.6rem;
  width: 560px;
  transition: color 0.2s ease;
}

.status.status--error { color: var(--error); font-style: normal; }
.status.status--win {
  color: var(--glow);
  font-style: normal;
  font-weight: 600;
  text-shadow: 0 0 18px rgba(255, 199, 102, 0.5);
}

.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  padding: 1.1rem 1.3rem;
  width: max-content;
  transition: background 0.25s ease, box-shadow 0.25s ease;
}

.player--active {
  background: rgba(240, 210, 154, 0.18);
  box-shadow: inset 0 0 0 1px rgba(240, 210, 154, 0.4);
}

.player__label {
  font-family: "Cinzel", serif;
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--parchment-dim);
}

.player--active .player__label { color: var(--brass-0); }

.stock {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
  max-width: 130px;
}

.stock__stone {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.4);
}

.stock--white .stock__stone {
  background: radial-gradient(circle at 32% 28%, var(--ivory-hi), var(--ivory-lo) 75%);
}

.stock--black .stock__stone {
  background: radial-gradient(circle at 32% 28%, var(--onyx-hi), var(--onyx-lo) 75%);
}

/* ------------------------------------------------------------- 3D stage --
 * Two overlapping full-size layers: a WebGL canvas (board + stones) below,
 * a CSS3DRenderer layer (relocated controls, see above) on top. The CSS3D
 * layer is pointer-events:none except for its actual interactive elements,
 * so board clicks/drags fall through to the canvas underneath. */

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 15%, rgba(80, 110, 210, 0.14), transparent 70%), #05070f;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.3);
  touch-action: none;
}

#stage canvas,
#stage .css3d-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
}

#stage canvas {
  display: block;
  z-index: 1;
  cursor: grab;
}

body.is-busy #stage canvas {
  cursor: wait;
}

#stage .css3d-layer {
  z-index: 2;
  pointer-events: none;
}

#stage .css3d-layer button,
#stage .css3d-layer input,
#stage .css3d-layer a {
  pointer-events: auto;
}

/* ---------------------------------------------------------- rules modal --
 * A plain viewport-fixed overlay (unlike the panels above, it is never
 * mounted into the 3D scene — see the comment in index.html). */

.rules-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
}

.rules-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 6, 3, 0.6);
  backdrop-filter: blur(2px);
}

.parchment {
  position: relative;
  width: 100%;
  max-width: 36rem;
  padding: 15px 0;
}

/* Wooden roller caps peeking out above/below the sheet, like a scroll rod. */
.parchment::before,
.parchment::after {
  content: "";
  position: absolute;
  left: -18px;
  right: -18px;
  height: 30px;
  z-index: 1;
  border-radius: 999px;
  background: linear-gradient(180deg, #d8b06a 0%, #a67c47 35%, #6b4a2a 75%, #4a3420 100%);
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.5),
    inset 0 2px 2px rgba(255, 255, 255, 0.3),
    inset 0 -3px 4px rgba(0, 0, 0, 0.35);
}

.parchment::before { top: 0; }
.parchment::after { bottom: 0; }

.parchment__close {
  position: absolute;
  top: 1.6rem;
  right: 1.4rem;
  z-index: 3;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: 1px solid var(--brass-2);
  background: rgba(74, 52, 32, 0.4);
  color: var(--wood-0);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
}

.parchment__close:hover { background: rgba(176, 138, 78, 0.3); }

.parchment__sheet {
  position: relative;
  z-index: 2;
  max-height: 72vh;
  overflow-y: auto;
  padding: 2.25rem 2.5rem 1.75rem;
  color: var(--wood-0);
  font-family: "Vollkorn", serif;
  background:
    radial-gradient(circle at 10% 15%, rgba(120, 80, 40, 0.12), transparent 24%),
    radial-gradient(circle at 85% 10%, rgba(120, 80, 40, 0.09), transparent 20%),
    radial-gradient(circle at 75% 88%, rgba(120, 80, 40, 0.12), transparent 26%),
    radial-gradient(circle at 15% 92%, rgba(120, 80, 40, 0.09), transparent 22%),
    radial-gradient(ellipse 90% 60% at 15% 0%, rgba(255, 255, 255, 0.35), transparent 55%),
    radial-gradient(ellipse 80% 50% at 100% 100%, rgba(0, 0, 0, 0.08), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    linear-gradient(160deg, var(--ivory-hi), var(--parchment) 55%, var(--parchment-dim));
  background-blend-mode: normal, normal, normal, normal, normal, normal, multiply, normal;
  border-radius: 3px;
  box-shadow:
    0 16px 34px rgba(0, 0, 0, 0.4),
    inset 0 0 40px rgba(176, 138, 78, 0.22),
    inset 14px 0 22px -16px rgba(90, 63, 36, 0.4),
    inset -14px 0 22px -16px rgba(90, 63, 36, 0.4);
}

.parchment h2 {
  font-family: "UnifrakturMaguntia", "Cinzel", serif;
  font-weight: 400;
  font-size: 2.4rem;
  letter-spacing: 0.02em;
  margin: 0 0 1.1rem;
  color: var(--wood-0);
}

.parchment__rules {
  margin: 0;
  padding-left: 1.5rem;
  font-family: "UnifrakturMaguntia", "Cinzel", serif;
  font-size: 1.2rem;
  line-height: 1.9;
  letter-spacing: 0.01em;
}

.parchment__rules li + li { margin-top: 0.9rem; }

.parchment__rules li::marker {
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--brass-2);
}

.parchment__rules strong {
  font-size: 1.32rem;
}
