@font-face {
  font-family: Caveat;
  src: url("fonts/Caveat-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: Caveat;
  src: url("fonts/Caveat-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: block;
}

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

html {
  --tray-h: 3.75rem;
  --tray-lift: 16px;
  --chart-pad: 4.75rem;
  --chrome-h: 10.5rem;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  width: 100%;
  background: #6A3A18;
  color: #3B3733;
  font-family: Avenir, "Century Gothic", "Trebuchet MS", sans-serif;
}

.table {
  position: relative;
  width: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: var(--chart-pad, 0px);
  padding-bottom: calc(var(--tray-h, 0px) + var(--tray-lift, 16px));
  overscroll-behavior: none;
  background-color: #6A3A18;
  background-image: var(--table-plate, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  isolation: isolate;
}

.table::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 55% at 16% 6%, rgba(255, 244, 214, 0.28), transparent 58%),
    radial-gradient(ellipse 95% 90% at 50% 48%, transparent 55%, rgba(40, 18, 6, 0.22) 100%);
  z-index: 0;
  transition: opacity 6s linear;
}

html.table-plate .table::after {
  display: none;
}

html.evening .table::after {
  opacity: 0;
}

.reduce-motion .table::after {
  transition: opacity 1s linear;
}

.week-chart {
  position: absolute;
  z-index: 1;
  width: min(17.5rem, 78vw);
  height: auto;
  background: #F8F4EB;
  box-shadow: 1px 1px 0 rgba(90, 70, 40, 0.28);
  padding: 0.2rem 0.3rem 0.35rem;
  pointer-events: none;
}

.week-chart text {
  font-family: Avenir, "Century Gothic", "Trebuchet MS", sans-serif;
  font-size: 11px;
  fill: #3B3733;
  text-anchor: middle;
  pointer-events: none;
}

.week-chart .chart-box {
  fill: none;
  stroke: #3B3733;
  stroke-width: 1.4;
  pointer-events: all; /* SVG: hit the whole box even with fill:none, so tapping the slot works */
  cursor: pointer;
}

.week-chart .chart-star {
  opacity: 0;
}

.week-chart .chart-star.on {
  opacity: 1;
}

.evening-veil {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background:
    linear-gradient(rgba(18, 16, 28, 0.34), rgba(18, 16, 28, 0.34)),
    radial-gradient(ellipse 80% 55% at 16% 6%, rgba(40, 55, 78, 0.22), transparent 62%);
  transition: opacity 6s linear;
}

html.evening .evening-veil {
  opacity: 1;
}

.reduce-motion .evening-veil {
  transition: opacity 1s linear;
}

#defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.sticker-pile,
.star-tray {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  touch-action: none;
}

.sticker-pile.star-tray.on,
.star-tray.on {
  pointer-events: auto;
}

.sticker-sheet {
  position: relative;
  left: 0;
  top: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--tray-gap, 6px);
  padding: 6px 10px;
  width: 100%;
  max-width: min(100%, var(--sticker-max, calc(100vw - 16px)));
  background: #FBF8F2;
  box-shadow: 1px 1px 0 rgba(90, 70, 40, 0.28);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  touch-action: none;
}

.sticker-sheet.in {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  animation: none;
}

.reduce-motion .sticker-sheet.in {
  animation: none;
  opacity: 1;
}

