/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Game container ─────────────────────────────────────────── */
#game-container {
  width: 100%;
  max-width: 480px;
  padding: 0 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  user-select: none;
  -webkit-user-select: none;
}


/* ── Paper background — shared by board, picker, marker-picker ─ */
/* #FFF3CF + grid overlay (4% lines at 8px + 64px) matching PaperPattern.swift */
.board, .guess-container, .picker, .marker-picker,
.color-hints-standalone, .color-hints-sidebar {
  background-color: #FFF3CF;
  background-image:
    repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
    repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
    repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px),
    repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px);
  border: 4px solid black;
  background-clip: padding-box;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}

/* ── Board ──────────────────────────────────────────────────── */
.board {
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Row ────────────────────────────────────────────────────── */
.row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.row .pieces {
  display: flex;
  gap: 8px;
  flex: 1;
}

/* ── Piece ──────────────────────────────────────────────────── */
.piece {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  box-sizing: border-box;
  cursor: default;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  transition: box-shadow 0.12s ease;
  background-color: transparent;
}
/* SVG backgrounds: piece color classes are defined in ../style.css */
.piece .marker {
  pointer-events: none;
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.9);
}
/* wrongColor marker: wrapper keeps piece + mini-piece in the same flow position.
   The faded piece sits inside; the mini-piece is a sibling so it renders at full opacity. */
.piece-wrongcolor-wrap {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 52px;
}
/* Mini-piece centered on the bottom-right corner — ~20% outside the parent. */
.mini-piece {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 2;
}
/* Tappable pieces — pointer cursor and brightness hover (board, pickers, color hints) */
.piece.tappable {
  cursor: pointer;
}
.piece.tappable:hover {
  filter: brightness(1.08);
}
.piece.tappable:active {
  filter: brightness(0.92);
}
/* Selected piece gets a blue ring (same as guess-row selection) */
.board .piece.mark-selected {
  box-shadow: 0 0 0 3px #0A84FF;
  z-index: 1;
}
/* Interactive board pieces are <button> — reset browser button appearance */
.board button.piece {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  font: inherit;
}
/* wrongColor interactive pieces use a button wrapper instead of the piece itself */
button.piece-wrongcolor-wrap {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  font: inherit;
}
.piece-wrongcolor-wrap.tappable,
.piece-wrongcolor-wrap.tappable .piece {
  cursor: pointer;
}
.piece-wrongcolor-wrap.tappable:hover {
  filter: brightness(1.08);
}
.piece-wrongcolor-wrap.tappable:active {
  filter: brightness(0.92);
}
.board button.piece-wrongcolor-wrap.mark-selected {
  box-shadow: 0 0 0 3px #0A84FF;
  z-index: 1;
}

/* ── Marker picker overlay ───────────────────────────────────── */
/* Floating panel — paper background matching the board.
   Initial position is offscreen; JS (positionMarkerPicker) sets top/left
   after the DOM is updated so it appears above the tapped piece. */
.marker-picker {
  position: fixed;
  top: -9999px;
  left: 0;
  z-index: 100;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  padding: 14px 16px;
}
.marker-picker-options {
  display: flex;
  gap: 10px;
  align-items: center;
}
/* Each option is a plain button wrapping a .piece */
.marker-option {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 12px;
}
/* Highlight the currently-active marker with a blue ring */
.marker-option.active .piece {
  box-shadow: 0 0 0 3px #0A84FF;
}
/* Highlight the currently-selected color swatch */
.picker-swatch.active .piece {
  box-shadow: 0 0 0 3px #0A84FF;
}
/* Guess row */
.guess-row .piece {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background-color: transparent;
}
.guess-row .piece:hover {
  filter: brightness(1.08);
}
.guess-row .piece:active {
  filter: brightness(0.92);
}
.guess-row .piece.empty {
  background-image: none;
  border: 2px dashed rgba(0,0,0,0.25);
}
.guess-row .piece.selected {
  box-shadow: 0 0 0 3px #0A84FF;
  z-index: 1;
}
.guess-row .piece.empty.selected {
  border-color: transparent;
}


