@font-face {
  font-family: "Jersey 15";
  src: url("/fonts/jersey-15.woff2") format("woff2");
  font-display: swap;
  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: "Jersey 15";
  src: url("/fonts/jersey-15-ext.woff2") format("woff2");
  font-display: swap;
  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 {
  --ink: #241a15;
  --paper: #fbf4e6;
  --cream: #f1e3c8;
  --parchment: #d4c3a0;
  --tan: #e3a24f;
  --green: #3d7a58;
  --red: #b3362b;
  --blue: #1f2f9c;
  --dark: #1b1411;
  font-family: "Jersey 15", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 16px;
  line-height: 1.15;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--dark);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ stage */

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

#room {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: default;
}
#room.can-click { cursor: pointer; }

button {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 0;
  box-shadow: 0 2px 0 var(--ink);
  padding: 0 7px 1px;
  min-height: 22px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: #fff; }
button:active { transform: translateY(2px); box-shadow: none; }
button:disabled { opacity: .55; cursor: default; transform: none; box-shadow: 0 2px 0 var(--ink); background: var(--cream); }
button.primary { background: var(--tan); }
button.primary:hover { background: #f0b262; }
button.on { background: var(--tan); }
button.link { background: none; border: 0; box-shadow: none; padding: 2px; text-decoration: underline; min-height: 0; }
button.link:active { transform: none; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }

#hud {
  position: absolute;
  inset: 4px 4px auto 4px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
#coins {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--ink);
  color: #ffe27a;
  padding: 1px 7px 2px 5px;
  min-height: 22px;
}
#coin-icon { width: 18px; height: 18px; image-rendering: pixelated; }
#buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }

#status {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  margin: 0;
  padding: 1px 8px 2px;
  background: var(--ink);
  color: var(--paper);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ cards */

.card {
  position: absolute;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(27, 20, 17, .55);
}

#auth, #notice, #panel {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100% - 12px);
  overflow: auto;
}

