/* Build a Sukkah.
 *
 * Two rules hold this layout together and both are about the art:
 *  - the backdrop covers, the sukkah is contained, and the wall is never
 *    cropped. The wall is where every decoration lives.
 *  - the tray sits along the bottom on a phone and moves to a side rail on a
 *    wide screen, so the sukkah keeps its height instead of being squeezed.
 */

:root {
  --ink: #26234A;
  --cream: #FFF6E5;
  --coral: #FF6A5B;
  --sun: #FFD23F;
  --mint: #8CE2A8;
  --grey: #6B6890;
  --pick: #FF8A3D;
  --rail: 300px;
  --topbar: 62px;
}

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

/* Anything marked hidden is hidden, full stop.
 *
 * The browser's own rule for the hidden attribute is weaker than any class
 * that sets display, so .bottom, .rnd and .selbar each quietly overrode it and
 * each had to be patched after somebody saw the wrong button on screen. One
 * rule, once, instead. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  /* Dragging a lantern about was starting a text selection, which turned the
   * whole screen blue and left the browser in a drag state that swallowed the
   * next few taps. Nothing here is text you would want to select, except the
   * two things you type into. */
  user-select: none;
  -webkit-user-select: none;
  font-family: 'Fredoka', 'Heebo', 'Nunito', 'Trebuchet MS', system-ui, sans-serif;
  color: var(--ink);
  background: var(--cream);
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  flex: none;
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: #fff;
  border-bottom: 4px solid var(--ink);
  z-index: 20;
}

.rnd {
  width: 44px; height: 44px;
  flex: none;
  border-radius: 50%;
  background: var(--cream);
  border: 4px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  display: flex; align-items: center; justify-content: center;
  font: inherit; font-size: 20px; line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: transform .08s;
}
.rnd:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.rnd.mint { background: var(--mint); }
.rnd.playing { background: var(--mint); }
.rnd.off .emoji { opacity: .4; }
.rnd.coral { background: var(--coral); }

.title { flex: 1; text-align: center; font-weight: 600; font-size: 21px; line-height: 1.05; min-width: 0; }
input, textarea {
  user-select: text;
  -webkit-user-select: text;
}

#sukkah-name {
  font: inherit;
  font-weight: 600;
  color: inherit;
  text-align: center;
  width: 100%;
  border: none;
  border-bottom: 3px dashed transparent;
  background: none;
  padding: 0 0 1px;
  outline: none;
}
#sukkah-name:hover { border-bottom-color: rgba(38, 35, 74, .25); }
#sukkah-name:focus { border-bottom-color: var(--pick); }
#sukkah-name[readonly] { border-bottom-color: transparent; cursor: default; }
.title small { display: block; font-weight: 500; font-size: 13px; color: var(--grey); }

/* ----------------------------------------------------------------- stage */
/* Stacked by default: the stage on top, the tray under it. `display:flex`
 * alone would lay these out side by side on a phone, which puts the sukkah in
 * a column two fingers wide. */
.split { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }

.stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;
  background: #7FB6DE;
  touch-action: none;
}