/* ── Hints ──────────────────────────────────────────────────── */
button.hints, div.hints {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 52px;
  flex-shrink: 0;
  padding: 4px 0;
  border-radius: 8px;
}
button.hints {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
button.hints:hover {
  background: rgba(0,0,0,0.06);
}
button.hints:active {
  background: rgba(0,0,0,0.12);
}
.hint {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 900;
}
.hint.correct  { color: black; }
.hint.misplaced { color: black; }
.hints-placeholder { width: 52px; flex-shrink: 0; }

/* Divider between preset rows and guess row */
.guess-container {
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Color picker overlay ───────────────────────────────────── */
.picker {
  position: fixed;
  top: -9999px;
  left: 0;
  z-index: 100;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  padding: 14px 16px;
}
.picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: center;
  gap: 8px;
}
.picker-swatch {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 12px;
}
.picker-erase {
  grid-column: 1 / -1;
  width: 100%;
  height: 52px;
  padding: 0 16px;
  background: #8E8E93;
  border: 4px solid black;
  border-radius: 8px;
  background-clip: padding-box;
  box-shadow: inset -2px -4px 0 rgba(0,0,0,0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.picker-erase:hover {
  filter: brightness(1.08);
}
.picker-erase:active {
  filter: brightness(0.92);
}

/* ── Game layout (board + color hints sidebar) ──────────────── */
.game-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}
.game-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Color hints panel ──────────────────────────────────────── */
.color-hints {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.color-hint-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 12px;
}
.color-hint-btn:disabled {
  cursor: default;
}
.color-hint-btn:disabled .piece {
  cursor: default;
  pointer-events: none;
}

/* Inline hints: shown inside guess-container on narrow, hidden on wide */
.color-hints-bottom {
  flex-direction: row;
  justify-content: center;
  padding-top: 10px;
  margin-top: 6px;
  border-top: 1px solid rgba(0,0,0,0.1);
}
/* Standalone version (after winning when guess-container is gone) */
.color-hints-standalone {
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 0; /* gap provided by game-main */
  border-top: 4px solid black; /* already has border from paper rule */
}

/* Sidebar: hidden on narrow, shown on wide */
.color-hints-sidebar {
  display: none;
  flex-direction: column;
  flex-wrap: nowrap;
  justify-content: flex-start;
  border-radius: 12px;
  padding: 14px 12px;
  gap: 8px;
}

/* ── Board controls (reset markers inside board) ────────────── */
.board-controls {
  display: flex;
  justify-content: flex-end;
}

/* ── Buttons ────────────────────────────────────────────────── */
/* Piece-tile button: yellow tint, 4px black border, depth shadow */
.btn {
  padding: 8px 16px;
  background: #FFD60A;
  color: black;
  font-size: 16px;
  font-weight: 900;
  border: 4px solid black;
  border-radius: 8px;
  background-clip: padding-box;
  cursor: pointer;
  box-shadow: inset -2px -4px 0 #C7A708;
}
.btn:hover:not(:disabled) {
  filter: brightness(1.08);
}
.btn:active:not(:disabled) {
  filter: brightness(0.92);
}
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-wide {
  padding: 8px 32px;
}
.btn-submit {
  width: 52px;
  height: 52px;
  padding: 0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 900;
  border-width: 3px;
  box-shadow: inset -1px -3px 0 #C7A708;
}

/* ── Hint overlay ───────────────────────────────────────────── */
.hint-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}
.hint-overlay-card {
  background-color: #FFF3CF;
  background-image:
    repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
    repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
    repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px),
    repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px);
  border: 4px solid black;
  border-radius: 16px;
  background-clip: padding-box;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: winPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hint-overlay-pieces {
  display: flex;
  gap: 8px;
}
.hint-overlay-counts {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.hint-overlay-counts .hint {
  font-size: 20px;
  font-weight: 900;
}

/* ── Week navigation ────────────────────────────────────────── */
.week-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.week-nav-days {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.week-btn {
  padding: 6px 10px;
  background: #FFD60A;
  color: black;
  font-size: 13px;
  font-weight: 900;
  border: 3px solid black;
  border-radius: 8px;
  background-clip: padding-box;
  cursor: pointer;
  box-shadow: inset -1px -3px 0 #C7A708;
  min-width: 40px;
}
.week-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}
.week-btn:active:not(:disabled) {
  filter: brightness(0.92);
}
.week-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}
.week-btn-selected {
  background: #34C759;
  box-shadow: inset -1px -3px 0 #248A3D;
}
.week-nav-hint {
  font-size: 12px;
  color: #6e6e73;
  text-align: center;
}

