:root {
  --pp-bg: #f6efe3;
  --pp-surface: #fffaf1;
  --pp-surface-strong: #ffffff;
  --pp-ink: #3e302a;
  --pp-muted: #806f64;
  --pp-line: #d7c7b7;
  --pp-accent: #8c4f3f;
  --pp-accent-dark: #6e392d;
  --pp-sage: #688057;
  --pp-sage-soft: #dfe7d7;
  --pp-gold: #d49a55;
  --pp-danger: #b7443e;
  --pp-shadow: 0 18px 50px rgba(84, 57, 40, 0.12);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--pp-bg); }

body.pp-page {
  display: block;
  min-height: 100vh;
  margin: 0;
  color: var(--pp-ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(212, 154, 85, 0.17), transparent 28rem),
    radial-gradient(circle at 88% 18%, rgba(104, 128, 87, 0.14), transparent 25rem),
    var(--pp-bg);
  font-family: Inter, ui-rounded, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.cuppa-dark {
  --pp-bg: #211b18;
  --pp-surface: #2c2521;
  --pp-surface-strong: #352c27;
  --pp-ink: #f8ecdd;
  --pp-muted: #c9b7aa;
  --pp-line: #655348;
  --pp-accent: #c47762;
  --pp-accent-dark: #e69a84;
  --pp-sage: #99ae88;
  --pp-sage-soft: #394534;
  --pp-gold: #e0aa66;
  --pp-danger: #ef8178;
  --pp-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

button, a { font: inherit; }

button {
  min-height: 44px;
  border: 1px solid var(--pp-line);
  border-radius: 12px;
  padding: 9px 14px;
  color: var(--pp-ink);
  background: var(--pp-surface-strong);
  font-weight: 750;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

button:hover { border-color: var(--pp-accent); }
button:active { transform: scale(0.97); }
button:focus-visible { outline: 3px solid var(--pp-gold); outline-offset: 3px; }
button:disabled { cursor: default; opacity: 0.5; transform: none; }
[hidden] { display: none !important; }

.pp-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.pp-hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
}

.pp-brandmark { width: 58px; height: 58px; }
.pp-brandmark svg { display: block; width: 100%; height: 100%; }
.pp-kicker { margin: 0 0 2px; color: var(--pp-sage); font-size: 12px; font-weight: 800; letter-spacing: 0.09em; text-transform: uppercase; }
.pp-hero h1 { margin: 0; color: var(--pp-accent-dark); font-family: Georgia, "Times New Roman", serif; font-size: clamp(29px, 6vw, 42px); line-height: 1; letter-spacing: -0.025em; }
.pp-help-button { border-radius: 999px; color: var(--pp-accent-dark); background: color-mix(in srgb, var(--pp-surface-strong) 84%, var(--pp-gold)); white-space: nowrap; }
.pp-instruction { margin: 22px auto 18px; color: var(--pp-muted); text-align: center; font-size: 14px; line-height: 1.5; }

.pp-game {
  position: relative;
  padding: 18px;
  border: 1px solid color-mix(in srgb, var(--pp-line) 82%, transparent);
  border-radius: 24px;
  background: color-mix(in srgb, var(--pp-surface) 94%, transparent);
  box-shadow: var(--pp-shadow);
}

.pp-mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  border-radius: 14px;
  background: var(--pp-sage-soft);
}

.pp-mode-tabs button { min-height: 44px; border: 0; background: transparent; color: var(--pp-sage); }
.pp-mode-tabs button.active { color: #fff; background: var(--pp-sage); box-shadow: 0 4px 12px rgba(71, 90, 58, 0.22); }

.pp-status {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: 14px;
  color: #fff;
  background: var(--pp-accent);
}

.pp-status > div { display: flex; min-width: 0; flex-direction: column; gap: 1px; }
.pp-status > div:not(:first-child) { text-align: right; }
.pp-label { color: rgba(255, 255, 255, 0.72); font-size: 10px; font-weight: 800; letter-spacing: 0.09em; text-transform: uppercase; }
.pp-status strong { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }

.pp-board-shell {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 320px;
}

.pp-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  /* Rows must be fixed sixths: auto rows collapse when a row has no symbols
     yet, which shifts every percentage-positioned constraint badge off its
     gridline and makes the board jump as squares fill in. */
  grid-template-rows: repeat(6, 1fr);
  width: min(100%, 410px);
  aspect-ratio: 1;
  overflow: visible;
  border: 3px solid var(--pp-accent-dark);
  border-radius: 14px;
  background: var(--pp-line);
  box-shadow: 0 10px 24px rgba(84, 57, 40, 0.14);
}

.pp-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 5px;
  border: 0;
  border-right: 1px solid var(--pp-line);
  border-bottom: 1px solid var(--pp-line);
  border-radius: 0;
  background: var(--pp-surface-strong);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.pp-row { display: contents; }
.pp-cell:last-child { border-right: 0; }
.pp-row:last-of-type .pp-cell { border-bottom: 0; }
.pp-row:first-of-type .pp-cell:first-child { border-radius: 10px 0 0; }
.pp-row:first-of-type .pp-cell:last-child { border-radius: 0 10px 0 0; }
.pp-row:last-of-type .pp-cell:first-child { border-radius: 0 0 0 10px; }
.pp-row:last-of-type .pp-cell:last-child { border-radius: 0 0 10px; }
.pp-cell:not(.given):hover { background: color-mix(in srgb, var(--pp-surface-strong) 83%, var(--pp-sage-soft)); }
.pp-cell.given { cursor: default; background: color-mix(in srgb, var(--pp-surface-strong) 72%, var(--pp-gold)); }
.pp-cell.given::after { content: ""; position: absolute; inset: 5px; border: 1.5px solid color-mix(in srgb, var(--pp-gold) 72%, var(--pp-accent)); border-radius: 9px; pointer-events: none; }
.pp-cell.bad { z-index: 1; background: color-mix(in srgb, var(--pp-surface-strong) 72%, var(--pp-danger)); box-shadow: inset 0 0 0 2px var(--pp-danger); }
.pp-cell.hinted { animation: pp-hint 0.65s ease; }
.pp-cell svg { position: relative; z-index: 1; display: block; width: 88%; height: 88%; pointer-events: none; }
.pp-cell .pp-empty-dot { width: 5px; height: 5px; border-radius: 50%; background: color-mix(in srgb, var(--pp-line) 76%, transparent); }

.pp-constraint {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 1.5px solid var(--pp-accent);
  border-radius: 50%;
  color: var(--pp-accent-dark);
  background: var(--pp-surface-strong);
  box-shadow: 0 2px 7px rgba(62, 48, 42, 0.18);
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
}

.pp-feedback { min-height: 21px; margin: 14px 4px 10px; color: var(--pp-muted); text-align: center; font-size: 13px; line-height: 1.4; }
.pp-feedback.warn { color: var(--pp-danger); font-weight: 750; }

.pp-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pp-controls button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; color: var(--pp-accent-dark); background: var(--pp-surface-strong); }
.pp-controls svg { width: 20px; height: 20px; }
.pp-controls span { color: var(--pp-muted); font-size: 11px; font-weight: 700; }

