/* Wichtel – a cozy Christmas evening, mobile first (plan.md, section 7). */

/* Fraunces (SIL OFL 1.1, see /fonts/Fraunces-OFL.txt), self-hosted: no font CDN. */
@font-face {
  font-family: 'Fraunces';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/fraunces-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Fraunces';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/fraunces-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --paper: #f7f1e3;
  --paper-2: #efe6d0;
  --card: #fffaf0;
  --green: #1f4d3a;
  --green-2: #2c6a50;
  --red: #b3262e;
  --red-2: #8f1d24;
  --gold: #c9a24a;
  --gold-2: #a8842f;
  --ink: #2b2118;
  --ink-soft: #5d5044;
  --cream: #f7f1e3;
  --cream-seg: #f3e7c9;
  --seg-ink: #2b2118;
  --name-red: #b3262e;
  --line: rgba(43, 33, 24, 0.12);
  --shadow: 0 1px 2px rgba(43, 33, 24, 0.08), 0 6px 18px rgba(43, 33, 24, 0.1);
  --radius: 14px;
  --font-head: 'Fraunces', Georgia, 'Times New Roman', serif;
  --input-bg: #fff;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper) url(/img/paper.svg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.55;
  overflow-x: hidden;
}

h1,
h2 {
  font-family: var(--font-head);
  color: var(--green);
  line-height: 1.2;
  font-weight: 600;
}

h1 {
  font-size: clamp(1.9rem, 7vw, 2.6rem);
  margin: 0.4em 0 0.2em;
}

h2 {
  font-size: 1.35rem;
  margin: 0 0 0.6em;
}

a {
  color: var(--green);
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- layout ---------- */

.site-header {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--green);
  color: var(--cream);
  border-bottom: 3px solid var(--gold);
}

.brand {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 1.1rem;
  color: inherit;
  text-decoration: none;
}

.countdown {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.9;
}

.page {
  position: relative;
  z-index: 1;
  max-width: 44rem;
  margin: 0 auto;
  padding: 0.5rem 1.25rem 4rem;
}

.page.narrow {
  max-width: 26rem;
}

.lead {
  color: var(--ink-soft);
  margin-top: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin: 1.25rem 0;
}

.center {
  text-align: center;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.hint {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 0.4rem 0;
}

.error {
  color: var(--red);
  font-weight: 600;
  margin: 0.75rem 0;
}

.status {
  color: var(--green);
  min-height: 1.5em;
  margin: 0.25rem 0 0;
}

.back {
  text-align: center;
}

/* ---------- buttons & forms ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: 2.9rem;
  padding: 0.6rem 1.3rem;
  border: 2px solid transparent;
  border-radius: 999px;
  font: 600 1rem/1.2 var(--font-body);
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

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

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

.btn.primary {
  background: var(--green);
  color: var(--cream);
  border-color: var(--gold);
}

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

.btn.ghost {
  background: transparent;
  color: var(--green);
  border-color: var(--line);
}

.btn.small {
  min-height: 2.3rem;
  padding: 0.3rem 0.9rem;
  font-size: 0.9rem;
}

.btn.big {
  font-size: 1.2rem;
  min-height: 3.4rem;
  padding: 0.8rem 2rem;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

label {
  display: block;
  font-weight: 600;
  margin: 0.75rem 0 0.3rem;
}

input,
textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--input-bg);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}

input:focus,
textarea:focus {
  border-color: var(--gold);
  outline: none;
  box-shadow: 0 0 0 3px rgba(201, 162, 74, 0.3);
}

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

.pin-input {
  font-size: 1.6rem;
  letter-spacing: 0.5em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.form .btn {
  width: 100%;
  margin-top: 1rem;
}

/* ---------- start page: gift tags ---------- */

.tags {
  list-style: none;
  margin: 1.5rem 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 1.4rem 1rem;
}

.tag {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 5.5rem;
  padding: 1rem 1rem 1rem 2.4rem;
  background: var(--card);
  border: 2px solid var(--gold);
  /* a gift tag: one end cut off at the corners */
  clip-path: polygon(1.4rem 0, 100% 0, 100% 100%, 1.4rem 100%, 0 70%, 0 30%);
  border-radius: 0 10px 10px 0;
  color: var(--green);
  text-decoration: none;
  transition: transform 0.2s ease;
}

.tags li {
  /* clip-path cuts off box-shadow, so the shadow goes on the parent */
  filter: drop-shadow(0 4px 8px rgba(43, 33, 24, 0.15));
}

.tag-hole {
  position: absolute;
  left: 1.1rem;
  top: 50%;
  width: 0.75rem;
  height: 0.75rem;
  margin-top: -0.375rem;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--gold);
}

