:root {
  --ink: #26221e;
  --soft: #7a7166;
  --line: #e2d9ca;
  --paper: #fffdf9;
  --bg: #f4efe6;
  --emerald: #145a5c;
  --emerald-hi: #2e8a87;
  --terracotta: #c4643f;
  --gold: #c9a24a;
  --head: Fraunces, Georgia, "Times New Roman", serif;
  --font: "DM Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
  font-family: var(--font);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#wrap { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); overflow: hidden; }
canvas { display: block; touch-action: none; }
.hidden { display: none !important; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 1.2em 0.8em 1.4em;
}

/* --- title ------------------------------------------------------------------ */
.title-top { text-align: center; margin-top: 2.2em; }
.logo { display: flex; flex-direction: column; align-items: center; }
.logo-big { font-family: var(--head); font-weight: 600; font-size: 2.6em; letter-spacing: -0.01em; line-height: 1; white-space: nowrap; }
.logo-sub { margin-top: 0.6em; font-size: 0.8em; font-weight: 500; color: var(--soft); letter-spacing: 0.02em; }
.best { margin-top: 0.7em; font-size: 0.72em; font-weight: 600; color: var(--emerald); }
.best:empty { display: none; }

.title-bottom { display: flex; flex-direction: column; align-items: center; gap: 0.55em; margin-bottom: 0.2em; }

.btn {
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.8em;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 0.6em 1.3em;
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn.big { font-size: 1.05em; background: var(--emerald); border-color: var(--emerald); color: #fff; padding: 0.65em 1.6em; }
.btn.ghost { background: rgba(255, 253, 249, 0.85); }

.icon-btn {
  position: absolute;
  top: 0.7em;
  width: 1.8em;
  height: 1.8em;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.95em;
  line-height: 1;
  cursor: pointer;
}
#btn-quit { left: 0.6em; }
.icon-btn.mute { right: 0.6em; }
.icon-btn.haptics { left: 2.7em; }
.icon-btn.off { opacity: 0.6; }
.skip-btn {
  position: absolute; left: 0.6em; top: 3.1em;
  font-family: var(--font); font-weight: 600; font-size: 0.55em; color: var(--soft);
  background: var(--paper); border: 2px solid var(--line);
  border-radius: 999px; padding: 0.35em 0.9em; cursor: pointer;
}

.update-note {
  position: absolute; left: 50%; bottom: 0.5em; transform: translateX(-50%);
  background: var(--paper); color: var(--ink); font-weight: 600; font-size: 0.55em;
  padding: 0.35em 0.9em; border-radius: 999px; border: 2px solid var(--line); white-space: nowrap;
  pointer-events: none;
}

.family-slot { margin-top: 0.8em; font-size: 0.9em; min-height: 1.6em; }
.family-line { margin: 0.2em 0 0.4em; font-weight: 600; color: var(--emerald); font-size: 0.72em; }
.next-line { margin: 0.2em 0 0.6em; font-weight: 500; font-size: 0.62em; color: var(--soft); }
.next-line:empty { display: none; }

/* --- modals ------------------------------------------------------------------ */
.modal { justify-content: center; background: rgba(244, 239, 230, 0.7); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.card {
  position: relative;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 0.8em;
  box-shadow: 0 0.4em 1.4em rgba(60, 45, 30, 0.12);
  padding: 0.9em 1em 1em;
  text-align: center;
  animation: fade 0.45s ease-out;
}
.card h2 { font-family: var(--head); font-weight: 600; margin: 0.1em 0 0.25em; font-size: 1.35em; line-height: 1.05; }
.how-list { list-style: none; padding: 0; margin: 0 0 0.8em; text-align: left; font-size: 0.66em; font-weight: 400; line-height: 1.35; }
.how-list li { display: flex; gap: 0.7em; align-items: center; padding: 0.5em 0; border-bottom: 1px solid var(--line); }
.how-list .ic { font-size: 1.5em; width: 1.4em; text-align: center; flex: none; }

#res-sub { margin: 0 0 0.5em; font-family: var(--head); font-size: 0.8em; font-style: italic; color: var(--soft); }
.catalogue { margin: 0.2em auto 0.5em; display: flex; gap: 0.6em; align-items: center; text-align: left; background: var(--bg); border-radius: 0.5em; padding: 0.4em; }
.catalogue img { width: 4.6em; height: 4.6em; border-radius: 0.3em; flex: none; }
.catalogue figcaption { display: flex; flex-direction: column; gap: 0.15em; }
.cat-no { font-size: 0.45em; text-transform: uppercase; letter-spacing: 0.12em; color: var(--soft); font-weight: 600; }
.cat-title { font-family: var(--head); font-size: 0.78em; line-height: 1.1; }
.cat-medium { font-size: 0.52em; color: var(--soft); line-height: 1.3; }
.stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.3em; margin: 0.4em 0; }
.stats div { border: 1px solid var(--line); border-radius: 0.4em; padding: 0.3em 0.2em; display: flex; flex-direction: column; }
.stats span { font-size: 0.45em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--soft); }
.stats b { font-family: var(--head); font-weight: 600; font-size: 0.9em; }
.total { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0.3em; margin: 0.4em 0; display: flex; flex-direction: column; }
.total span { font-size: 0.5em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.14em; color: var(--soft); }
.total b { font-family: var(--head); font-weight: 600; font-size: 1.9em; line-height: 1.1; color: var(--emerald); }
.results-card .best { margin: 0.2em 0 0.3em; }
.row { display: flex; gap: 0.5em; justify-content: center; align-items: center; flex-wrap: wrap; }

.install-how { font-size: 0.8em; font-weight: 400; margin: 0.4em 0 1em; line-height: 1.4; }
.share-ic { display: inline-block; border: 0.1em solid currentColor; border-radius: 0.25em; padding: 0 0.25em; font-size: 0.85em; }

/* --- Christmas gift ------------------------------------------------------------- */
.gift { justify-content: center; background: rgba(244, 239, 230, 0.8); }
.gift-inner { position: relative; width: 100%; display: flex; flex-direction: column; align-items: center; }
.gift-box { position: relative; width: 7em; height: 7em; border: 0; background: none; padding: 0; cursor: pointer; font-family: var(--font); animation: wiggle 2.2s ease-in-out infinite; }
.gift-base, .gift-lid { position: absolute; left: 50%; transform: translateX(-50%); }
.gift-base {
  bottom: 0; width: 5.6em; height: 4.4em; border-radius: 0.2em;
  background: linear-gradient(90deg, transparent 44%, var(--gold) 44% 56%, transparent 56%), var(--emerald);
}
.gift-lid {
  bottom: 4.2em; width: 6.2em; height: 1.3em; border-radius: 0.2em;
  background: linear-gradient(90deg, transparent 44%, var(--gold) 44% 56%, transparent 56%), #0f4a4c;
  transition: transform 0.8s cubic-bezier(.3, 1.4, .5, 1), opacity 0.6s 0.2s;
}
.gift-lid::before, .gift-lid::after { content: ""; position: absolute; bottom: 100%; width: 1.4em; height: 1.1em; border: 0.2em solid var(--gold); border-radius: 50% 50% 0 50%; }
.gift-lid::before { left: 1.6em; transform: rotate(-20deg); }
.gift-lid::after { right: 1.6em; transform: scaleX(-1) rotate(-20deg); }
.gift-tag { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 0.7em; white-space: nowrap; font-family: var(--head); font-style: italic; font-size: 0.8em; color: var(--ink); }
.gift-card { display: none; background: var(--paper); color: var(--ink); border: 2px solid var(--line); border-radius: 0.8em; box-shadow: 0 0.4em 1.4em rgba(60, 45, 30, 0.12); padding: 1em 1.1em 1.2em; text-align: center; width: 100%; }
.gift-card h2 { font-family: var(--head); font-weight: 600; margin: 0 0 0.4em; font-size: 1.4em; line-height: 1.1; }
.gift-card p { margin: 0.45em 0; font-size: 0.8em; font-weight: 400; line-height: 1.4; }
.gift-card .gift-signature { margin-top: 0.8em; font-family: var(--head); font-style: italic; font-size: 0.9em; color: var(--emerald); }
.gift-card .btn { margin-top: 0.8em; }
.gift.open .gift-box { animation: none; cursor: default; height: 4.6em; margin-bottom: 0.6em; transition: height 0.4s 0.4s; }
.gift.open .gift-lid { transform: translate(-50%, -4em) rotate(-18deg); opacity: 0; }
.gift.open .gift-tag { display: none; }
.gift.open .gift-card { display: block; animation: fade 0.6s 0.35s ease-out both; }

@keyframes wiggle { 0%, 75%, 100% { transform: rotate(0); } 80% { transform: rotate(-4deg); } 88% { transform: rotate(4deg); } 94% { transform: rotate(-2deg); } }
@keyframes fade { from { transform: translateY(0.6em); opacity: 0; } to { transform: none; opacity: 1; } }

/* --- portrait only ---------------------------------------------------------------- */
#rotate { display: none; position: fixed; inset: 0; background: var(--bg); color: var(--ink); font-family: var(--head); font-size: 1.5rem; text-align: center; align-items: center; justify-content: center; z-index: 10; }
@media (orientation: landscape) and (max-height: 520px) { #rotate { display: flex; } }