@keyframes sticker-slide-in {
  from {
    opacity: 0;
    transform: translateX(45vw);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.sticker-slot {
  position: relative;
  width: var(--star-slot, 48px);
  height: var(--star-slot, 48px);
  min-width: var(--star-slot, 48px);
  min-height: var(--star-slot, 48px);
  display: grid;
  place-items: center;
  touch-action: none;
}

.sticker-slot.taken {
  display: none;
}

.sticker-slot.is-day .die-cut path {
  stroke: rgba(217, 169, 43, 0.55);
}

.die-cut {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.sticker {
  position: relative;
  z-index: 1;
  width: var(--star-slot, 48px);
  height: var(--star-slot, 48px);
  min-width: var(--star-slot, 48px);
  min-height: var(--star-slot, 48px);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}

.sticker.taken {
  visibility: hidden;
  pointer-events: none;
}

.sticker.lift .star {
  transform: rotate(-8deg) translateY(-5px);
  filter: drop-shadow(1px 4px 2px rgba(40, 20, 8, 0.28));
}

.sticker.flying {
  z-index: 20;
  pointer-events: none;
  filter: drop-shadow(1px 5px 3px rgba(40, 20, 8, 0.3));
}

.sheet {
  position: relative;
  z-index: 2;
  width: 96vw;
  max-width: min(96vw, calc((100dvh - var(--chrome-h, 10rem)) * 8.5 / 11));
  aspect-ratio: 8.5 / 11;
  max-height: calc(100dvh - var(--chrome-h, 10rem));
  background: #F8F4EB;
  box-shadow: 1px 1px 0 rgba(90, 70, 40, 0.28);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  flex-direction: column;
  padding: 8px 0 12px;
  overflow: hidden;
  transform: translate(0, 0);
  container-type: size;
}

@media (min-width: 480px) {
  .sheet {
    width: 92vw;
    max-width: min(92vw, calc((100dvh - var(--chrome-h, 10rem)) * 8.5 / 11));
  }
}

.sheet.is-gesturing {
  will-change: transform;
}

.head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.6rem;
  flex: 0 0 auto;
  width: 88%;
  margin-left: auto;
  margin-right: auto;
}

.be {
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: clamp(1.15rem, 4.6vw, 1.85rem);
  line-height: 1.1;
}

.trace {
  margin-top: 0.22rem;
  font-size: clamp(0.72rem, 2.5vw, 0.98rem);
}

.day-wrap {
  text-align: right;
  min-width: 4.5rem;
}

.day {
  font-size: clamp(0.78rem, 2.6vw, 1.05rem);
}

.ticks {
  display: flex;
  justify-content: flex-end;
  gap: 0.18rem;
  min-height: 0.7rem;
  margin-top: 0.12rem;
}

.tick {
  width: 0.55rem;
  height: 0.85rem;
  border-right: 2px solid #B3261E;
  transform: rotate(18deg);
}

.name-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin: 0.45rem auto 0.4rem;
  width: 88%;
}

.name-label {
  font-size: clamp(0.72rem, 2.4vw, 0.95rem);
  padding-bottom: 0.12rem;
}

.name-line {
  position: relative;
  flex: 1;
  height: 1.55rem;
  border-bottom: 1px solid #3B3733;
}

.name-line canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.row {
  display: grid;
  gap: 0.08rem 0.18%;
  margin-top: 0.12rem;
}

.row-helpful {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  width: 88%;
  margin-left: auto;
  margin-right: auto;
}

.cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.glyph-slot {
  position: relative;
  width: 100%;
}

.glyph {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1.4;
  overflow: visible;
  display: block;
}

.glyph path {
  fill: none;
  stroke: #3B3733;
  stroke-width: 8.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 6.4 22;
}

.cell.done .glyph path {
  opacity: 0;
}

.cell.gated .glyph path {
  opacity: 0.4;
}

.cell.done.gated .glyph path {
  opacity: 0;
}

.smile-guide {
  fill: none;
  stroke: #3B3733;
  stroke-width: 3px;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 3 9;
  vector-effect: non-scaling-stroke;
  opacity: 0;
  pointer-events: none;
}

.smile-guide.on {
  opacity: 1;
}

.face-print .face-ring {
  vector-effect: non-scaling-stroke;
  stroke-width: var(--face-ring, 2px);
}

.face.gate .face-print .face-ring {
  stroke-dasharray: 314;
  stroke-dashoffset: 314;
  animation: ink-circle 600ms linear forwards;
}

.reduce-motion .face.gate .face-print .face-ring {
  animation: none;
  stroke-dashoffset: 0;
  stroke-width: 2.8px;
}

@keyframes ink-circle {
  to { stroke-dashoffset: 0; stroke-width: 2.8px; }
}

#preview-canvas {
  transition: opacity 300ms linear;
}

#preview-canvas.fade {
  opacity: 0;
}

.reduce-motion #preview-canvas {
  transition: none;
}

