/* ============================================================
   Sudoku for Two 💕 — cozy co-op sudoku for long-distance love
   Mobile-first, scales up to desktop.
   ============================================================ */

:root {
  /* palette */
  --bg-grad-1: #ffe3ee;          /* soft pink */
  --bg-grad-2: #e6e0fa;          /* soft lavender */
  --bg-grad-3: #fdeef4;
  --card-bg: #ffffff;
  --ink: #4a3b52;                /* warm dark plum for text */
  --ink-soft: #8b7a96;
  --line-soft: #e9dff0;          /* thin grid lines */
  --line-strong: #b9a6cc;        /* 3x3 box lines + outer border */

  --pink: #f06292;               /* "mine" accent */
  --pink-soft: #fde6ef;
  --purple: #7e6bd9;             /* "partner" accent */
  --purple-soft: #e9e4fb;

  --green: #2e9e5b;
  --green-soft: #ddf3e4;
  --amber: #b07d18;
  --amber-soft: #fdf0d3;
  --red: #d64550;
  --red-soft: #fde3e5;

  --radius-card: 22px;
  --radius-btn: 16px;
  --shadow-card: 0 10px 30px rgba(122, 90, 145, 0.18);
  --shadow-btn: 0 6px 16px rgba(240, 98, 146, 0.35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: "Quicksand", "Nunito", -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-grad-1) 0%, var(--bg-grad-3) 45%, var(--bg-grad-2) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* the one rule the JS glue absolutely depends on */
.hidden {
  display: none !important;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ============================================================
   Shared bits
   ============================================================ */

.card {
  background: var(--card-bg);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 28px 24px;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: var(--radius-btn);
  font-size: 18px;
  font-weight: 700;
  padding: 16px 24px;
  min-height: 54px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--pink) 0%, #ec5fb0 100%);
  color: #fff;
  box-shadow: var(--shadow-btn);
}

.btn-primary:hover {
  box-shadow: 0 8px 20px rgba(240, 98, 146, 0.45);
}

.btn-secondary {
  background: var(--purple-soft);
  color: var(--purple);
  box-shadow: 0 4px 12px rgba(126, 107, 217, 0.18);
}

.btn-secondary:hover {
  background: #ded6f9;
}

/* ============================================================
   HOME SCREEN
   ============================================================ */

#screen-home {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.home-card {
  width: min(100%, 400px);
  text-align: center;
}

.app-title {
  margin: 0 0 6px;
  font-size: clamp(28px, 8vw, 36px);
  font-weight: 700;
  letter-spacing: 0.3px;
}

.title-heart {
  display: inline-block;
  animation: heartbeat 1.8s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  12%       { transform: scale(1.18); }
  24%       { transform: scale(1); }
  36%       { transform: scale(1.12); }
  48%       { transform: scale(1); }
}

.tagline {
  margin: 0 0 26px;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 500;
  font-style: italic;
}

#btn-create {
  width: 100%;
  font-size: 20px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 18px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line-soft);
}

.join-row {
  display: flex;
  gap: 10px;
}

#join-code {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 22px;             /* ≥16px: no iOS zoom on focus */
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.45em;
  text-indent: 0.45em;         /* re-center despite letter-spacing */
  color: var(--ink);
  background: #faf7fd;
  border: 2px solid var(--line-soft);
  border-radius: var(--radius-btn);
  padding: 12px 8px;
  min-height: 54px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#join-code::placeholder {
  color: #c9bbd6;
  letter-spacing: 0.3em;
}

#join-code:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 4px rgba(240, 98, 146, 0.15);
}

#btn-join {
  flex: 0 0 auto;
  padding: 16px 28px;
}

#home-status {
  min-height: 1.4em;
  margin: 16px 0 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--red);
}

/* ============================================================
   GAME SCREEN
   ============================================================ */

#screen-game {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 16px 12px 28px;
}

/* --- top bar --- */

.top-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 12px 16px;
}

#room-code-display {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--ink);
  cursor: pointer;
  border-bottom: 2px dashed var(--line-strong);
  padding-bottom: 1px;
  user-select: none;
  -webkit-user-select: none;
}

#room-code-display::after {
  content: " 📋";
  font-size: 14px;
  letter-spacing: normal;
}

#room-code-display:hover {
  border-bottom-color: var(--pink);
  color: var(--pink);
}

#peer-status {
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--amber-soft);
  color: var(--amber);
  transition: background-color 0.2s ease, color 0.2s ease;
}

#peer-status::before {
  content: "● ";
  font-size: 10px;
  vertical-align: 1px;
}

#peer-status[data-state="connecting"] {
  background: var(--amber-soft);
  color: var(--amber);
}

#peer-status[data-state="connected"] {
  background: var(--green-soft);
  color: var(--green);
}

#peer-status[data-state="disconnected"] {
  background: var(--red-soft);
  color: var(--red);
}

/* --- legend --- */

.legend {
  display: flex;
  gap: 10px;
}

.legend-chip {
  font-size: 13px;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: 999px;
}

.legend-chip::before {
  content: "♥ ";
}

.legend-chip.mine {
  background: var(--pink-soft);
  color: var(--pink);
  border: 1.5px solid var(--pink);
}

.legend-chip.partner {
  background: var(--purple-soft);
  color: var(--purple);
  border: 1.5px solid var(--purple);
}