.pp-completed {
  width: min(100%, 410px);
  padding: 34px 18px;
  border: 1px solid var(--pp-line);
  border-radius: 20px;
  text-align: center;
  background: var(--pp-surface-strong);
}

.pp-completed > svg { width: 76px; height: 76px; }
.pp-completed h2 { margin: 10px 0 6px; color: var(--pp-accent-dark); font-family: Georgia, "Times New Roman", serif; font-size: 24px; }
.pp-completed p { margin: 0 0 18px; color: var(--pp-muted); font-size: 14px; }

.pp-primary { border-color: var(--pp-accent); color: #fff; background: var(--pp-accent); }
.pp-primary:hover { background: var(--pp-accent-dark); }
.pp-wide { width: 100%; }

.pp-overlay {
  position: fixed;
  z-index: 2000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(43, 31, 26, 0.62);
  backdrop-filter: blur(5px);
}

.pp-modal {
  position: relative;
  width: min(100%, 440px);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 26px;
  border: 1px solid var(--pp-line);
  border-radius: 22px;
  color: var(--pp-ink);
  background: var(--pp-surface-strong);
  box-shadow: 0 30px 80px rgba(32, 21, 16, 0.3);
}

.pp-modal h2 { margin: 0 34px 8px 0; color: var(--pp-accent-dark); font-family: Georgia, "Times New Roman", serif; font-size: 27px; }
.pp-modal p { color: var(--pp-muted); line-height: 1.5; }
.pp-modal ul { margin: 18px 0; padding-left: 22px; }
.pp-modal li { margin: 10px 0; line-height: 1.45; }
.pp-tip { padding: 11px 13px; border-radius: 12px; background: var(--pp-sage-soft); }
.pp-close { position: absolute; top: 14px; right: 14px; width: 42px; min-height: 42px; padding: 0; border-radius: 50%; font-size: 24px; line-height: 1; }
.pp-win-modal { text-align: center; }
.pp-win-modal h2 { margin-right: 0; }
.pp-win-art svg { width: 82px; height: 82px; }
.pp-result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 20px 0; }
.pp-result-stats div { display: flex; flex-direction: column; padding: 13px; border-radius: 14px; background: var(--pp-sage-soft); }
.pp-result-stats strong { color: var(--pp-accent-dark); font-size: 22px; }
.pp-result-stats span { margin-top: 2px; color: var(--pp-muted); font-size: 11px; font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase; }
.pp-modal-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.pp-modal-actions button { flex: 1 1 135px; }