.tag-name {
  font-family: var(--font-head);
  font-size: 1.35rem;
  font-weight: 600;
}

.tag-done {
  position: absolute;
  top: 0.35rem;
  right: 0.5rem;
  font-size: 0.85rem;
  color: var(--green-2);
  font-weight: 700;
}

.tilt-0 { transform: rotate(-2deg); }
.tilt-1 { transform: rotate(1.5deg); }
.tilt-2 { transform: rotate(-1deg); }
.tilt-3 { transform: rotate(2deg); }

.tag:hover,
.tag:focus-visible {
  transform: rotate(0) translateY(-3px);
}

/* ---------- draw page: the wheel ---------- */

.draw-page {
  text-align: center;
}

.wheel-wrap {
  position: relative;
  width: min(88vw, 22rem);
  margin: 1.5rem auto 1.75rem;
  aspect-ratio: 1;
}

.wheel {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 8px 18px rgba(43, 33, 24, 0.25));
}

.rotor {
  transform-box: fill-box;
  transform-origin: center;
}

.wheel-rim {
  fill: var(--gold);
}

.wheel-edge {
  stroke: var(--gold-2);
  stroke-width: 1.5;
}

.wheel-hub {
  fill: var(--gold);
  stroke: var(--gold-2);
  stroke-width: 2;
}

.wheel-name {
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 600;
}

.pointer {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: -1.1rem;
  width: 3rem;
  height: 3rem;
  margin-left: -1.5rem;
  fill: var(--gold);
  stroke: var(--gold-2);
  stroke-width: 1.5;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
}

.result {
  animation: fade-in 0.6s ease both;
}

.result-pre {
  font-size: 1.2rem;
  margin: 0;
}

.result-name {
  font-family: var(--font-head);
  font-size: clamp(2.6rem, 12vw, 4rem);
  font-weight: 700;
  color: var(--name-red);
  margin: 0;
  line-height: 1.1;
}

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

/* ---------- overview page ---------- */

.present {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  width: 100%;
  min-height: 11rem;
  margin: 2rem 0 1.25rem;
  padding: 2rem 1.25rem 1.5rem;
  border: 0;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.12) 0 3px, transparent 4px) 0 0 / 34px 34px,
    var(--red);
  color: var(--cream);
  font: inherit;
  cursor: pointer;
  box-shadow: var(--shadow);
  overflow: visible;
  transition: background-color 0.5s ease, color 0.5s ease;
  -webkit-tap-highlight-color: transparent;
}