.star-box {
  width: 100%;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  margin-top: 0.08rem;
  border: 1.4px solid rgba(59, 55, 51, 0.55);
  background: rgba(248, 244, 235, 0.4);
  position: relative;
  display: grid;
  place-items: center;
}

.star-box::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(100%, 48px);
  height: max(100%, 48px);
  transform: translate(-50%, -50%);
}

.box-ink {
  position: absolute;
  inset: -2px;
  width: calc(100% + 4px);
  height: calc(100% + 4px);
  overflow: visible;
  pointer-events: none;
  opacity: 0;
}

.box-ink.go {
  opacity: 1;
}

.box-ink-rect {
  fill: none;
  stroke: #3B3733;
  stroke-width: 1.8;
  stroke-linecap: square;
  stroke-dasharray: 196;
  stroke-dashoffset: 196;
}

.box-ink.go .box-ink-rect {
  animation: ink-box 400ms linear forwards;
}

.reduce-motion .box-ink.go .box-ink-rect {
  animation: none;
  stroke-dashoffset: 0;
}

@keyframes ink-box {
  to { stroke-dashoffset: 0; }
}

.star-box:focus-visible,
.letter-hit:focus-visible,
.face:focus-visible,
.sound-toggle:focus-visible {
  outline: 2px solid #3B3733;
  outline-offset: 2px;
}

.letter-hit {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.writing-line {
  width: 88%;
  height: 1.05rem;
  margin: 0.2rem auto 0;
  border-bottom: 1px solid #3B3733;
  flex: 0 0 auto;
  pointer-events: none;
}

.help-covers {
  position: absolute;
  inset: 0;
  z-index: 6;
  overflow: hidden;
  pointer-events: none;
}

.help-cover {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  overflow: visible;
}

.help-cover .star {
  position: absolute;
  overflow: visible;
  flex: none;
  margin: 0;
  transform-origin: 50% 50%;
}

.cell.help-covered .glyph,
.cell.help-covered .star-box {
  visibility: hidden;
}

.star {
  width: 72%;
  height: 72%;
  overflow: visible;
}

.thumb {
  position: absolute;
  width: 18px;
  height: 22px;
  border-radius: 50%;
  background: rgba(90, 70, 40, 0.16);
  right: -14px;
  top: 8px;
  pointer-events: none;
  animation: dry-thumb 10s linear forwards;
}

@keyframes dry-thumb {
  0% { opacity: 1; filter: blur(0.4px); }
  100% { opacity: 0; filter: blur(5px); }
}

.star.peel {
  animation: peel 0.85s ease-in forwards;
}

@keyframes peel {
  0% { transform: rotate(var(--tilt, 0deg)) translateY(0); opacity: 1; }
  100% { transform: rotate(calc(var(--tilt, 0deg) + 18deg)) translateY(140px); opacity: 0; }
}

.house-line {
  font-family: Caveat, cursive;
  font-weight: 700;
  font-style: normal;
  font-size: clamp(1.05rem, 3.4vw, 1.45rem);
  margin: 0;
  color: #3B3733;
  clip-path: inset(0 100% 0 0);
  opacity: 0;
  pointer-events: none;
  transition: clip-path 400ms linear, opacity 80ms linear;
}

.house-line.show {
  clip-path: inset(0 0 0 0);
  opacity: 1;
}

.house-line.stay {
  position: relative;
}

.under-row {
  position: relative;
  text-align: center;
  min-height: var(--rule-clear, 1.4em);
  margin: 0.15rem auto 0;
  width: 88%;
  flex: 0 0 auto;
}

#slide-line,
#where-line {
  text-align: center;
  margin: 0;
}

#where-line:not(.show),
#slide-line:not(.show) {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  clip-path: none;
}

#smile-line {
  position: absolute;
  left: 50%;
  top: 0;
  margin: 0;
  text-align: center;
  min-height: 0;
  white-space: nowrap;
  z-index: 5;
  line-height: 1;
  transform: translate(-50%, -100%);
  pointer-events: none;
}

#smile-line:not(.show) {
  width: 0;
  height: 0;
  overflow: hidden;
  font-size: 0;
  line-height: 0;
  margin: 0;
}

