:root {
  --paper: #f3eee4;
  --ink: #1d1a17;
  --muted: #5e564d;
  --edge: #d9d0c1;
  --card: #fffaf1;
  --accent: #9a4220;
  color-scheme: light;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;    /* no bounce or pull-to-refresh mid-stroke */
  background: var(--paper);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.5 ui-rounded, "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
}

a { color: var(--ink); text-underline-offset: 0.15em; }

button { font: inherit; color: inherit; }

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* the app: label, wall, toolbar — exactly one screen tall */

.app {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: 100vh;                /* fallback */
  height: 100dvh;               /* follows the phone's collapsing address bar */
  min-height: 20rem;
  max-width: 64rem;
  margin: 0 auto;
  padding:
    max(0.5rem, env(safe-area-inset-top))
    max(0.5rem, env(safe-area-inset-right))
    max(0.5rem, env(safe-area-inset-bottom))
    max(0.5rem, env(safe-area-inset-left));
}

/* today's tin, as a slim label above the wall */

.label {
  flex: none;
  padding: 0 0.25rem;
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--muted);
}

.label-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.label h2 {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
}

.batch {
  margin-left: 0.35em;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.batch .star { color: var(--accent); }

.about-link {
  display: inline-block;
  padding: 0.2rem 0.25rem;
  color: var(--muted);
}

.warning {
  margin: 0.1rem 0 0;
  color: var(--ink);
}

.same { margin: 0; }

/* the wall */

.wall {
  position: relative;
  flex: 1 1 auto;
  min-height: 10rem;
  overflow: hidden;
  border: 1px solid var(--edge);
  border-radius: 1rem;
  background: var(--paper);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#room {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;           /* dragging sprays; it never scrolls or zooms */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;  /* no iOS long-press callout */
  -webkit-tap-highlight-color: transparent;
}

#room:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: -3px;
}

.cta {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 1rem;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.6s ease, visibility 0.6s;
}

.cta.gone {
  opacity: 0;
  visibility: hidden;
}

.cta-main {
  margin: 0;
  font-size: clamp(2rem, 9vw, 3.5rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
}

.cta-hint {
  margin: 0.6rem 0 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.status {
  position: absolute;
  right: 0.5rem;
  bottom: 0.5rem;
  left: 0.5rem;
  width: fit-content;
  max-width: calc(100% - 1rem);
  margin: 0 auto;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: rgba(243, 238, 228, 0.88);
  font-size: 0.85rem;
  line-height: 1.3;
  text-align: center;
  pointer-events: none;
}

.status:empty {
  padding: 0;
  background: none;
}

.nojs-note {
  display: none;
  position: absolute;
  inset: auto 1rem 1rem;
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.no-js .cta,
.no-js .controls { display: none; }

.no-js .nojs-note { display: block; }

/* the toolbar, pinned under the wall */

.toolbar {
  flex: none;
  display: grid;
  gap: 0.4rem;
}

.pigments {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
}

.pigment {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  min-height: 44px;
  padding: 0.35rem 0.5rem;
  border: 2px solid var(--edge);
  border-radius: 0.75rem;
  background: var(--card);
  font-size: 0.8rem;
  line-height: 1.15;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.pigment[aria-pressed="true"] {
  border-color: var(--ink);
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--ink);
  font-weight: 700;
}

.pname {
  min-width: 0;
  /* long names (Quinacridone, Duochrome) break at a syllable with a hyphen,
     never mid-word without one */
  -webkit-hyphens: auto;
  hyphens: auto;
  overflow-wrap: break-word;
}

/* no-JS defaults; smoke.js overrides --c with today's colours */
.pigment:nth-child(1) { --c: #3348c8; }
.pigment:nth-child(2) { --c: #f4d10c; }
.pigment:nth-child(3) { --c: #c21a5c; }

.swatch {
  flex: none;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  background: var(--c, #888);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

/* a misprint pigment catches the light; still under reduced motion */
.pigment.odd .swatch {
  background: linear-gradient(120deg, var(--c) 25%, var(--c2, #fff) 50%, var(--c) 75%);
  background-size: 300% 100%;
  animation: shimmer 3.2s ease-in-out infinite alternate;
}

@keyframes shimmer {
  from { background-position: 0% 0; }
  to   { background-position: 100% 0; }
}

.controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.35rem;
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-width: 0;
  min-height: 52px;
  padding: 0.3rem 0.15rem;
  border: 2px solid var(--ink);
  border-radius: 0.75rem;
  background: transparent;
  color: var(--ink);
  font-size: 0.72rem;
  line-height: 1.1;
  cursor: pointer;
  touch-action: manipulation;
}

.tool svg {
  flex: none;
  width: 1.35rem;
  height: 1.35rem;
}

.tool.primary {
  background: var(--ink);
  color: var(--paper);
}

.tool[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--paper);
}

/* wide screens and landscape phones: pigments and controls share a row */

@media (min-width: 48rem), (orientation: landscape) and (max-height: 32rem) {
  .toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
  }

  .controls { grid-template-columns: repeat(5, 4.75rem); }
}

@media (min-width: 48rem) {
  .app {
    gap: 0.75rem;
    padding:
      max(1rem, env(safe-area-inset-top))
      max(1.5rem, env(safe-area-inset-right))
      max(1rem, env(safe-area-inset-bottom))
      max(1.5rem, env(safe-area-inset-left));
  }

  .label { font-size: 0.9rem; }
  .label h2 { font-size: 0.85rem; }
  .pigment { font-size: 0.9rem; }
  .tool { font-size: 0.8rem; }
}

@media (max-height: 32rem) {
  .app { gap: 0.35rem; }
  .same { display: none; }
  .tool { min-height: 44px; }
}

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

/* about, below the fold */

.about {
  max-width: 40rem;
  margin: 0 auto;
  padding:
    2rem
    max(1rem, env(safe-area-inset-right))
    max(2rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  font-size: 0.9rem;
  color: var(--muted);
}

.about h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: var(--ink);
}

.about p { margin: 0 0 0.6rem; }

/* 404 */

.lost {
  display: grid;
  place-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
}

.lost svg {
  display: block;
  width: min(16rem, 60vw);
  height: auto;
  margin: 0 auto 1rem;
}

.lost .code {
  margin: 0;
  font-size: 0.9rem;
  letter-spacing: 0.2em;
  color: var(--muted);
}

.lost h1 {
  margin: 0.25rem 0 0.5rem;
  font-size: clamp(1.75rem, 6vw, 2.75rem);
  line-height: 1.1;
}

.lost p { margin: 0 0 0.75rem; }

.drift {
  transform-box: fill-box;
  animation: drift 7s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translate(0, 0); opacity: 1; }
  to   { transform: translate(10px, -12px); opacity: 0.6; }
}

/* motion */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