/* the ribbon: a vertical and a horizontal gold band */
.present-ribbon,
.present-ribbon::after {
  position: absolute;
  background: linear-gradient(90deg, var(--gold-2), var(--gold) 30%, #e2c67d 50%, var(--gold) 70%, var(--gold-2));
  transition: transform 0.6s cubic-bezier(0.6, -0.2, 0.7, 0.4), opacity 0.6s ease;
}

.present-ribbon {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1.6rem;
  margin-left: -0.8rem;
}

.present-ribbon::after {
  content: '';
  top: 50%;
  left: calc(-50vw);
  width: 100vw;
  max-width: none;
  height: 1.6rem;
  margin-top: -0.8rem;
  background: linear-gradient(180deg, var(--gold-2), var(--gold) 30%, #e2c67d 50%, var(--gold) 70%, var(--gold-2));
}

.present {
  clip-path: inset(-3rem 0 0 0 round var(--radius));
}

/* the bow on top */
.present-bow {
  position: absolute;
  top: -1.7rem;
  left: 50%;
  width: 4.4rem;
  height: 2.4rem;
  margin-left: -2.2rem;
  transition: transform 0.6s ease, opacity 0.5s ease;
}

.present-bow::before,
.present-bow::after {
  content: '';
  position: absolute;
  bottom: 0;
  width: 2.1rem;
  height: 2.1rem;
  border: 0.55rem solid var(--gold);
  border-radius: 50% 50% 0 50%;
  transform: rotate(45deg);
}

.present-bow::before {
  left: 0.1rem;
  transform: rotate(-30deg) skew(5deg);
  border-radius: 50% 0 50% 50%;
}

.present-bow::after {
  right: 0.1rem;
  transform: rotate(30deg) skew(-5deg);
  border-radius: 0 50% 50% 50%;
}

.present-label,
.present-hint,
.present-name {
  position: relative;
  z-index: 1;
  padding: 0.1rem 0.7rem;
  border-radius: 8px;
}

.present-label {
  font-family: var(--font-head);
  font-size: 1.3rem;
  background: var(--red);
}

.present-hint {
  font-size: 0.9rem;
  background: var(--red);
}

.present-name {
  font-family: var(--font-head);
  font-size: clamp(2.4rem, 11vw, 3.4rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--name-red);
}

.present-name:empty {
  display: none;
}

/* unwrapped */
.present.open {
  background-color: var(--card);
  background-image: none;
  color: var(--ink);
  outline: 2px dashed var(--gold);
  outline-offset: -8px;
}

.present.open .present-label,
.present.open .present-hint {
  background: transparent;
  color: var(--ink-soft);
}

.present.open .present-ribbon {
  transform: translateY(-120%);
  opacity: 0;
}

.present.open .present-bow {
  transform: translateY(-2rem) rotate(25deg) scale(0.6);
  opacity: 0;
}

.present.open .present-name {
  animation: pop 0.5s 0.15s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.others details {
  padding: 0;
}

.others summary {
  cursor: pointer;
  padding: 1rem 1.25rem;
  font-family: var(--font-head);
  font-weight: 600;
  color: var(--green);
  font-size: 1.1rem;
}

.details-body {
  padding: 0 1.25rem 1.25rem;
}

.others .card {
  margin: 0.75rem 0;
}

.wish-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty {
  color: var(--ink-soft);
  font-style: italic;
}

.my-preview:not(:empty) {
  border-top: 1px dashed var(--line);
  margin-top: 1rem;
  padding-top: 1rem;
}

.my-preview .wish-text {
  display: none; /* the text is in the textarea already; show only the cards */
}

/* ---------- link preview cards ---------- */

.cards {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.link-card {
  display: flex;
  gap: 0.85rem;
  align-items: stretch;
  min-height: 5.5rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}

.link-card:hover {
  box-shadow: var(--shadow);
}

.link-card img,
.link-icon {
  flex: 0 0 5.5rem;
  width: 5.5rem;
  object-fit: cover;
  background: var(--paper-2);
}

.link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
}

.link-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: 0.6rem 0.85rem 0.6rem 0;
}

.link-title {
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.link-desc {
  font-size: 0.88rem;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.link-domain {
  font-size: 0.8rem;
  color: var(--green-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- snow (flakes are made in common.js, the motion is CSS) ---------- */

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

.flake {
  position: absolute;
  top: -2vh;
  left: var(--left);
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: #fff;
  opacity: var(--opacity);
  box-shadow: 0 0 2px rgba(43, 33, 24, 0.25);
  animation: snowfall var(--fall) linear var(--delay) infinite;
  will-change: transform;
}

@keyframes snowfall {
  from { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(var(--drift), 52vh, 0); }
  to { transform: translate3d(0, 104vh, 0); }
}

/* ---------- confetti after the draw ---------- */

.confetti {
  position: fixed;
  left: 50%;
  top: 38%;
  width: 0;
  height: 0;
  z-index: 5;
  pointer-events: none;
}

.piece {
  position: absolute;
  width: 0.55rem;
  height: 0.85rem;
  background: var(--gold);
  border-radius: 2px;
  opacity: 0;
  animation: burst var(--d) cubic-bezier(0.2, 0.7, 0.4, 1) var(--delay) forwards;
}

.piece:nth-child(4n + 1) {
  background: #e2c67d;
}

.piece.flake-piece {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 3px rgba(43, 33, 24, 0.3);
}

@keyframes burst {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  30% { transform: translate(calc(var(--x) * 0.6), -18vh) rotate(calc(var(--r) * 0.4)); opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; }
}

/* ---------- dark mode: winter night ---------- */

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #14213d;
    --paper-2: #1c2c4f;
    --card: #1b2a4a;
    --ink: #f7f1e3;
    --ink-soft: #c9c1ad;
    --line: rgba(247, 241, 227, 0.16);
    --input-bg: #111c34;
    --cream-seg: #f3e7c9;
    --name-red: #ff7a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 22px rgba(0, 0, 0, 0.35);
  }

  body {
    background-image: radial-gradient(ellipse at top, #1f3260 0%, transparent 60%);
  }

  h1,
  h2,
  a,
  .tag,
  .others summary,
  .btn.ghost {
    color: #e9cf8a;
  }

  .site-header {
    background: #0e1830;
  }

  .tag-done,
  .status,
  .link-domain {
    color: #9fd3b6;
  }

  .error {
    color: #ff8a8f;
  }

  .link-card {
    color: var(--ink);
  }

  .flake {
    box-shadow: none;
  }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .snow,
  .confetti {
    display: none;
  }

  .present-ribbon,
  .present-ribbon::after,
  .present-bow,
  .present.open .present-name {
    transition: none;
    animation: none;
  }

  .btn,
  .tag,
  .link-card {
    transition: none;
  }

  /* no spin (see draw.js), only a fade-in of the result */
  .result {
    animation: fade-only 0.8s ease both;
  }
}

@keyframes fade-only {
  from { opacity: 0; }
  to { opacity: 1; }
}
