/* ---------- tokens ---------- */
:root {
  --paper: #f7f6f2;
  --ink: #26324f;
  --ink-2: #3a4566;
  --muted: #8a8e97;
  --faint: #c3c2bc;
  --line: rgba(38, 50, 79, 0.14);
  --hover: rgba(38, 50, 79, 0.05);
  --ui: 'Unica', 'Neue Haas Unica', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --mono: 'HP Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --gutter: clamp(16px, 2.2vw, 28px);
  --panel-w: 248px;

  /* type scale: label 11 · body 14 · lead 16 · display 32 */
  --t-label: 11px;
  --t-body: 14px;
  --t-lead: 16px;
  --t-display: clamp(26px, 3vw, 32px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--t-body)/1.45 var(--ui);
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 1px dotted var(--ink); outline-offset: 3px; }
svg { display: block; }

/* small uppercase labels — one style used everywhere */
.eyebrow, .row__label, .piece__meta, .menu__item, .pick, .row__val {
  font-size: var(--t-label);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.eyebrow { color: var(--muted); margin-bottom: 6px; }

/* ---------- header ---------- */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 4;
  display: flex; justify-content: space-between; align-items: baseline;
  padding: var(--gutter);
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.mark { font-weight: 500; }
.links { display: flex; gap: 20px; }
.links a { color: var(--muted); transition: color .2s; }
.links a:hover, .links a.is-on { color: var(--ink); }

/* ---------- home ---------- */
.view { min-height: 100vh; }
#make { display: grid; place-items: center; padding: 84px var(--gutter) 96px; }
.home { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 20px; }
.mosaic {
  --cols: 8;
  position: relative;
  width: min(100%, calc((100vh - 190px) * 1.6), 1240px);
  display: grid; gap: 10px;
  grid-template-columns: repeat(var(--cols), 1fr);
}
.tile { position: relative; aspect-ratio: 1; display: block; border-radius: 2px; transition: opacity .3s; }
.tile canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.tile:hover { opacity: .65; }
.drop {
  grid-column: 2 / 8; grid-row: 2 / 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  text-align: center; cursor: pointer; padding: 56px 24px;
  border: 1.5px dotted rgba(38, 50, 79, .3); border-radius: 10px;
  transition: background .2s, border-color .2s;
}
.drop:hover, body.dragging .drop { background: var(--hover); border-color: rgba(38, 50, 79, .5); }
.drop__title { font-size: var(--t-display); font-weight: 500; letter-spacing: .005em; line-height: 1.1; }
.drop__sub { color: var(--muted); font-size: var(--t-lead); max-width: 30ch; }
.drop__cta { margin-top: 14px; font-weight: 500; }
.drop__hint { color: var(--muted); font-size: 12px; }
.home__note {
  position: absolute; z-index: 1; left: 50%; top: calc(100% - var(--tile, 64px) / 2);
  transform: translate(-50%, -50%); white-space: nowrap;
  color: var(--muted); font-size: 12px;
  background: var(--paper); padding: 4px 12px; border-radius: 999px;
}
.home__note a { color: var(--ink); border-bottom: 1px solid var(--line); }
body.dragging .drop__title::after { content: ' here'; }

/* ---------- stage ---------- */
.stage {
  position: relative;
  width: min(980px, calc(100vw - 2 * (var(--panel-w) + 2 * var(--gutter))));
  height: calc(100vh - 200px);
  display: grid; place-items: center;
}
body.dragging .stage::after {
  content: 'Release for a new image'; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: var(--t-lead); background: rgba(247, 246, 242, .85); border: 1px solid var(--line);
}
.out { max-width: 100%; max-height: 100%; }
.out--ht { display: block; touch-action: none; cursor: crosshair; }
.out--ascii {
  resize: none; border: 0; outline: none; background: transparent; color: var(--ink);
  font-family: var(--mono); line-height: 1; letter-spacing: 0;
  white-space: pre; overflow: auto; padding: 0; scrollbar-width: none; caret-color: var(--ink);
}
.out--ascii::-webkit-scrollbar { display: none; }
.out--ascii:focus { background: var(--hover); }

/* ---------- corners ---------- */
.modes {
  position: fixed; left: var(--gutter); bottom: var(--gutter); z-index: 3;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
}
.mode { color: var(--faint); font-size: var(--t-lead); position: relative; padding-left: 14px; transition: color .2s; }
.mode:hover { color: var(--muted); }
.mode.is-on { color: var(--ink); }
.mode.is-on::before { content: ''; position: absolute; left: 0; top: 50%; width: 5px; height: 5px; margin-top: -2px; border-radius: 50%; background: var(--ink); }

.dock { position: fixed; left: 50%; bottom: var(--gutter); transform: translateX(-50%); z-index: 3; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 18px 0 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--paper);
  transition: border-color .2s, background .2s;
}
.pill:hover { border-color: rgba(38, 50, 79, .35); background: var(--hover); }
.pill svg { width: 12px; height: 12px; stroke: currentColor; stroke-width: 1.4; fill: none; stroke-linecap: round; }

.status {
  position: fixed; left: 50%; bottom: calc(var(--gutter) + 46px); transform: translateX(-50%); z-index: 3;
  color: var(--muted); font-size: 12px; white-space: nowrap;
  background: var(--paper); padding: 2px 10px; border-radius: 999px;
  opacity: 0; transition: opacity .4s; pointer-events: none;
}
.status.is-on { opacity: 1; }
body:not(.has-image) .status { bottom: var(--gutter); }

