:root {
  --red: #c8102e;
  --red-dark: #8f0b20;
  --green: #2f6b1e;
  --green-dark: #1e4713;
  --brown: #7a4a12;
  --brown-dark: #55330b;
  --gold: #f7b84b;
  --cream: #fff6e3;
  --night: #070b2a;
  --ink: #ffffff;
  --muted: #b9c0e6;
  --panel: rgb(14 20 62 / 0.78);
  --line: rgb(255 255 255 / 0.16);
  --display: "Mountains of Christmas", "Snell Roundhand", cursive;
  --poster: "Anton", Impact, "Arial Narrow Bold", sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 25% 15%, #2a3a8f 0%, transparent 55%),
    radial-gradient(ellipse at 80% 85%, #3a1f6b 0%, transparent 50%),
    linear-gradient(#0a0f3d, #04051a);
  background-attachment: fixed;
}

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.page {
  position: relative;
  z-index: 1;
}

h1,
h2 {
  font-family: var(--display);
  font-weight: 700;
  margin: 0;
  text-wrap: balance;
}

a {
  color: inherit;
}

/* ---- buttons & form controls ------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: 2.6rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgb(255 255 255 / 0.08);
  color: var(--ink);
  font: 600 0.95rem var(--body);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, border-color 0.15s;
}

.btn:hover {
  background: rgb(255 255 255 / 0.18);
}

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

.btn:focus-visible,
.tile:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--red);
  border-color: transparent;
}

.btn--primary:hover {
  background: #e21a3a;
}

.btn--gold {
  background: var(--gold);
  border-color: transparent;
  color: #3a2500;
}

.btn--gold:hover {
  background: #ffcb6b;
}

.btn--danger.is-armed {
  background: var(--red);
  border-color: transparent;
}

.btn[aria-pressed="false"] {
  opacity: 0.55;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field > span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.field small {
  color: var(--muted);
}

input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: rgb(0 0 0 / 0.3);
  color: var(--ink);
  font: 1rem var(--body);
}

textarea {
  resize: vertical;
  min-height: 4.5rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.segmented label {
  display: grid;
  place-items: center;
  gap: 0.2rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  cursor: pointer;
  font-weight: 600;
}

.segmented label span:first-child {
  font-size: 1.8rem;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented label:has(input:checked) {
  border-color: var(--gold);
  background: rgb(247 184 75 / 0.16);
}

.segmented label:has(input:focus-visible) {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.error {
  color: #ff9aa8;
  min-height: 1.3em;
  margin: 0 0 0.6rem;
  font-size: 0.9rem;
}

/* ---- form dialogs ------------------------------------------------------ */

dialog.sheet {
  width: min(30rem, calc(100vw - 2rem));
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  background: #10174a;
  color: var(--ink);
  box-shadow: 0 2rem 5rem rgb(0 0 0 / 0.6);
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.25s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

dialog.sheet[open] {
  opacity: 1;

  @starting-style {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  dialog.sheet {
    transform: translateY(1rem) scale(0.96);
  }

  dialog.sheet[open] {
    transform: none;

    @starting-style {
      transform: translateY(1rem) scale(0.96);
    }
  }
}

dialog.sheet::backdrop {
  background: rgb(3 5 25 / 0.7);
  backdrop-filter: blur(4px);
}

dialog.sheet h2 {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.sheet__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

/* ---- home -------------------------------------------------------------- */

.home {
  max-width: 68rem;
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 4rem) clamp(1rem, 4vw, 2rem);
}

.home__hero {
  text-align: center;
  margin-bottom: 2.5rem;
}

.home__hero h1 {
  font-size: clamp(2.8rem, 9vw, 6rem);
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 0 2rem rgb(247 184 75 / 0.45);
}

.home__hero p {
  max-width: 36rem;
  margin: 1rem auto 1.5rem;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.5;
}

.cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.card {
  flex: 0 1 18rem;
  display: grid;
  gap: 0.8rem;
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  background: var(--panel);
  backdrop-filter: blur(6px);
}

.card__icon {
  font-size: 2.6rem;
  line-height: 1;
}

.card h2 {
  font-size: 1.9rem;
  overflow-wrap: anywhere;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.card__actions {
  display: flex;
  gap: 0.5rem;
}

.card__actions .btn--primary {
  flex: 1;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}

/* ---- play / edit shell ------------------------------------------------- */

.shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  transition: opacity 0.5s;
}

.bar h1 {
  flex: 1;
  min-width: 0;
  font-size: clamp(1.4rem, 3vw, 2.4rem);
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar .btn {
  min-height: 2.3rem;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

body.is-idle .bar {
  opacity: 0;
}

body.is-idle {
  cursor: none;
}

@media (max-width: 720px) {
  .bar {
    flex-wrap: wrap;
  }

  .bar h1 {
    flex-basis: 100%;
  }

  .bar .btn span {
    display: none;
  }
}

.stage {
  flex: 1;
  min-height: 0;
  min-width: 0;
  container-type: size;
  display: grid;
  place-items: center;
  padding: 1vmin 2vmin 2vmin;
}

.message {
  text-align: center;
  color: var(--muted);
  font-size: 1.2rem;
}

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

.board {
  --ratio: 1.5;
  --h: min(calc(100cqh / var(--lines)), calc(100cqw / var(--cols) / var(--ratio)));
  --w: calc(var(--h) * var(--ratio));
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board__star {
  height: calc(var(--h) * 0.8);
  font-size: calc(var(--h) * 0.95);
  line-height: 0.85;
  color: var(--gold);
  text-shadow: 0 0 calc(var(--h) * 0.3) rgb(247 184 75 / 0.8);
}

@media (prefers-reduced-motion: no-preference) {
  .board__star {
    animation: twinkle 2.4s ease-in-out infinite;
  }
}

@keyframes twinkle {
  50% {
    transform: scale(1.12) rotate(8deg);
    text-shadow: 0 0 calc(var(--h) * 0.6) rgb(255 220 150 / 1);
  }
}

.row {
  display: flex;
}

.tile {
  --c: var(--red);
  --c-dark: var(--red-dark);
  position: relative;
  width: var(--w);
  height: var(--h);
  padding: calc(var(--h) * 0.045);
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  perspective: calc(var(--h) * 6);
}

.row--green .tile {
  --c: var(--green);
  --c-dark: var(--green-dark);
}

.row--trunk .tile {
  --c: var(--brown);
  --c-dark: var(--brown-dark);
}

.tile__inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.3, 1.35, 0.5, 1);
}

.tile.is-open .tile__inner {
  transform: rotateY(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .tile__inner {
    transition-duration: 0.01s;
  }
}

.tile:hover .tile__face {
  filter: brightness(1.18);
}

.tile__face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 6%;
  border-radius: calc(var(--h) * 0.3);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  text-align: center;
  overflow: hidden;
  transition: filter 0.15s;
}

.tile__front {
  background: radial-gradient(circle at 30% 20%, rgb(255 255 255 / 0.28), transparent 45%), var(--c);
  box-shadow: inset 0 0 0 calc(var(--h) * 0.035) rgb(255 255 255 / 0.22),
    0 calc(var(--h) * 0.04) calc(var(--h) * 0.1) rgb(0 0 0 / 0.45);
  font-family: var(--display);
  font-weight: 700;
  font-size: calc(var(--h) * 0.52);
  line-height: 1;
  text-shadow: 0 2px 0 rgb(0 0 0 / 0.3);
}

.tile__back {
  transform: rotateY(180deg);
  background: var(--c-dark);
  box-shadow: inset 0 0 0 calc(var(--h) * 0.035) var(--gold);
  font-family: var(--poster);
  font-size: calc(var(--h) * 0.2);
  line-height: 1.08;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.tile__back.is-long {
  font-size: calc(var(--h) * 0.15);
}

.tile__back.is-empty {
  opacity: 0.55;
  font-family: var(--body);
  text-transform: none;
  letter-spacing: 0;
}

/* gifts style */

.board--gifts .row {
  margin-top: calc(var(--h) * 0.22);
}

.board--gifts .tile {
  --c: var(--gift, var(--red));
  --c-dark: var(--gift-dark, var(--red-dark));
  --ribbon: var(--gift-ribbon, var(--gold));
}

.board--gifts .tile__face {
  border-radius: calc(var(--h) * 0.08);
}

.board--gifts .tile__front {
  background:
    linear-gradient(90deg, transparent 42%, var(--ribbon) 42% 58%, transparent 58%),
    linear-gradient(0deg, transparent 40%, var(--ribbon) 40% 60%, transparent 60%),
    repeating-linear-gradient(45deg, rgb(255 255 255 / 0.1) 0 8%, transparent 8% 16%),
    var(--c);
  box-shadow: 0 calc(var(--h) * 0.04) calc(var(--h) * 0.1) rgb(0 0 0 / 0.45);
}

.board--gifts .tile__num {
  display: grid;
  place-items: center;
  width: calc(var(--h) * 0.56);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--cream);
  color: #33230a;
  font-size: calc(var(--h) * 0.36);
  text-shadow: none;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.4);
}

.board--gifts .tile::before {
  content: "🎀";
  position: absolute;
  z-index: 2;
  left: 50%;
  top: calc(var(--h) * -0.2);
  translate: -50% 0;
  font-size: calc(var(--h) * 0.36);
  line-height: 1;
  transition: opacity 0.3s, translate 0.4s;
  pointer-events: none;
}

.board--gifts .tile.is-open::before {
  opacity: 0;
  translate: -50% -60%;
}

.board--gifts .tile__back {
  background: var(--cream);
  color: #2b1c05;
  box-shadow: inset 0 0 0 calc(var(--h) * 0.045) var(--c);
}

/* editor: show every tile's content */

.board--editing .tile__inner {
  transition: none;
}

/* ---- the big reveal ---------------------------------------------------- */

dialog.reveal {
  --c: var(--red-dark);
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: hidden;
  cursor: pointer;
  opacity: 0;
  transition-property: opacity, display, overlay;
  transition-duration: 0.3s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

dialog.reveal[open] {
  display: grid;
  place-items: center;
  opacity: 1;

  @starting-style {
    opacity: 0;
  }
}

dialog.reveal::backdrop {
  background: rgb(3 5 25 / 0.86);
  backdrop-filter: blur(8px);
}

.reveal__card {
  position: relative;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2vmin;
  width: min(90vw, 170vh);
  min-height: 62vh;
  max-height: 90vh;
  padding: 5vmin 6vmin;
  border: 1vmin solid var(--gold);
  border-radius: 7vmin;
  background: radial-gradient(circle at 30% 15%, rgb(255 255 255 / 0.2), transparent 50%), var(--c);
  box-shadow: 0 0 12vmin rgb(247 184 75 / 0.45), 0 3vmin 8vmin rgb(0 0 0 / 0.6);
  text-align: center;
}

@media (prefers-reduced-motion: no-preference) {
  dialog.reveal[open] .reveal__card {
    animation: reveal-in 0.95s cubic-bezier(0.2, 1.25, 0.4, 1) both;
  }

  dialog.reveal[open] .reveal__emoji {
    animation: bounce 1.6s 0.9s ease-in-out infinite;
  }
}

@keyframes reveal-in {
  from {
    transform: scale(0.04) rotateY(540deg) rotate(-25deg);
    opacity: 0;
  }
}

@keyframes bounce {
  50% {
    transform: translateY(-1.5vmin) scale(1.08);
  }
}

.reveal__kicker {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 5vmin;
  color: var(--gold);
}

.reveal__emoji {
  font-size: 16vmin;
  line-height: 1;
}

.reveal__emoji:empty {
  display: none;
}

.reveal__label {
  font-family: var(--poster);
  font-weight: 400;
  font-size: var(--size, 14vw);
  line-height: 1;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
  text-shadow: 0 0.6vmin 0 rgb(0 0 0 / 0.35);
}

.reveal__desc {
  max-width: 60ch;
  margin: 0;
  font-size: 4vmin;
  line-height: 1.3;
}

.reveal__desc:empty {
  display: none;
}

.reveal__close {
  position: absolute;
  top: 2vmin;
  right: 2vmin;
}

.spark {
  position: absolute;
  left: 50%;
  top: 50%;
  font-size: var(--s);
  color: var(--col);
  pointer-events: none;
  opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
  dialog.reveal[open] .spark {
    animation: spark 1.6s var(--d) cubic-bezier(0.1, 0.7, 0.3, 1) both;
  }
}

@keyframes spark {
  0% {
    transform: translate(-50%, -50%) scale(0.2);
    opacity: 1;
  }

  100% {
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(1) rotate(180deg);
    opacity: 0;
  }
}

/* ---- editor ------------------------------------------------------------ */

.editor {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(16rem, 21rem) 1fr;
}

.editor__panel {
  overflow-y: auto;
  margin: 0 0 0.9rem 0.9rem;
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  background: var(--panel);
  backdrop-filter: blur(6px);
}

.editor__panel p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.editor__buttons {
  display: grid;
  gap: 0.5rem;
}

.status {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.status.is-error {
  color: #ff9aa8;
}

@media (max-width: 820px) {
  .shell--editor {
    height: auto;
    min-height: 100dvh;
  }

  .editor {
    grid-template-columns: 1fr;
  }

  .editor__panel {
    margin: 0 0.9rem 0.9rem;
  }

  .editor .stage {
    height: 80vh;
  }
}

/* ---- logo in the corner ------------------------------------------------ */

.logo {
  position: fixed;
  right: clamp(0.6rem, 1.5vmin, 1.5rem);
  bottom: clamp(0.6rem, 1.5vmin, 1.5rem);
  z-index: 2;
  width: clamp(2.5rem, 7vmin, 5rem);
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 2px 6px rgb(0 0 0 / 0.5));
}