/* --- the board --- */

#board {
  width: min(92vw, 460px);
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  background: var(--card-bg);
  border: 3px solid var(--line-strong);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.cell {
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  width: 100%;
  margin: 0;
  padding: 0;
  background: var(--card-bg);
  border: none;
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  font-family: inherit;
  font-size: clamp(18px, 4.8vw, 26px);
  font-weight: 600;
  color: var(--ink);
  transition: background-color 0.1s ease;
}

/* thicker 3x3 box separators */
.cell[data-col="2"],
.cell[data-col="5"] {
  border-right: 2.5px solid var(--line-strong);
}

.cell[data-row="2"],
.cell[data-row="5"] {
  border-bottom: 2.5px solid var(--line-strong);
}

.cell[data-col="8"] {
  border-right: none;
}

.cell[data-row="8"] {
  border-bottom: none;
}

/* --- cell states (toggled by JS) --- */

.cell.given {
  font-weight: 700;
  color: #352a3d;
  background: #f4eff8;
}

.cell.mine {
  color: var(--pink);
}

.cell.partner {
  color: var(--purple);
}

.cell.selected {
  background: #ffd3e3;
}

.cell.given.selected {
  background: #f0c9da;
}

.cell.error {
  color: var(--red);
  background: var(--red-soft);
}

.cell.error.selected {
  background: #fbcdd1;
}

/* partner's cursor: an inner ring that survives any background state */
.cell.partner-cursor {
  box-shadow: inset 0 0 0 3px var(--purple),
              inset 0 0 10px rgba(126, 107, 217, 0.35);
}

/* ============================================================
   NUMPAD
   ============================================================ */

#numpad {
  width: min(92vw, 460px);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

#numpad button {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: 14px;
  background: var(--card-bg);
  color: var(--pink);
  font-family: inherit;
  font-size: 24px;
  font-weight: 700;
  min-height: 56px;
  box-shadow: 0 4px 10px rgba(122, 90, 145, 0.14);
  transition: transform 0.1s ease, background-color 0.1s ease;
}

#numpad button:active {
  transform: scale(0.94);
  background: var(--pink-soft);
}

#numpad button.numpad-erase,
#numpad button[data-num="0"] {
  color: var(--ink-soft);
  background: #f6f1fa;
}

#btn-new-game {
  margin-top: 4px;
  font-size: 16px;
  padding: 13px 26px;
  min-height: 48px;
}

/* ============================================================
   WIN OVERLAY
   ============================================================ */

#win-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(74, 59, 82, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.win-card {
  position: relative;
  z-index: 2;
  width: min(100%, 380px);
  text-align: center;
  animation: pop-in 0.45s cubic-bezier(0.18, 1.25, 0.4, 1) both;
}

@keyframes pop-in {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.win-title {
  margin: 0 0 8px;
  font-size: 26px;
}

.win-sub {
  margin: 0 0 22px;
  color: var(--ink-soft);
  font-weight: 500;
}

#btn-play-again {
  width: 100%;
  font-size: 19px;
}

/* floating hearts */

.hearts {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.float-heart {
  position: absolute;
  bottom: -60px;
  font-size: 30px;
  animation: float-up 5s linear infinite;
  opacity: 0;
}

.float-heart:nth-child(1) { left: 8%;  font-size: 26px; animation-duration: 5.2s; animation-delay: 0s; }
.float-heart:nth-child(2) { left: 24%; font-size: 36px; animation-duration: 6.5s; animation-delay: 1.1s; }
.float-heart:nth-child(3) { left: 42%; font-size: 24px; animation-duration: 4.6s; animation-delay: 0.5s; }
.float-heart:nth-child(4) { left: 58%; font-size: 40px; animation-duration: 7s;   animation-delay: 1.8s; }
.float-heart:nth-child(5) { left: 74%; font-size: 28px; animation-duration: 5.6s; animation-delay: 0.2s; }
.float-heart:nth-child(6) { left: 88%; font-size: 32px; animation-duration: 6.1s; animation-delay: 2.4s; }

@keyframes float-up {
  0% {
    transform: translateY(0) rotate(-8deg);
    opacity: 0;
  }
  10% {
    opacity: 0.9;
  }
  50% {
    transform: translateY(-55vh) rotate(8deg) translateX(14px);
    opacity: 0.85;
  }
  100% {
    transform: translateY(-110vh) rotate(-6deg) translateX(-10px);
    opacity: 0;
  }
}

/* ============================================================
   TOAST
   ============================================================ */

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 200;
  transform: translateX(-50%) translateY(16px);
  max-width: min(88vw, 360px);
  background: rgba(58, 44, 66, 0.94);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}

#toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   BIGGER SCREENS
   ============================================================ */

@media (min-width: 700px) {
  #screen-game {
    padding-top: 32px;
    gap: 18px;
  }

  #numpad {
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
  }

  #numpad button {
    min-height: 50px;
    font-size: 21px;
  }

  .cell {
    font-size: 27px;
  }
}

/* be gentle with motion-sensitive users */
@media (prefers-reduced-motion: reduce) {
  .title-heart,
  .float-heart {
    animation: none;
  }

  .float-heart {
    opacity: 0.7;
    bottom: auto;
    top: 12%;
  }
}
