:root {
  --bg: #fafaf8;
  --ink: #3d3d3d;
  --ink-soft: #8a8a86;
  --line: #c9c9c4;
  --accent: #e8b13d;
  --accent-soft: #faf3d3;
  --black-cube: #636363;
  --white-cube: #f6f6f3;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Nunito", "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  padding: 0.65rem 1.25rem 0.35rem;
}

h1 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 700;
  font-style: italic;
  letter-spacing: 0.02em;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
}

button, select {
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
}

button:hover, select:hover { border-color: var(--ink-soft); }
button:disabled { opacity: 0.4; cursor: default; }

.help-link {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.select-tag {
  font-size: 0.75rem;
  font-style: italic;
  color: var(--ink-soft);
  margin-right: 0.15rem;
}

.select-tag[hidden] { display: none; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#status-bar {
  text-align: center;
  font-size: 1rem;
  padding: 0.2rem 0 0.4rem;
  min-height: 1.7rem;
}

#status-text .dot {
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  border-radius: 50%;
  margin-right: 0.45em;
  border: 1.5px solid var(--ink);
  vertical-align: baseline;
}

#status-text .dot.black { background: var(--black-cube); }
#status-text .dot.white { background: var(--white-cube); }

#status-text.gameover {
  font-weight: 700;
  font-size: 1.15rem;
}

#board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 1rem 1rem;
}

svg#scene {
  width: 100%;
  height: 100%;
  max-width: 1100px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* cube pieces animate via FLIP */
g.turtle {
  transition: transform 0.28s cubic-bezier(0.3, 0.8, 0.4, 1);
}

g.turtle.clickable { cursor: pointer; }

g.turtle .face { stroke: #454545; stroke-width: 1.1; stroke-linejoin: round; }

g.turtle.selected .face { stroke: var(--accent); stroke-width: 2.4; }
g.turtle.carried .face { stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: 4 3; }

/* a stack that hides pieces behind it turns translucent while hovered */
g.stack { transition: opacity 0.15s ease; }
g.stack.occluder.reveal { opacity: 0.45; }
g.stack.occluder.reveal .cube-number { opacity: 0; }

/* invisible click shapes for cubes hidden behind an occluding stack */
.hit { fill: #000; fill-opacity: 0; stroke: none; pointer-events: all; }
.hit.clickable { cursor: pointer; }

.tile { fill: #ffffff; stroke: #a8a8a2; stroke-width: 1.4; stroke-linejoin: round; }

.target {
  fill: var(--accent-soft);
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linejoin: round;
  cursor: pointer;
}

.target:hover { fill: #f5e6a8; }

.target-arrow {
  fill: var(--accent);
  pointer-events: none;
}

.score-label {
  font-size: 13px;
  font-style: italic;
  fill: var(--ink-soft);
}

.score-slot { fill: none; stroke: var(--line); stroke-width: 1.2; }
.score-fill-black { fill: var(--black-cube); stroke: #454545; }
.score-fill-white { fill: var(--white-cube); stroke: #454545; }

.last-move { fill: none; stroke: #b8cfe0; stroke-width: 2.5; stroke-linejoin: round; }

.pin-badge {
  font-size: 12px;
  font-weight: 700;
  fill: #b0483a;
  pointer-events: none;
}

.back-select-hint {
  fill: var(--ink-soft);
  font-weight: 600;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 3px;
}

/* help overlay */
#help[hidden], #online-setup[hidden] { display: none; }

#online-setup {
  position: fixed;
  inset: 0;
  background: rgba(60, 60, 55, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.color-pick {
  display: flex;
  gap: 0.8rem;
  margin: 1rem 0;
}

.color-pick button {
  flex: 1;
  padding: 0.8rem;
  font-size: 1rem;
  border-radius: 10px;
}

.color-pick .hint { color: var(--ink-soft); font-size: 0.8rem; }

.error { color: #b0483a; }

#online-bar {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 1.2rem;
  font-size: 0.9rem;
  padding-bottom: 0.3rem;
}

#online-bar[hidden] { display: none; }

#online-room { font-weight: 700; letter-spacing: 0.08em; }

#online-bar a { color: var(--ink-soft); }

#online-presence.online { color: #4a8c4a; }
#online-presence.offline { color: var(--ink-soft); font-style: italic; }

#help {
  position: fixed;
  inset: 0;
  background: rgba(60, 60, 55, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.help-card {
  position: relative;
  background: #fff;
  max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
  margin: 1rem;
  padding: 1.5rem 2rem;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  font-size: 0.95rem;
  line-height: 1.5;
}

.help-card h2 { margin-top: 0; font-style: italic; }
.help-card .close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink-soft);
}

@media (max-width: 640px) {
  header {
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem 0.25rem;
    row-gap: 0.3rem;
  }
  h1 { font-size: 1.3rem; }
  .controls { flex-wrap: wrap; gap: 0.4rem; }
  button, select { padding: 0.35rem 0.6rem; }
  #board-wrap { padding: 0 0.25rem 0.5rem; }
  #status-bar { font-size: 0.9rem; }
}
