/* ─── Sewer Shenanigans — cream notebook / hub palette ───────────── */
:root {
  --bg-deep: #F5E4C4;
  --bg: #FDF0D5;
  --bg-elevated: #FFFBF3;
  --bg-card: #FFFBF3;
  --slime: #249D8F;
  --slime-bright: #3DB5A3;
  --slime-dim: #1A7A6F;
  --slime-glow: rgba(36, 157, 143, 0.28);
  --rust: #E76F51;
  --rust-bright: #E9C46A;
  --water: #249D8F;
  --water-glow: rgba(36, 157, 143, 0.35);
  --text: #2C2416;
  --text-muted: #7A6A52;
  --border: rgba(36, 157, 143, 0.28);
  --danger: #E76F51;
  --shadow: 5px 5px 0 #2C2416;
  --radius: 22px;
  --radius-sm: 12px;
  --font: "Fredoka", system-ui, sans-serif;
  --mono: "Share Tech Mono", ui-monospace, monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --pipe: #1A7A6F;
  --pipe-edge: #2C2416;
  --pipe-shine: #3DB5A3;
  --tile-bg: #0f241c;
  --tile-border: #2C2416;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  /* Page paper from /shared/notebook-bg.css */
  background-color: var(--bg-deep);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.bg-blobs {
  display: none;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 16px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  gap: 16px;
  animation: fade-in 0.35s ease;
}

.screen.active {
  display: flex;
}

.screen[hidden] {
  display: none !important;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ─── Brand / setup ─────────────────────────────────────────────── */
.brand {
  text-align: center;
  padding: 12px 0 4px;
}

.manhole {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  position: relative;
  display: grid;
  place-items: center;
}

.manhole-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 4px solid #2C2416;
  box-shadow:
    inset 0 0 0 3px var(--bg-elevated),
    3px 3px 0 var(--coral, #E76F51);
  background:
    repeating-conic-gradient(from 0deg, #E9C46A 0deg 12deg, #FDF0D5 12deg 24deg);
}

.manhole-lid {
  position: relative;
  z-index: 1;
  font-size: 1.4rem;
  color: var(--slime-dim);
  text-shadow: none;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.75rem, 6vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-family: "Waukegan LDO", "Eurostile", "Arial Narrow", system-ui, sans-serif;
  background: linear-gradient(120deg, #1A7A6F 0%, #249D8F 45%, #E9C46A 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 400;
}

.setup-card {
  background: var(--bg-elevated);
  border: 3px solid #2C2416;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 5px 5px 0 #2C2416;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

legend {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.seg {
  cursor: pointer;
}

.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg span {
  display: grid;
  place-items: center;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 2px solid #2C2416;
  background: var(--bg-card);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, color 0.15s;
}

.seg input:checked + span {
  border-color: #2C2416;
  background: color-mix(in srgb, var(--slime) 18%, #FFFBF3);
  color: var(--slime-dim);
  box-shadow: 2px 2px 0 #2C2416;
}

.seg input:focus-visible + span {
  outline: 2px solid var(--slime-bright);
  outline-offset: 2px;
}

.difficulty-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diff-card {
  cursor: pointer;
  display: block;
}

.diff-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.diff-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 2px solid #2C2416;
  background: var(--bg-card);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.diff-name {
  font-weight: 600;
  font-size: 1rem;
}

.diff-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.diff-card input:checked + .diff-body {
  border-color: #2C2416;
  background: color-mix(in srgb, var(--gold, #E9C46A) 28%, #FFFBF3);
  box-shadow: 3px 3px 0 var(--coral, #E76F51);
}

.diff-card input:checked + .diff-body .diff-name {
  color: var(--slime-dim);
}

.diff-card input:focus-visible + .diff-body {
  outline: 2px solid var(--slime-bright);
  outline-offset: 2px;
}

.how-to {
  margin: 0;
  padding: 0 4px;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text-muted);
  text-align: center;
}

.how-to strong {
  color: var(--text);
}

/* ─── Login / X auth ────────────────────────────────────────────── */
.login-card {
  text-align: center;
  gap: 16px;
}

.login-lead {
  margin: 0;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.45;
}

.login-fineprint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.btn-x {
  background: #000;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  gap: 10px;
}

.btn-x:hover {
  background: #111;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.45);
}

.btn-x:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.x-logo {
  font-size: 1.25rem;
  line-height: 1;
  font-weight: 700;
}

.auth-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--coral, #E76F51) 14%, #FFFBF3);
  border: 2px solid #2C2416;
  color: #9A3F2A;
  font-size: 0.88rem;
  text-align: left;
}

.auth-hint {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--gold, #E9C46A) 22%, #FFFBF3);
  border: 2px solid #2C2416;
  color: #5A4A28;
  font-size: 0.82rem;
  text-align: left;
  line-height: 1.4;
}

.auth-hint code {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: #2C2416;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: var(--bg-elevated);
  border: 2px solid #2C2416;
  border-radius: 999px;
  padding: 6px 8px 6px 6px;
  margin-bottom: 14px;
  box-shadow: 2px 2px 0 rgba(44, 36, 22, 0.2);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-card);
  border: 2px solid var(--slime-dim);
  flex-shrink: 0;
}

.user-meta {
  flex: 1;
  min-width: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-handle {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.82rem;
  flex-shrink: 0;
}

.brand-compact h1 {
  font-size: clamp(1.4rem, 5vw, 1.85rem);
}

.brand-compact .tagline {
  margin-top: 4px;
}

/* ─── Buttons ───────────────────────────────────────────────────── */
.btn {
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.95rem;
  border: 2px solid #2C2416;
  border-radius: 999px;
  cursor: pointer;
  min-height: 44px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s, background 0.15s, box-shadow 0.15s, opacity 0.15s;
  user-select: none;
  box-shadow: 3px 3px 0 rgba(44, 36, 22, 0.3);
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible {
  outline: 2px solid var(--slime-bright);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(180deg, #3DB5A3 0%, var(--slime) 55%, var(--slime-dim) 100%);
  color: #FFFBF3;
  box-shadow: 3px 3px 0 rgba(44, 36, 22, 0.35);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 2px solid #2C2416;
}

.btn-secondary:hover {
  border-color: var(--slime-dim);
  color: var(--slime-dim);
}

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

.btn-ghost:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--gold, #E9C46A) 18%, transparent);
  border-color: #2C2416;
}

.btn-lg {
  width: 100%;
  min-height: 52px;
  font-size: 1.05rem;
}

/* ─── HUD / play ────────────────────────────────────────────────── */
.hud {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding-top: 4px;
}

.hud-center {
  text-align: center;
  min-width: 0;
}

.hud-title {
  margin: 0;
  font-size: clamp(0.95rem, 3.5vw, 1.1rem);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.hud-meta .dot {
  margin: 0 4px;
  opacity: 0.5;
}

.timer-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 2px solid #2C2416;
  border-radius: 999px;
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 1.05rem;
  min-width: 5.5rem;
  justify-content: center;
  color: var(--slime-dim);
  box-shadow: 2px 2px 0 rgba(44, 36, 22, 0.2);
}

.timer-icon {
  font-size: 0.9rem;
  opacity: 0.85;
}

#btn-menu {
  padding: 0 12px;
  font-size: 0.88rem;
}

.stats-bar {
  display: flex;
  justify-content: center;
  gap: 24px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.stat-value {
  font-family: var(--mono);
  font-size: 1.15rem;
  color: var(--text);
}

/* ─── Board ─────────────────────────────────────────────────────── */
.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 4px 0;
}

.board {
  --cols: 5;
  --gap: 2px;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: var(--gap);
  width: min(100%, calc(100dvh - 240px), 480px);
  aspect-ratio: 1;
  background: #061510;
  border: 3px solid #2C2416;
  border-radius: 16px;
  padding: var(--gap);
  box-shadow: 5px 5px 0 var(--coral, #E76F51);
  user-select: none;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  margin: 0;
  background: var(--tile-bg);
  border-radius: 4px !important; /* keep square blocks; site-theme buttons are pills */
  cursor: pointer;
  overflow: hidden;
  touch-action: manipulation;
  transition: background 0.15s, box-shadow 0.2s;
}

.cell:focus-visible {
  outline: 2px solid var(--slime-bright);
  outline-offset: -2px;
  z-index: 2;
}

.cell:active {
  transform: scale(0.96);
}

.cell.filled {
  background: #0a2a22;
  box-shadow: inset 0 0 12px var(--water-glow);
}

.cell.source {
  box-shadow: inset 0 0 16px rgba(36, 157, 143, 0.28);
}

.cell.source.filled {
  box-shadow:
    inset 0 0 16px var(--water-glow),
    0 0 8px var(--slime-glow);
}

/* Pipe SVG layer */
.cell .pipe-svg {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  transition: transform 0.18s cubic-bezier(0.34, 1.4, 0.64, 1);
  transform: rotate(var(--rot, 0deg));
}

.cell.spinning .pipe-svg {
  transition: transform 0.18s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.cell.locked {
  cursor: default;
  opacity: 0.92;
}

.cell.locked::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rust);
  box-shadow: 0 0 6px var(--rust);
  z-index: 3;
}

.play-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  padding-top: 4px;
}

.play-actions .btn {
  flex: 1;
  max-width: 200px;
}

/* ─── Win modal ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(26, 43, 51, 0.45);
  backdrop-filter: blur(4px);
  animation: fade-in 0.25s ease;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: transparent;
  animation: fade-in 0.25s ease;
  pointer-events: none;
}

.modal:not([hidden]) {
  pointer-events: auto;
}

.modal[hidden] {
  display: none !important;
}

body.modal-open {
  overflow: hidden;
}

.modal-card {
  width: min(100%, 360px);
  background: var(--bg-elevated);
  border: 3px solid #2C2416;
  border-radius: var(--radius);
  padding: 28px 24px 22px;
  text-align: center;
  box-shadow: 6px 6px 0 var(--gold, #E9C46A);
  animation: pop-in 0.35s cubic-bezier(0.34, 1.3, 0.64, 1);
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.9) translateY(12px); }
  to { opacity: 1; transform: none; }
}

.win-burst {
  font-size: 2.5rem;
  line-height: 1;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 12px var(--water-glow));
  animation: bounce 0.6s ease;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-10px); }
  70% { transform: translateY(-4px); }
}

.modal-card h2 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--slime-dim);
  font-family: "Waukegan LDO", "Eurostile", "Arial Narrow", system-ui, sans-serif;
}

.win-sub {
  margin: 6px 0 18px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.win-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 0 22px;
  text-align: left;
}

.win-stats > div {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border: 2px solid #2C2416;
}

.win-stats dt {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 2px;
}

.win-stats dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.1rem;
  color: var(--text);
  text-transform: capitalize;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-actions .btn {
  width: 100%;
}

.btn-x-share {
  background: linear-gradient(180deg, #E9C46A 0%, #D4A84A 100%) !important;
  color: #2C2416 !important;
  border: 2px solid #2C2416 !important;
  font-weight: 800;
}

.btn-x-share:hover {
  filter: brightness(0.95);
}

.modal-fineprint {
  margin: 12px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.board.won {
  pointer-events: none;
  opacity: 0.92;
}

.board.won .cell {
  cursor: default;
}

/* ─── Responsive ────────────────────────────────────────────────── */
@media (min-width: 600px) {
  .app {
    max-width: 640px;
    padding: calc(24px + var(--safe-top)) 24px calc(28px + var(--safe-bottom));
  }

  .segmented {
    grid-template-columns: repeat(6, 1fr);
  }

  .board {
    --gap: 2px;
  }
}

@media (max-width: 380px) {
  .hud {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 10px;
  }

  .hud-center {
    order: -1;
  }

  #btn-menu {
    justify-self: start;
  }

  .timer-wrap {
    justify-self: end;
    grid-row: 2;
    grid-column: 1;
  }

  .hud {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .hud-center {
    width: 100%;
    order: -1;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .app {
    max-width: 100%;
    padding: 8px 16px;
  }

  #play-screen.active {
    display: grid;
    grid-template-columns: 1fr min(50vh, 50vw) 1fr;
    grid-template-rows: auto 1fr auto;
    gap: 8px 12px;
    align-items: center;
  }

  #play-screen .hud {
    grid-column: 1 / -1;
  }

  #play-screen .stats-bar {
    grid-column: 1;
    flex-direction: column;
    gap: 12px;
  }

  #play-screen .board-wrap {
    grid-column: 2;
    grid-row: 2 / 4;
  }

  #play-screen .play-actions {
    grid-column: 3;
    flex-direction: column;
    align-items: stretch;
  }

  #play-screen .play-actions .btn {
    max-width: none;
  }

  .board {
    width: min(50vh, 50vw, 360px);
  }

  .brand h1 {
    font-size: 1.5rem;
  }
}

/* Win celebration pulse on board */
.board.won .cell.filled {
  animation: fill-pulse 1.2s ease infinite alternate;
}

@keyframes fill-pulse {
  from { box-shadow: inset 0 0 8px var(--water-glow); }
  to { box-shadow: inset 0 0 18px var(--water-glow); }
}


/* Site integration */
.nav-home-wrap { margin: 0 0 8px; }
.nav-home {
  color: rgba(180, 230, 200, 0.9);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.nav-home:hover { text-decoration: underline; color: #fff; }
.score-note {
  margin: 8px 0 0;
  color: #7dffa3;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
}

.daily-brief {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(120, 200, 160, 0.25);
  background: rgba(20, 50, 40, 0.45);
  color: rgba(210, 240, 220, 0.95);
  font-size: 0.95rem;
  line-height: 1.45;
}


h1, h2 {
  font-family: "Waukegan LDO", "Eurostile", "Arial Narrow", system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Puzzle info box under How to play (matches One Stroke) */
.side-meta {
  background: rgba(20, 50, 40, 0.55);
  border: 1px solid rgba(61, 204, 122, 0.22);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
  color: var(--text-muted, #8fb5a3);
  margin: 0 12px 12px;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}
.side-meta dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
}
.side-meta dt {
  color: var(--text-muted, #8fb5a3);
  font-weight: 500;
}
.side-meta dd {
  margin: 0;
  color: var(--text, #e8f5ee);
  font-weight: 600;
}

/* CORAL-EMPHASIS */
.btn-primary {
  box-shadow: 0 8px 20px rgba(36, 157, 143, 0.3);
}
.btn-ghost:hover,
.btn-secondary:hover {
  border-color: #E76F51 !important;
  color: #E76F51 !important;
}
.score-note,
.modal-fineprint {
  color: color-mix(in srgb, #E76F51 55%, var(--text-muted));
}
#btn-share-toolbar {
  background: linear-gradient(180deg, #E9C46A, #D4A84A) !important;
  color: #2C2416 !important;
}
.hud-title {
  color: #E76F51 !important;
}
