:root {
  --cream: #f5e3bd;
  --ink: #1f1a17;
  --wine: #853d38;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "SF Pro Rounded", ui-rounded, "Hiragino Maru Gothic ProN", system-ui, sans-serif;
  color: var(--cream);
  background: #120e0c;
}

body {
  background:
    linear-gradient(180deg, rgba(0,0,0,.32) 0%, rgba(0,0,0,.08) 26%, rgba(0,0,0,0) 48%, rgba(0,0,0,.24) 100%),
    url("../img/house-exterior.jpg") center / cover no-repeat fixed;
}

.play {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  padding: 4px 16px 28px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.toolbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
}

.toolbar-cluster {
  display: flex;
  gap: 2px;
}

.icon-btn, .size-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--cream);
  font: inherit;
  font-weight: 600;
  padding: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
}

.size-btn {
  font-variant-numeric: tabular-nums;
  padding: 8px 10px;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  display: block;
}

.wordmark {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(36px, 9vw, 48px);
  font-weight: 800;
  letter-spacing: -1.4px;
  line-height: 1;
  margin: 18px 0 20px;
  text-shadow: 0 1px 3px rgba(0,0,0,.55);
}

.wordmark img {
  width: 0.72em;
  height: 0.72em;
  border-radius: 50%;
  margin: 0 0.04em -0.08em;
  box-shadow: 0 0 0 1.4px rgba(219, 189, 133, .7);
}

.status {
  text-align: center;
  color: var(--ink);
  background: var(--cream);
  border-radius: 12px;
  padding: 8px 14px;
  min-height: 36px;
  font-size: 0.95rem;
  white-space: pre-line;
}

.board-wrap {
  margin: 12px 0 8px;
  aspect-ratio: 1;
  width: 100%;
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  border-radius: 8px;
  overflow: hidden;
  border: 4px solid #1f1f1f;
  position: relative;
  touch-action: none;
  user-select: none;
}

.cell {
  position: relative;
  overflow: hidden;
}

.cell img {
  position: absolute;
  inset: 8%;
  width: 84%;
  height: 84%;
  object-fit: cover;
  border-radius: 50%;
  pointer-events: none;
}

.cell.blocked img { opacity: 0.32; }

.cell .x {
  position: absolute;
  inset: 18%;
  pointer-events: none;
}

.cell .ring {
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  box-shadow: 0 0 0 3.75px rgba(0,0,0,.62), 0 0 0 8.25px var(--cream);
  pointer-events: none;
}

.patterned .cell .ring {
  box-shadow: 0 0 0 3.75px rgba(0,0,0,.62), 0 0 0 8.25px var(--wine);
}

.cell.conflict .ring {
  box-shadow: 0 0 0 3.75px rgba(0,0,0,.62), 0 0 0 8.25px #e33;
}

.cell.conflict::after {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: rgba(255, 0, 0, 0.42);
  pointer-events: none;
}

.cell.won img { transform: scale(1.08); }

.controls {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.play-btn {
  flex: 1;
  appearance: none;
  border: 0;
  border-radius: 12px;
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 12px 10px;
  cursor: pointer;
}

.play-btn:disabled { opacity: 0.42; }

.play-btn.wine {
  background: var(--wine);
  color: var(--cream);
}

.play-btn.ghost {
  background: rgba(255,255,255,.55);
  color: var(--ink);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.overlay.hidden { display: none; }

.overlay.confirm { z-index: 30; }
.overlay.loading { z-index: 40; }

.overlay.help, .overlay.settings {
  background:
    linear-gradient(180deg, rgba(0,0,0,.52) 0%, rgba(0,0,0,.2) 30%, rgba(0,0,0,.34) 100%),
    url("../img/house-library.jpg") center / cover no-repeat;
}

.card {
  background: var(--cream);
  color: var(--ink);
  border-radius: 24px;
  padding: 28px;
  max-width: 420px;
  width: 100%;
  max-height: min(88vh, 720px);
  overflow: auto;
  box-shadow: 0 10px 24px rgba(0,0,0,.2);
}

.card.narrow { max-width: 320px; }

.card h1, .card h2 {
  margin: 0 0 10px;
  text-align: center;
  font-size: 1.35rem;
}

.card p { color: rgba(31,26,23,.78); margin: 0 0 12px; }

.rule {
  display: flex;
  gap: 14px;
  background: rgba(255,255,255,.5);
  border-radius: 16px;
  padding: 14px;
  margin: 8px 0;
}

.rule-n {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--wine);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.rule h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.rule p { margin: 0; color: rgba(31,26,23,.68); }

.note {
  background: rgba(31,26,23,.06);
  border-radius: 16px;
  padding: 16px;
  margin: 12px 0;
  color: rgba(31,26,23,.72);
}

.note h3 { margin: 0 0 6px; color: var(--ink); }

.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.settings-card {
  background: rgba(255,255,255,.5);
  border-radius: 20px;
  padding: 18px;
  margin: 0 0 12px;
}

.toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-weight: 500;
  color: var(--ink);
}

.toggle + .toggle {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(31,26,23,.12);
}

.toggle input {
  appearance: none;
  width: 44px;
  height: 26px;
  margin: 0;
  background: rgba(31,26,23,.18);
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle input::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: transform 0.15s ease;
}

.toggle input:checked {
  background: var(--wine);
}

.toggle input:checked::after {
  transform: translateX(18px);
}

.more-games {
  font-size: 0.9rem;
}

.more-games p {
  font-weight: 600;
  color: rgba(31,26,23,.55);
  margin-bottom: 12px;
}

.more-games a {
  display: flex;
  justify-content: space-between;
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
  padding: 6px 0;
}

.more-games a + a {
  border-top: 1px solid rgba(31,26,23,.12);
  padding-top: 12px;
  margin-top: 6px;
}

.size-menu {
  position: absolute;
  top: 48px;
  left: 0;
  background: var(--ink);
  color: var(--cream);
  border-radius: 12px;
  min-width: 140px;
  z-index: 15;
  overflow: hidden;
  padding: 6px 0;
}

.size-menu.hidden { display: none; }

.size-menu button {
  display: flex;
  width: 100%;
  justify-content: space-between;
  background: transparent;
  border: 0;
  color: var(--cream);
  font: inherit;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 12px 16px;
  cursor: pointer;
}

.loading {
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(0,0,0,.45) 0%, rgba(0,0,0,.12) 40%, rgba(0,0,0,.38) 100%),
    url("../img/house-exterior.jpg") center / cover no-repeat;
}

.loading .wordmark { font-size: clamp(40px, 11vw, 56px); margin-bottom: 12px; }

.loading p {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,.55);
  margin: 0;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(245,227,189,.3);
  border-top-color: var(--cream);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 16px auto 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

.walls {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.patterned .cell { background-color: var(--cream) !important; }

.site-footer {
  margin-top: auto;
  padding-top: 18px;
  text-align: center;
  font-size: 0.8rem;
  color: rgba(245,227,189,.7);
}

.site-footer a { color: inherit; }

.privacy {
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.privacy .card { max-width: none; }

.privacy h1 { font-size: 1.6rem; }

.privacy h2 {
  font-size: 1.1rem;
  margin: 22px 0 8px;
  text-align: left;
}

@media (min-width: 768px) {
  .overlay.help .card,
  .overlay.settings .card {
    max-width: min(520px, 92vw);
  }
}