#smile-line.gate {
  font-size: calc(var(--smile-scale, 1.5) * clamp(1.05rem, 3.4vw, 1.45rem));
}

#smile-line.dark {
  color: #1A1816;
}

#not-line {
  position: absolute;
  left: 8%;
  max-width: 70%;
  z-index: 6;
}

.feel {
  position: absolute;
  inset: 0;
  margin: 0;
  width: auto;
  max-width: none;
  pointer-events: none;
  overflow: visible;
}

.face {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--face-d, 40%);
  height: var(--face-d, 40%);
  pointer-events: auto;
}

.face-print,
.face canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.face canvas {
  pointer-events: none;
}

.caption {
  position: absolute;
  left: 0;
  width: 100%;
  margin: 0;
  font-size: clamp(0.72rem, 2.5vw, 0.98rem);
  text-align: center;
  line-height: 1.2;
  pointer-events: none;
}

.kid-line {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 12px;
  min-height: var(--kid-band, 7%);
  margin: 0;
  font-family: Caveat, cursive;
  font-weight: 500;
  font-size: clamp(0.95rem, 3vw, 1.2rem);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0;
  pointer-events: none;
  z-index: 6;
}

.kid-line span {
  display: inline-block;
}

.sheet-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

.eraser {
  position: absolute;
  width: 38px;
  height: 22px;
  background: #E8A3A0;
  border-radius: 2px;
  z-index: 7;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 1px 0 rgba(90, 70, 40, 0.18);
}

.eraser.go {
  opacity: 1;
}

.smudge {
  position: absolute;
  background: rgba(140, 110, 108, 0.18);
  border-radius: 40% 55% 45% 50%;
  filter: blur(2px);
  z-index: 4;
  opacity: 0;
  pointer-events: none;
}

.smudge.show {
  opacity: 1;
}

.sound-toggle {
  position: fixed;
  left: calc(12px + env(safe-area-inset-left));
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 30;
  min-height: 48px;
  min-width: 48px;
  padding: 0.45rem 0.7rem;
  border: 0;
  background: transparent;
  color: #F1E8D8;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.title-card {
  position: absolute;
  z-index: 8;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 1.1s ease;
  font-size: 20px;
  letter-spacing: 0.08em;
  line-height: 1.25;
  color: #F1E8D8;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

.title-card.on {
  opacity: 1;
  visibility: visible;
}

.title-card div:last-child {
  letter-spacing: 0.02em;
  font-size: 13px;
}

.live {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.reduce-motion .house-line {
  transition: none;
}

.reduce-motion .house-line.show {
  clip-path: none;
}

.reduce-motion .star.peel {
  animation: fade-out 0.45s ease forwards;
}

.reduce-motion .thumb {
  animation: fade-out 10s linear forwards;
}

.reduce-motion .title-card {
  transition: opacity 1s ease;
}

.reduce-motion .sheet.is-gesturing {
  will-change: opacity;
}

.reduce-motion .eraser.go {
  transition: opacity 220ms linear;
}

@media (max-height: 500px) {
  .caption {
    font-size: clamp(0.62rem, 2vw, 0.8rem);
  }

  .be {
    font-size: clamp(0.9rem, 3.2vw, 1.15rem);
  }

  .trace,
  .day,
  .name-label {
    font-size: clamp(0.62rem, 2vw, 0.8rem);
  }

  .head {
    gap: 0.25rem;
  }

  .under-row {
    min-height: var(--rule-clear, 0.9em);
    margin-top: 0;
  }

  .house-line {
    font-size: clamp(0.8rem, 2.6vw, 1.05rem);
  }

  #smile-line.gate {
    font-size: calc(var(--smile-scale, 1.5) * clamp(0.8rem, 2.6vw, 1.05rem));
  }

  .name-row {
    margin: 0.12rem auto 0.1rem;
  }

  .name-line {
    height: 1.15rem;
  }

  .row {
    margin-top: 0;
    gap: 0.04rem 0.12%;
  }

  .writing-line {
    height: 0.72rem;
    margin-top: 0.06rem;
  }
}

@keyframes fade-out {
  to { opacity: 0; }
}