/* ── Win banner ─────────────────────────────────────────────── */
.win-banner {
  background-color: #FFF3CF;
  background-image:
    repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
    repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
    repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px),
    repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px);
  border: 4px solid black;
  border-radius: 12px;
  background-clip: padding-box;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
  padding: 24px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: winPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes winPop {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.win-icon     { font-size: 48px; line-height: 1; }
.win-title    { font-size: 28px; font-weight: 900; color: black; }
.win-next     { font-size: 14px; color: #6e6e73; }
.win-next #next-puzzle-countdown { font-weight: 700; color: #3a3a3c; font-variant-numeric: tabular-nums; }
.win-replay   { margin-top: 4px; }

/* ── Loading state ──────────────────────────────────────────── */
.loading {
  text-align: center;
  color: #3a3a3c;
  padding: 48px 0;
  font-size: 15px;
}

/* ── Dark mode ──────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  .board, .guess-container, .picker, .marker-picker,
  .color-hints-standalone, .color-hints-sidebar {
    background-color: #2c2c2e;
    background-image:
      repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
      repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
      repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px),
      repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px);
  }

  .hint.correct, .hint.misplaced { color: #fff; }
  .hint img { filter: invert(1); }
  .loading { color: rgba(255,255,255,0.75); }

  button.hints:hover { background: rgba(255,255,255,0.08); }
  button.hints:active { background: rgba(255,255,255,0.14); }

  .win-banner {
    background-color: #2c2c2e;
    background-image:
      repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
      repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
      repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px),
      repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px);
  }
  .win-title    { color: #fff; }
  .win-next     { color: rgba(255,255,255,0.5); }
  .win-next #next-puzzle-countdown { color: rgba(255,255,255,0.85); }

  .hint-overlay-card {
    background-color: #2c2c2e;
    background-image:
      repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
      repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 64px),
      repeating-linear-gradient(0deg,   rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px),
      repeating-linear-gradient(90deg,  rgba(0,0,0,0.04) 0, rgba(0,0,0,0.04) 1px, transparent 1px, transparent 8px);
  }

  .week-nav-hint { color: rgba(255,255,255,0.45); }
  .week-btn:disabled { opacity: 0.3; }
}

/* ── Responsive ─────────────────────────────────────────────── */
/* Wide viewport: show color hints as a sidebar column to the right of the board.
   Required: board (~396px) + gap (16px) + sidebar (~76px) + container padding (40px)
   + body padding (32px) ≈ 560px → breakpoint at 560px. */
@media (min-width: 560px) {
  #game-container {
    max-width: 548px;
  }
  .game-layout {
    flex-direction: row;
    align-items: flex-start;
    gap: 16px;
  }
  .game-main {
    flex: 1;
    min-width: 0;
  }
  /* Hide inline hints on wide (sidebar takes over) */
  .color-hints-bottom {
    display: none;
  }
  /* Show sidebar */
  .color-hints-sidebar {
    display: flex;
    flex-shrink: 0;
    align-items: center;
  }
}

/* Compact appearance */
@media (max-width: 468px) {
  .board, .guess-container { padding: 14px 10px; }
  .piece { width: 40px; height: 40px; border-radius: 8px; }
  .piece-wrongcolor-wrap { width: 40px; height: 40px; }
  .picker-swatch { height: 40px; }
  .row { gap: 8px; }
  .row .pieces { gap: 5px; }
  button.hints, div.hints, .hints-placeholder { width: 36px; }
  .btn-submit { width: 36px; height: 40px; }
  .picker-erase { height: 40px; }
}