.pp-level-overlay { place-items: start center; overflow: auto; }
.pp-level-modal { width: min(100%, 680px); margin: 24px 0; }
.pp-level-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 18px; }
.pp-level-card { min-height: 66px; padding: 8px 4px; }
.pp-level-card strong, .pp-level-card span { display: block; }
.pp-level-card strong { color: var(--pp-accent-dark); font-size: 16px; }
.pp-level-card span { margin-top: 3px; color: var(--pp-muted); font-size: 10px; }
.pp-level-card.current { border-color: var(--pp-accent); background: color-mix(in srgb, var(--pp-surface-strong) 76%, var(--pp-gold)); }
.pp-level-card.complete::after { content: "Done"; display: block; margin-top: 3px; color: var(--pp-sage); font-size: 9px; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; }
.pp-svg-defs { position: absolute; }

@keyframes pp-hint {
  0%, 100% { filter: none; transform: scale(1); }
  45% { filter: drop-shadow(0 0 9px var(--pp-gold)); transform: scale(1.09); }
}

@media (max-width: 520px) {
  .pp-shell { padding: 18px 10px 42px; }
  .pp-hero { gap: 9px; padding: 0 5px; }
  .pp-brandmark { width: 48px; height: 48px; }
  .pp-kicker { font-size: 9px; }
  .pp-hero h1 { font-size: 29px; }
  .pp-help-button { min-height: 40px; padding: 7px 10px; font-size: 12px; }
  .pp-instruction { margin: 16px 8px 14px; font-size: 13px; }
  .pp-game { padding: 12px; border-radius: 19px; }
  .pp-status { padding: 9px 11px; }
  .pp-status strong { font-size: 13px; }
  .pp-board-shell { min-height: 0; }
  .pp-board { width: 100%; }
  .pp-cell { padding: 3px; }
  .pp-cell.given::after { inset: 3px; border-radius: 7px; }
  .pp-constraint { width: 18px; height: 18px; margin: -9px 0 0 -9px; font-size: 12px; }
  .pp-feedback { margin-top: 12px; font-size: 12px; }
  .pp-level-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .pp-modal { padding: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