#auth { width: min(296px, calc(100% - 16px)); padding: 10px 14px 8px; text-align: center; }
#auth h1 { margin: 0; font-size: 38px; font-weight: 400; line-height: .9; letter-spacing: 1px; }
.tagline { margin: 2px 0 8px; color: #6d5a4c; }
#auth-form { display: grid; gap: 6px; text-align: left; }
#auth-form label { display: grid; gap: 1px; }
#auth-form input {
  width: 100%;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: 1px 6px 2px;
  min-height: 26px;
  font-size: 18px;
}
#auth-form input:focus { outline: 2px solid var(--green); outline-offset: 0; }
#auth-submit { min-height: 28px; font-size: 18px; margin-top: 2px; }
#auth-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 12px; margin-top: 4px; }
#auth-legal { margin: 1px 0 0; font-size: 14px; line-height: 1; }
#auth-legal a { color: inherit; }
#auth-form #auth-legal label { display: block; cursor: pointer; }
#auth-form #auth-legal input { width: 13px; height: 13px; min-height: 0; padding: 0; margin: 0 3px 0 0; vertical-align: -2px; accent-color: var(--green); }
#auth-form .error { line-height: 1.05; }
#auth.welcome #auth-submit, #auth.login #auth-submit { min-height: 36px; font-size: 22px; }
/* A guest with something to lose: the Save button asks for attention. */
#b-save.nudge { animation: nudge 1.2s steps(2, jump-none) 6; }
@keyframes nudge { 50% { background: #fff; } }
/* Saving happens over the whole window, chat included, so the card has room. */
#auth.save { z-index: 6; position: fixed; max-height: calc(100dvh - 12px); }
#auth.save h1 { font-size: 28px; line-height: 1; letter-spacing: 0; }
.soft { color: #8a776a; }
.error { margin: 0; color: var(--red); }

#notice { width: min(260px, calc(100% - 16px)); padding: 12px 14px; text-align: center; }
#notice p { margin: 0 0 10px; }

#panel { width: min(408px, calc(100% - 12px)); padding: 0 10px 10px; }
.panel-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 0 -10px 8px;
  padding: 5px 8px 5px 10px;
  background: var(--ink);
  color: var(--paper);
}
.panel-head h2 { margin: 0; font-size: 20px; font-weight: 400; }
.panel-head .note { color: #ffe27a; margin-left: auto; }
.panel-head button { min-height: 20px; color: var(--ink); }
.panel-hint { margin: 0 0 8px; color: #6d5a4c; }
.group { margin: 10px 0 4px; font-size: 16px; font-weight: 400; color: #6d5a4c; }
.group:first-of-type { margin-top: 0; }

.goods { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 6px; }
.good {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 4px 4px 6px;
  background: var(--cream);
  border: 2px solid var(--ink);
  text-align: center;
}
.good canvas, .preview canvas { image-rendering: pixelated; display: block; }
.good .name { line-height: 1; }
.price { display: inline-flex; align-items: center; gap: 3px; }
.only { color: var(--green); line-height: 1; }
.price canvas { width: 9px; height: 9px; image-rendering: pixelated; }

.wardrobe, .builder { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; }
.wardrobe h3, .builder h3 { margin: 0 0 3px; font-size: 16px; font-weight: 400; color: #6d5a4c; }
.under { display: block; width: 100%; margin-top: 6px; white-space: normal; line-height: 1; padding: 3px 4px 4px; }
.holding { align-self: center; }
.choices.end { justify-content: flex-end; margin: 4px 0 0; }

/* The builder: colours as swatches, markings as small corgis. */
.builder .preview canvas { width: 96px; height: 112px; }
.swatch { width: 26px; height: 26px; min-height: 0; padding: 0; }
.swatch.on { outline: 3px solid var(--ink); outline-offset: 2px; box-shadow: none; }
.swatch:hover { filter: brightness(1.06); }
.swatch:disabled { opacity: .3; }
.builder h3 .soft { font-size: 14px; }
.markings { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-bottom: 8px; }
.marking { display: grid; justify-items: center; align-content: start; padding: 1px 1px 3px; white-space: normal; line-height: .95; font-size: 14px; }
.marking canvas { image-rendering: pixelated; display: block; width: 34px; height: 34px; }
/* With room to spare, the corgi being made is bigger. */
@media (min-width: 520px) and (min-height: 520px) {
  #panel.wide { width: min(480px, calc(100% - 12px)); }
  .builder .preview canvas { width: 144px; height: 168px; }
  .marking canvas { width: 51px; height: 51px; }
  .marking { font-size: 16px; }
}
#auth-note { margin: 0; line-height: 1.05; }
.preview { background: #d6b085; border: 2px solid var(--ink); padding: 2px 6px 0; }
.choices { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }

.rows { display: grid; gap: 4px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 6px;
  background: var(--cream);
  border: 2px solid var(--ink);
}
.row.here { background: #f6dba8; }
.row .count { margin-left: auto; color: #6d5a4c; }

#popover { padding: 6px; display: grid; gap: 4px; min-width: 110px; z-index: 5; }
#popover .who { margin: 0 0 2px; text-align: center; }

/* ------------------------------------------------------------------- chat */

#chat {
  flex: 0 0 auto;
  background: var(--parchment);
  border-top: 2px solid var(--ink);
  font-size: 16px;
}
#log {
  height: 58px;
  overflow-y: auto;
  padding: 2px 6px 0;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
  scrollbar-color: #8a775c var(--parchment);
}
#log p { margin: 0; }
#log .said { color: var(--blue); }
#log .sys { color: var(--red); }
#log button.who { all: unset; cursor: pointer; color: var(--ink); }
#log button.who:hover { text-decoration: underline; }
#log button.who:focus-visible { outline: 2px solid var(--green); }
#say {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px 2px;
  border-top: 1px solid #8a775c;
}
#say-name { flex: 0 0 auto; }
#say-text {
  flex: 1 1 auto;
  min-width: 0;
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--blue);
  /* 16px keeps iOS from zooming the page when the box is tapped. */
  font-size: 16px;
  min-height: 22px;
}
#say-text:focus { outline: none; }
#say:focus-within { background: #e0d1b0; }

/* A very short window keeps the room and the line you type on. */
@media (max-height: 300px) {
  #log { display: none; }
}

/* In a very small window the buttons stay out of the way until the pointer comes in. */
@media (hover: hover) and (max-width: 380px), (hover: hover) and (max-height: 300px) {
  #hud { opacity: 0; transition: opacity .12s; }
  #stage:hover #hud, #hud:focus-within { opacity: 1; }
}

/* Held upright, the cafe takes the top of the screen and the chat the rest.
   Both give way evenly when the keyboard comes up. */
@media (max-aspect-ratio: 4/5) {
  #stage { flex: 3 1 0; min-height: 0; }
  #chat { flex: 2 1 0; min-height: 0; display: flex; flex-direction: column; }
  #log { flex: 1 1 auto; height: auto; min-height: 0; }
}

/* Fingers: bigger things to press, and a row of things to say with one tap. */
#quick { display: none; }
@media (pointer: coarse) {
  button { min-height: 34px; padding: 0 10px 1px; font-size: 18px; }
  button.link { min-height: 30px; }
  #coins { min-height: 34px; font-size: 18px; }
  .swatch { width: 34px; height: 34px; }
  #popover button { min-height: 40px; }
  #quick { display: flex; gap: 6px; padding: 4px 6px; overflow-x: auto; border-top: 1px solid #8a775c; scrollbar-width: none; }
  #quick button { flex: 0 0 auto; min-height: 30px; font-size: 16px; box-shadow: none; }
  #say-text { min-height: 34px; }
}

/* A phone on its side: the cafe fills the screen, and the last few lines of
   chat are written over its bottom corner. */
@media (pointer: coarse) and (max-height: 430px) and (min-aspect-ratio: 5/4) {
  #quick { display: none; }
  #log {
    display: flex; flex-direction: column; justify-content: flex-end;
    position: fixed; left: 8px; bottom: 40px; width: 60%; height: auto; max-height: 4.6em;
    overflow: hidden; padding: 0; background: none; pointer-events: none;
    text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, 1px -1px 0 #000, -1px -1px 0 #000;
  }
  #log p, #log .said, #log .sys, #log button.who { color: #fff; flex: 0 0 auto; }
  #log .said { color: #ffff00; }
}

@media (prefers-reduced-motion: reduce) {
  button:active { transform: none; }
  #b-save.nudge { animation: none; }
}

/* ...and let a panel use the whole screen rather than the strip the cafe sits in. */
@media (max-aspect-ratio: 4/5) {
  #panel {
    position: fixed;
    inset: 8px 6px;
    transform: none;
    width: auto;
    max-height: none;
    z-index: 4;
  }
}

/* The builder has three rows of choices; keep them close so it all fits a small window. */
.builder h3 { margin-bottom: 1px; }
.builder .choices, .builder .markings { margin-bottom: 4px; }
.builder .choices.end { margin: 2px 0 0; }
.builder .marking { padding-bottom: 1px; }
#panel.wide { padding-bottom: 6px; }

#popover .leaving { margin: 2px 4px 4px; max-width: 140px; line-height: 1.05; }
