:root {
  --red: #b3121b;
  --red-dark: #8c0d14;
  --green: #1f5f3a;
  --green-dark: #184b2e;
  --gold: #e3a92b;
  --ink: #1d1d1f;
  --muted: #5d6066;
  --line: #e3dccf;
  --paper: #fffdf8;
  --bg: #f4efe6;
  --word: rgba(255, 205, 80, 0.5);
  --active: rgba(255, 170, 0, 0.78);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html {
  /* Never a sideways scrollbar, whatever the content does */
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(179, 18, 27, 0.09), transparent 60%),
    radial-gradient(900px 500px at 95% 0%, rgba(31, 95, 58, 0.09), transparent 55%),
    var(--bg);
  min-height: 100vh;
  overflow-x: clip;
}

/* ------------------------------------------------------------ header */

.masthead {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 16px 14px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green);
}

.masthead h1 {
  margin: 0 0 8px;
  font-size: clamp(1.7rem, 5vw, 2.6rem);
  line-height: 1.1;
  color: var(--red);
  letter-spacing: -0.01em;
}

.lead {
  margin: 0 auto;
  max-width: 600px;
  color: var(--muted);
  line-height: 1.5;
}

.closing {
  display: inline-block;
  margin: 12px 0 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(31, 95, 58, 0.1);
  color: var(--green);
  font-weight: 600;
  font-size: 0.9rem;
}

.closing:empty {
  display: none;
}

/* ------------------------------------------------------------ toolbar */

.bar-wrap {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}

.toolbar {
  max-width: 1000px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

.hidden-word {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.hidden-word .label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.letters {
  display: flex;
  gap: 3px;
}

.slot {
  position: relative;
  width: 28px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  border: 1.5px solid #e6b9bc;
  background: #fdeced;
  color: var(--ink);
  font: 800 1rem/1 system-ui, sans-serif;
  cursor: pointer;
}

.slot::before {
  content: attr(data-n);
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 0.55rem;
  font-weight: 700;
  color: var(--red);
}

.slot:hover {
  border-color: var(--red);
}

.actions-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid #d8d0c1;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:hover:not(:disabled) {
  background: #f7f2e8;
}

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

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn:focus-visible,
.slot:focus-visible,
a:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--green-dark);
}

.btn.accent {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.btn.accent:hover:not(:disabled) {
  background: var(--red-dark);
}

.btn.danger {
  border-color: var(--red);
  color: var(--red);
}

.btn.icon {
  width: 40px;
  padding: 0;
}

.btn.icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn.icon svg .fill {
  fill: currentColor;
  stroke: none;
}

.progress {
  height: 3px;
}

#progress-bar {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), #48a46b);
  transition: width 0.3s;
}

/* ------------------------------------------------------------ puzzle */

main {
  position: relative;
  z-index: 1;
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px 16px 0;
}

/* The puzzle is part of the page: no box of its own that scrolls. */
.puzzle {
  position: relative;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.06),
    0 12px 40px rgba(60, 30, 10, 0.12);
}

.puzzle img {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.grid {
  position: absolute;
}

.cell {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: calc(var(--square, 40px) * 0.1);
  font-family: "Arial Black", "Segoe UI", Arial, sans-serif;
  font-weight: 800;
  font-size: calc(var(--square, 40px) * 0.56);
  line-height: 1;
  color: #10203a;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color 0.12s;
}

.cell:hover {
  background: rgba(255, 205, 80, 0.22);
}

.cell.in-word {
  background: var(--word);
}

.cell.active {
  background: var(--active);
  box-shadow: inset 0 0 0 2px #c77800;
}

/* Without focus the selection stays visible, just quieter */
.puzzle:not(.focused) .cell.active {
  background: var(--word);
  box-shadow: inset 0 0 0 2px rgba(199, 120, 0, 0.6);
}

/* The keyboard's target: sits on the chosen square, invisible. 16px stops iOS zooming in. */
.entry {
  position: absolute;
  left: 0;
  top: 0;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font-size: 16px;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}

.progress-text {
  margin: 10px 0 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.load-error {
  text-align: center;
  color: var(--red);
  font-weight: 600;
}

/* ------------------------------------------------------------ footer */

.footer {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 28px auto 40px;
  padding: 0 16px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

.footer p {
  margin: 4px 0;
}

.footer a {
  color: var(--red);
}

/* ------------------------------------------------------------ dialog */

.dialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.3);
  background: var(--paper);
  color: var(--ink);
}

.dialog::backdrop {
  background: rgba(25, 12, 10, 0.45);
  backdrop-filter: blur(2px);
}

.dialog-body {
  padding: 24px 24px 20px;
}

.dialog h2 {
  margin: 0 0 10px;
  color: var(--red);
  font-size: 1.3rem;
}

.dialog p,
.dialog li {
  line-height: 1.5;
}

.dialog ul {
  padding-left: 20px;
}

.dialog li + li {
  margin-top: 6px;
}

.dialog .big {
  font-size: 2.2rem;
  font-weight: 800;
  margin: 4px 0;
  color: var(--green);
}

.dialog .ok {
  color: var(--green);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

form label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 600;
}

form input:not([type="checkbox"]) {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  border: 1px solid #cfc7b8;
  border-radius: 10px;
  font: inherit;
  font-size: 16px;
  background: #fff;
}

form input:focus {
  outline: 2px solid var(--gold);
  border-color: var(--gold);
}

form .consent {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--muted);
}

form .consent input {
  margin-top: 2px;
  width: 18px;
  height: 18px;
  flex: none;
  accent-color: var(--green);
}

.hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.form-error {
  min-height: 1.2em;
  margin: 4px 0 0;
  color: var(--red);
  font-weight: 600;
}

/* ------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 40px);
  opacity: 0;
  background: #222;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------ snow (behind the page) */

.snow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.snow span {
  position: absolute;
  top: -24px;
  color: #fff;
  text-shadow: 0 0 3px rgba(120, 140, 170, 0.55);
  animation-name: fall, sway;
  animation-timing-function: linear, ease-in-out;
  animation-iteration-count: infinite, infinite;
  animation-direction: normal, alternate;
}

@keyframes fall {
  to {
    transform: translateY(110vh);
  }
}

@keyframes sway {
  from {
    margin-left: -12px;
  }
  to {
    margin-left: 12px;
  }
}

/* ------------------------------------------------------------ phones */

@media (max-width: 720px) {
  .masthead {
    padding: 18px 16px 10px;
  }
  .lead {
    font-size: 0.92rem;
  }
  .toolbar {
    padding: 8px 12px;
    justify-content: center;
  }
  .hidden-word {
    width: 100%;
    justify-content: center;
  }
  .hidden-word .label {
    display: none;
  }
  .slot {
    width: min(30px, calc((100vw - 60px) / 10));
    height: 30px;
    font-size: 0.95rem;
  }
  .actions-row {
    width: 100%;
    justify-content: center;
  }
  .btn {
    height: 38px;
    padding: 0 14px;
  }
  .btn.icon {
    width: 38px;
  }
  main {
    padding: 10px 8px 0;
  }
  .puzzle {
    border-radius: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