.backdrop {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* An image the browser is allowed to drag is an image that starts a native
 * drag instead of a decoration being moved. */
img { -webkit-user-drag: none; user-select: none; }

/* Positioned by JS: the sukkah's box, with the wall a fixed fraction inside. */
.sukkah-layer { position: absolute; }
.sukkah { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.wall { position: absolute; }

.piece {
  position: absolute;
  display: block;
  transform: translate(-50%, -50%);   /* replaced inline when it leans */
  transform-origin: center;
  filter: drop-shadow(0 2px 2px rgba(38, 35, 74, .3));
  /* The stage decides what was pressed, by shape rather than by rectangle, so
   * a sticker must not intercept anything itself. */
  pointer-events: none;
  transform-origin: center;
  touch-action: none;
  user-select: none; -webkit-user-drag: none;
}
.piece.picked { filter: drop-shadow(0 0 0 var(--pick)) drop-shadow(0 3px 3px rgba(38,35,74,.35)); }
.piece.picked::after { content: ''; }

.halo {
  position: absolute;
  border: 4px dashed var(--pick);
  border-radius: 14px;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.hint {
  position: absolute;
  left: 50%; bottom: 12px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, .92);
  border: 4px solid var(--ink);
  border-radius: 999px;
  padding: 7px 16px;
  font-weight: 600; font-size: 15px;
  box-shadow: 0 5px 0 var(--ink);
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100% - 24px);
  overflow: hidden; text-overflow: ellipsis;
  transition: opacity .3s;
}
.hint.gone { opacity: 0; }

/* ------------------------------------------------------------------ tray */
.tray {
  flex: 0 0 210px;
  background: #fff;
  border-top: 4px solid var(--ink);
  padding: 9px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 0;
}

/* Ten families now. Wrapped, they took four rows of a phone tray and left one
 * row of stickers under them, so on a narrow screen they scroll sideways in a
 * single row instead - which is what a phone does with a row of tabs anyway. */
.tabs { display: flex; gap: 6px; flex: none; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  min-width: 74px;
  height: 34px;
  border-radius: 999px;
  border: 4px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  background: #fff;
  font: inherit; font-weight: 600; font-size: 13px;
  cursor: pointer;
  padding: 0 4px;
  min-width: 0;          /* a flex item will not shrink below its text without this */
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.tab.on { background: var(--sun); }
.tab:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }

.shelf {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  /* Without this the rows stretch to fill the shelf, which leaves small chips
   * marooned in tall empty bands. Rows should be as tall as a chip and no
   * taller, and the leftover space belongs at the bottom. */
  align-content: start;
  gap: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px 2px 4px;
}

.chip {
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--cream);
  border: 4px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 5px;
  transition: transform .08s;
}
.chip img { max-width: 100%; max-height: 100%; display: block; pointer-events: none; }
.chip.on { box-shadow: 0 4px 0 var(--ink), 0 0 0 5px var(--pick); background: #fff; }
.chip:active { transform: translateY(2px); }

/* ---------------------------------------------------------------- bottom */
.bottom {
  flex: none;
  display: flex;
  gap: 10px;
  padding: 9px 12px calc(12px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 4px solid var(--ink);
}

.btn {
  flex: 1;
  height: 54px;
  border-radius: 18px;
  border: 4px solid var(--ink);
  box-shadow: 0 6px 0 var(--ink);
  background: var(--cream);
  font: inherit; font-weight: 600; font-size: 17px;
  cursor: pointer;
  min-width: 0;
  white-space: nowrap;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.mint { background: var(--mint); }
.btn.sun { background: var(--sun); }
.btn.coral { background: var(--coral); color: #fff; }
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--ink); }

/* `.bottom` sets display:flex, which beats the browser's own rule for the
 * hidden attribute, so the guest's bar showed up in the editor. */
.bottom[hidden] { display: none; }

/* The controls for the sticker you are holding. Docked to the bottom of the
 * stage, always in the same place: a bar that appears wherever you last pressed
 * is a bar a child has to hunt for, and it can land under the tray where it
 * cannot be pressed at all. */
/* The controls for the chosen decoration.
 *
 * They live OUTSIDE the stage, over the tray, and that is the whole point.
 * Inside the stage they sat in the middle of the sukkah - three rows of
 * buttons squarely on top of the table, the people, and the very thing you
 * had just tapped. You were adjusting something you could not see.
 *
 * Over the tray they cover nothing that matters: while you are resizing a
 * lantern you are not also choosing a new sticker, and tapping the sukkah
 * puts the tray back. */
.selbar {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  /* Ten controls do not fit across a phone, so they wrap rather than running
   * off the edge. */
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100% - 20px);
  gap: 7px;
  padding: 7px;
  background: rgba(255, 255, 255, .95);
  border: 4px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 6px 0 var(--ink);
}
.selbar[hidden] { display: none; }
.selbar .rnd { width: 40px; height: 40px; font-size: 18px; box-shadow: 0 3px 0 var(--ink); }
.selbar .rnd[hidden] { display: none; }

/* The sticker following your finger out of the tray. */
.ghost {
  position: fixed;
  z-index: 60;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: .92;
  filter: drop-shadow(0 6px 5px rgba(38, 35, 74, .45));
}
.chip.lifting { opacity: .35; }

/* Choosing a sukkah and a sky. */
.picker {
  position: absolute;
  left: 0; right: 0;
  top: var(--topbar);
  z-index: 25;
  background: #fff;
  border-bottom: 4px solid var(--ink);
  padding: 10px 12px 14px;
  box-shadow: 0 8px 18px rgba(38, 35, 74, .25);
  max-height: 62vh;
  overflow-y: auto;
}
.picker[hidden] { display: none; }
.picker h3 { margin: 4px 0 8px; font-size: 15px; font-weight: 600; }
.picker .strip { display: flex; gap: 9px; overflow-x: auto; padding-bottom: 8px; }
.swatch {
  flex: none;
  width: 84px;
  border: 4px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  background: var(--cream);
  padding: 0 0 3px;
  overflow: hidden;
  cursor: pointer;
  font: inherit;
}
.swatch img { display: block; width: 100%; height: 58px; object-fit: cover; background: #A9CFE3; }
.swatch span { display: block; font-size: 12px; font-weight: 600; padding-top: 3px; }
.swatch.on { box-shadow: 0 4px 0 var(--ink), 0 0 0 5px var(--pick); background: #fff; }
.swatch:active { transform: translateY(2px); }

/* --------------------------------------------------------- a wide screen */
@media (min-width: 900px) {
  .split { flex-direction: row; }
  .tray {
    flex: none;
    width: var(--rail);
    border-top: none;
    border-left: 4px solid var(--ink);
    padding: 14px 12px;
  }
  .tabs { flex-wrap: wrap; overflow: visible; }
  .tab { flex: 1 1 44%; font-size: 14px; height: 38px; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 10px; }
  /* The tray is a rail down one side here, so the middle of the split is not
   * the middle of the sukkah. */
  .selbar { left: calc((100% - var(--rail)) / 2); max-width: calc(100% - var(--rail) - 20px); }
}

/* ------------------------------------------------------- somebody's guest */
/* A visitor sees the sukkah and nothing to fiddle with: no tray, no toolbar,
 * no paintbrush. The only thing they can do is go and build their own, which
 * is the whole point of sending the link. */
body.visiting .tray,
body.visiting .bottom:not(.visiting),
body.visiting #dress,
body.visiting #music,
body.visiting #mail,
body.visiting #book,
body.visiting #share,
body.visiting .selbar { display: none !important; }
body.visiting .piece { cursor: default; pointer-events: none; }
body.visiting .hint { bottom: 16px; }

/* --------------------------------------------------------- writing on it */
/* A sign is a sticker with words on it. The words are laid over the drawing
 * rather than drawn into it, so a child can change them without redrawing
 * anything, and they scale with the sign because everything here scales with
 * the wall. */
.piece img { display: block; width: 100%; height: 100%; }
.piece .words {
  position: absolute;
  /* The usable patch of each sign differs - a scroll is wide, a flag is a
   * triangle - so the inset is set per sign by the script and these are only
   * the fallback. */
  left: 14%; right: 14%; top: 16%; bottom: 16%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 600;
  line-height: 1.08;
  color: #3B2A14;
  word-break: break-word;
  hyphens: auto;
  /* A last line of defence. The size is shrunk to fit, but on a sign the size
   * of a stamp there is no size that fits, and writing must never spill past
   * the edge of the thing it is written on. */
  overflow: hidden;
  pointer-events: none;
}
.piece .words.dark { color: #FFF8E7; }

/* ------------------------------------------------------- being a guest */
/* One panel does every step of a visit and the guestbook too: a title, a
 * line of talk, a body and some buttons. A visit is four short questions and
 * a child's grandmother should never have to learn a second kind of screen. */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(38, 35, 74, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}
.sheet[hidden] { display: none; }
.sheetbox {
  width: 100%;
  max-width: 520px;
  max-height: 92%;
  overflow-y: auto;
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 26px;
  box-shadow: 0 10px 0 var(--ink);
  padding: 16px;
}
.sheetbox h2 { margin: 0 0 4px; font-size: 23px; font-weight: 600; text-align: center; }
.sheetbox p { margin: 0 0 12px; font-size: 15px; font-weight: 500; color: var(--grey); text-align: center; }
.sheetbtns { display: flex; gap: 10px; margin-top: 14px; }
.sheetbtns .btn { height: 52px; font-size: 17px; }

.whogrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.whopick {
  background: #fff; border: 4px solid var(--ink); border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink); padding: 6px 2px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.whopick img { width: 100%; height: 52px; object-fit: contain; display: block; }
.whopick.on { box-shadow: 0 4px 0 var(--ink), 0 0 0 5px var(--pick); }

.giftgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.giftgrid .whopick img { height: 48px; }

.namefield {
  width: 100%; margin-top: 12px; font: inherit; font-size: 19px; font-weight: 600;
  text-align: center; padding: 12px; border: 4px solid var(--ink); border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink); background: #fff; outline: none;
}
.namefield:focus { border-color: var(--pick); }
.msgfield { min-height: 84px; resize: none; text-align: left; font-size: 16px; font-weight: 500; }

.starrow { display: flex; justify-content: center; gap: 6px; margin: 6px 0 2px; }
.starrow button {
  border: none; background: none; font-size: 42px; line-height: 1; cursor: pointer; padding: 0;
  filter: grayscale(1); opacity: .3;
}
.starrow button.lit { filter: none; opacity: 1; }

.bookrow { display: flex; gap: 10px; align-items: flex-start; background: #fff;
  border: 4px solid var(--ink); border-radius: 18px; box-shadow: 0 4px 0 var(--ink);
  padding: 9px; margin-bottom: 9px; position: relative; }
.bookrow img { width: 46px; height: 46px; object-fit: contain; flex: none; }
.bookrow b { font-size: 16px; font-weight: 600; }
.bookrow .stars { font-size: 13px; }
.bookrow p { margin: 3px 0 0; text-align: left; font-size: 14px; color: #3B3960; }
.bookrow .kill { position: absolute; top: -10px; right: -8px; width: 26px; height: 26px;
  border-radius: 50%; background: #fff; border: 3px solid var(--ink); font-size: 13px;
  font-weight: 700; cursor: pointer; line-height: 1; padding: 0; }

.rnd .dot { position: absolute; top: -2px; right: -2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--coral); border: 3px solid var(--ink); }
.rnd { position: relative; }

/* Tamar, aged 7, asked for this: a letter button that goes green when somebody
 * has invited you, and opens a list of who. */
#mail.haspost { background: var(--mint); }
.invite { display: flex; gap: 10px; align-items: center; background: #fff;
  border: 4px solid var(--ink); border-radius: 18px; box-shadow: 0 4px 0 var(--ink);
  padding: 9px; margin-bottom: 9px; width: 100%; text-align: left; cursor: pointer; font: inherit; }
.invite img { width: 46px; height: 46px; object-fit: contain; flex: none; }
.invite b { font-size: 16px; font-weight: 600; display: block; }
.invite span { font-size: 13px; color: var(--grey); }
.invite.unread { box-shadow: 0 4px 0 var(--ink), 0 0 0 4px var(--mint); }

/* While a guest is choosing where their present goes, the sukkah is the only
 * thing to press and it says so. */
body.placing .stage { cursor: crosshair; }
body.placing .hint { bottom: 16px; opacity: 1; }
body.placing .hint.gone { opacity: 1; }

/* A guest's present and the basket it sits in are drawn, not owned. They are
 * not .piece: sharing that class made them count as decorations, and three
 * tests started counting other people's presents as the child's own things. */
.guestgift, .guestbasket {
  position: absolute;
  display: block;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(38, 35, 74, .28));
}

/* ---------------------------------------------------------- the gift basket */
/* A chest on the grass beside the sukkah. Pinned to the corner of the screen
 * rather than to a spot in the sukkah, because a place outside the hut in the
 * hut's own coordinates falls off the edge of a phone. */
.giftchest {
  position: absolute;
  right: 2.5%;
  bottom: 3%;
  width: clamp(76px, 13%, 132px);
  cursor: pointer;
  z-index: 8;
  text-align: center;
  filter: drop-shadow(0 4px 4px rgba(38, 35, 74, .4));
  transition: transform .12s;
}
.giftchest:hover { transform: translateY(-3px); }
.giftchest:active { transform: translateY(2px); }
.giftchest img { display: block; width: 100%; }
.giftchest .count {
  position: absolute;
  top: -6px; right: -6px;
  min-width: 26px; height: 26px;
  border-radius: 999px;
  background: var(--coral);
  color: #fff;
  border: 3px solid var(--ink);
  font-weight: 700; font-size: 14px; line-height: 20px;
  padding: 0 5px;
}
.giftchest .tag {
  display: block;
  margin-top: 2px;
  background: rgba(255, 255, 255, .92);
  border: 3px solid var(--ink);
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  padding: 1px 8px;
  white-space: nowrap;
}
@keyframes thud {
  0% { transform: translateY(-14px) scale(1.06); }
  60% { transform: translateY(3px) scale(.98); }
  100% { transform: translateY(0) scale(1); }
}
.giftchest.thud { animation: thud .6s ease-out; }

.giftrow {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border: 4px solid var(--ink); border-radius: 18px;
  box-shadow: 0 4px 0 var(--ink); padding: 8px; margin-bottom: 9px;
}
.giftrow img { width: 48px; height: 48px; object-fit: contain; flex: none; }
.giftrow b { display: block; font-size: 16px; font-weight: 600; }
.giftrow span { font-size: 13px; color: var(--grey); }

/* What a character is wearing. Positioned as a percentage of the character, so
 * it follows them through every size, turn and flip for free. */
.piece .addon {
  position: absolute;
  display: block;
  height: auto;
  pointer-events: none;
}

/* ------------------------------------------------- dragging on a touchscreen */
/* A finger dragging a sticker upward out of the tray and a finger scrolling the
 * tray are the same gesture, and the browser wins that argument every time: it
 * scrolls, then sends pointercancel, and the sticker is dropped.
 *
 * So on a narrow screen the shelf scrolls sideways instead. `touch-action:
 * pan-x` then hands the browser the horizontal swipes, which scroll the tray,
 * and leaves every vertical movement to the game - which is exactly the drag
 * that carries a sticker up into the sukkah. */
@media (max-width: 899px) {
  .shelf {
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-template-rows: repeat(2, 1fr);
    grid-auto-columns: 64px;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
    scrollbar-width: none;
  }
  .shelf::-webkit-scrollbar { display: none; }
  .chip { touch-action: pan-x; }
}

/* The top bar gained buttons faster than a phone gained width: paint, full
 * screen, language, music, sound, camera and the link, plus the sukkah's name.
 * On a narrow screen the buttons shrink, the gaps close and the subtitle goes,
 * which is the least useful thing up there. */
@media (max-width: 899px) {
  .topbar { gap: 5px; padding: 0 8px; height: 56px; }
  .rnd { width: 38px; height: 38px; font-size: 17px; border-width: 3px; box-shadow: 0 3px 0 var(--ink); }
  .title { font-size: 17px; }
  .title small { display: none; }
  #sukkah-name { font-size: 17px; }
}