/* ---------- settings panel ---------- */
.panel {
  position: fixed; right: var(--gutter); bottom: var(--gutter); z-index: 3;
  width: var(--panel-w);
  display: flex; flex-direction: column;
}
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 30px;
  border-top: 1px solid var(--line);
}
.row:first-of-type { border-top: 0; }
.row__label { color: var(--muted); }
.row__val { color: var(--ink); min-width: 2.5ch; text-align: right; font-variant-numeric: tabular-nums; }
.row__ctl { display: flex; align-items: center; gap: 10px; }

.pick { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); padding: 6px 8px; margin-right: -8px; border-radius: 4px; }
.pick:hover { background: var(--hover); }
.pick svg, .dl__fmt svg { width: 8px; height: 8px; stroke: currentColor; stroke-width: 1.4; fill: none; transition: transform .2s; }
.pick[aria-expanded="true"] svg, .dl__fmt[aria-expanded="true"] svg { transform: rotate(180deg); }
.swatch { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); flex: none; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 104px; height: 16px; background: transparent; cursor: pointer; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 1px; background: var(--faint); }
input[type=range]::-moz-range-track { height: 1px; background: var(--faint); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 10px; height: 10px; border-radius: 50%; background: var(--ink); margin-top: -4.5px; }
input[type=range]::-moz-range-thumb { width: 10px; height: 10px; border: 0; border-radius: 50%; background: var(--ink); }

.switch {
  position: relative; width: 26px; height: 14px; border-radius: 999px;
  background: var(--faint); transition: background .2s; flex: none;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--paper); transition: transform .2s;
}
.switch[aria-checked="true"] { background: var(--ink); }
.switch[aria-checked="true"]::after { transform: translateX(12px); }

.actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin-top: 14px; }
.textbtn { font-size: var(--t-label); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.textbtn:hover { color: var(--ink); }
.dl { display: inline-flex; height: 36px; border-radius: 999px; background: var(--ink); color: var(--paper); overflow: hidden; }
.dl button { font-size: var(--t-label); letter-spacing: .1em; text-transform: uppercase; transition: background .2s; }
.dl button:hover { background: var(--ink-2); }
.dl__go { padding: 0 14px 0 18px; font-weight: 500; }
.dl__fmt { display: inline-flex; align-items: center; gap: 6px; padding: 0 14px 0 12px; border-left: 1px solid rgba(247, 246, 242, .25) !important; opacity: .85; }
.dl button:disabled { opacity: .5; cursor: progress; }

/* dropdown menu (one, positioned next to whichever control opened it) */
.menu {
  position: fixed; z-index: 10; min-width: 140px;
  padding: 4px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 4px;
  box-shadow: 0 8px 24px rgba(38, 50, 79, .1);
}
.menu__item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border-radius: 2px; color: var(--muted); text-align: left;
}
.menu__item:hover, .menu__item:focus-visible { background: var(--hover); color: var(--ink); outline: none; }
.menu__item[aria-selected="true"] { color: var(--ink); }
.menu__item[aria-selected="true"]::after { content: ''; margin-left: auto; width: 5px; height: 5px; border-radius: 50%; background: var(--ink); }
.menu__note { margin-left: auto; color: var(--faint); letter-spacing: .06em; }

/* ---------- wall ---------- */
#wall { padding: 120px var(--gutter) 80px; }
.wall__head { max-width: 1080px; margin: 0 auto 32px; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.seg { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 999px; flex: none; }
.seg button { height: 28px; padding: 0 14px; border-radius: 999px; font-size: var(--t-label); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); transition: color .2s, background .2s; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.wall__title { font-size: var(--t-display); font-weight: 500; letter-spacing: .005em; line-height: 1.1; }
.wall__sub { margin-top: 8px; color: var(--muted); max-width: 54ch; }
.wall__grid { max-width: 1080px; margin: 0 auto; columns: 4 220px; column-gap: 24px; }
.piece { margin: 0 0 32px; display: flex; flex-direction: column; gap: 10px; break-inside: avoid; }
.piece__frame { position: relative; }
.piece__frame img { display: block; width: 100%; height: auto; transition: opacity .4s; }
.piece__frame .piece__in { position: absolute; inset: 0; height: 100%; object-fit: contain; }
.piece__in { opacity: 0; }
.piece:hover .piece__in, .piece:focus-visible .piece__in { opacity: 1; }
.piece__meta { display: flex; justify-content: space-between; color: var(--muted); }
.wall__note { max-width: 1080px; margin: 32px auto 0; color: var(--muted); }

/* ---------- smaller screens: stack everything ---------- */
@media (max-width: 1000px) {
  .top { position: absolute; }
  #make { display: flex; flex-direction: column; align-items: stretch; gap: 24px; padding: 72px var(--gutter) 32px; }
  body:not(.has-image) #make { justify-content: center; }
  .dock { position: static; transform: none; align-self: center; order: 10; margin-top: 8px; }
  .status, body:not(.has-image) .status { bottom: 12px; }
  .mosaic { --cols: 4; width: 100%; }
  .drop { grid-column: 1 / 5; grid-row: 2 / 5; }
  .stage { width: 100%; height: 56vh; }
  .modes, .panel { position: static; }
  .modes { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 18px; }
  .modes .eyebrow { margin: 0 6px 0 0; }
  .panel { width: 100%; }
}
