/* Neutral greys only, and no dark or colour theme: a coloured surround shifts how skin and hair tones are perceived. */
:root {
  --bg: #808080;
  --panel: #5e5e5e;
  --panel-strong: #404040;
  --ink: #ffffff;
  --ink-dim: #dcdcdc;
  --focus: #ffffff;
  --pad: 6px;
  --gap: 3px;
  --season-gap: 14px;
  --col-gap: 10px;
  --name-w: 70px;
  --mid-min: 30vw;
  --vh: 100vh;
  /* Eight rows fill the window height exactly, so nothing ever scrolls and every group stays in view. */
  --row: calc((var(--vh) - 2 * var(--pad) - 6 * var(--gap) - var(--season-gap)) / 8);
  --tile-w: min(calc(var(--row) * .8), calc((100vw - 2 * var(--pad) - 2 * var(--col-gap) - var(--mid-min) - 2 * var(--name-w)) / 10 - 2px));
  --side-w: calc(var(--name-w) + 5 * var(--tile-w) + 10px);
}
/* Unlike vh, dvh leaves out the browser's own toolbars on a tablet. Without it, older iPads fall back to vh. */
@supports (height: 100dvh) {
  :root { --vh: 100dvh; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 .35em;
  border-radius: 3px;
  background: var(--panel-strong);
  color: var(--ink);
  font: 600 12px/1.6 ui-monospace, monospace;
  text-align: center;
}

/* Login */
#login, #picker {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: fixed;
  inset: 0;
  z-index: 5;
  overflow: auto;
  padding: 12vh max(16px, calc(50vw - 260px)) 24px;
  background: var(--bg);
}
#login > *, #picker > * { flex: none; }
h1 { margin: 0; font-size: 22px; }
#login label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
/* 16px at least, or iPad Safari zooms the page when a field gets focus. */
#login input {
  padding: 10px;
  border: 0;
  border-radius: 4px;
  font: 16px system-ui, -apple-system, sans-serif;
  color: #000;
  background: #fff;
}
.action {
  padding: 8px 12px;
  border: 0;
  border-radius: 4px;
  background: var(--panel-strong);
}
.action:disabled { opacity: .5; cursor: default; }
#loginBtn { padding: 12px; font-weight: 700; font-size: 16px; }
.note { margin: 0; color: var(--ink); font-size: 13px; }
#loginMsg { margin: 0; font-weight: 700; }
#loginMsg:empty { display: none; }
#pickerList { display: grid; gap: 8px; }
#pickerList button {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 14px;
  align-items: center;
  font-size: 17px;
  font-weight: 600;
  text-align: left;
}
#pickerList span:last-child { font-size: 14px; font-weight: 400; font-variant-numeric: tabular-nums; white-space: nowrap; }
#pickerMsg { margin: 0; font-weight: 700; }
#pickerMsg:empty { display: none; }
#pickerFoot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#pickerFoot button { min-height: 44px; }
#who { flex: 1; text-align: center; font-size: 13px; }

/* Labeling */
#app {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, calc(var(--vh) * .72)) var(--side-w);
  justify-content: center;
  gap: var(--col-gap);
  height: var(--vh);
  padding: var(--pad);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.side { display: flex; flex-direction: column; justify-content: space-between; min-width: 0; }
.season { display: grid; gap: var(--gap); }
.group {
  display: grid;
  grid-template-columns: var(--name-w) repeat(5, var(--tile-w));
  gap: 2px;
  height: var(--row);
  padding: 0;
  border: 0;
  background: var(--panel);
  text-align: left;
  /* Keeps the finger's events flowing during a press and hold, and removes the tap delay. Nothing here scrolls anyway. */
  touch-action: none;
}
.side.right .group { grid-template-columns: repeat(5, var(--tile-w)) var(--name-w); }
.side.right .name { order: 1; }
.group.hit { outline: 3px solid var(--focus); outline-offset: -1px; position: relative; z-index: 1; background: var(--ink); color: #000; }
.group img { display: block; width: 100%; height: var(--row); object-fit: cover; pointer-events: auto; }
.name {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 3px;
  padding: 0 6px;
  font-size: clamp(11px, calc(var(--row) * .135), 14px);
  line-height: 1.15;
  font-weight: 600;
  min-width: 0;
}

.mid { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 6px; min-width: 0; }
#progress { height: 4px; background: var(--panel); }
#progressBar { height: 100%; width: 0; background: var(--ink); }
#stage { position: relative; min-height: 0; }
#app.buttons { grid-template-columns: minmax(0, var(--vh)); }
#choices { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
#choices button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: clamp(64px, 13dvh, 110px);
  border: 0;
  border-radius: 4px;
  background: var(--panel);
  font-size: 22px;
  font-weight: 700;
}
#choices button.hit { outline: 3px solid var(--focus); outline-offset: -1px; background: var(--ink); color: #000; }
#stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.stageMsg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  text-align: center;
  font-size: 16px;
}
.stageMsg h2 { margin: 0; font-size: 24px; }
.stageMsg p { margin: 0; }
.stageMsg table { border-collapse: collapse; font-size: 14px; text-align: left; }
.stageMsg td { padding: 1px 8px; }
.stageMsg td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
#extras { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
#extras button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  height: clamp(44px, 7dvh, 56px);
  padding: 0 4px;
  border: 0;
  border-radius: 4px;
  background: var(--panel);
  font-size: clamp(12px, 1.15vw, 15px);
  font-weight: 600;
  line-height: 1.1;
}
#extras button.hit { outline: 3px solid var(--focus); outline-offset: -1px; background: var(--ink); color: #000; }
#status {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  font-size: 13px;
}
#count { font-weight: 700; font-variant-numeric: tabular-nums; }
#last { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#last.warn { font-weight: 700; white-space: normal; line-height: 1.1; }
#undo, #menu { padding: 2px 8px; }

/* Hover and key hints only where there is a mouse. On a touch screen a hover style sticks to whatever was tapped last. */
@media (hover: hover) {
  .group:hover { outline: 3px solid var(--focus); outline-offset: -1px; position: relative; z-index: 1; }
  #extras button:hover, #choices button:hover { outline: 3px solid var(--focus); outline-offset: -1px; }
  .action:hover:not(:disabled) { background: #333; }
}
@media (hover: none) {
  kbd { display: none; }
  #status { min-height: 44px; }
  #undo { min-height: 44px; min-width: 64px; font-weight: 600; }
  #menu { min-height: 44px; }
}

/* A reference face enlarged by press and hold. It stays over its own column, so the photo in the middle stays visible. */
#zoom {
  position: fixed;
  z-index: 3;
  background: var(--panel-strong);
  border: 3px solid var(--focus);
  pointer-events: none;
}
#zoomImg { display: block; width: 100%; height: 100%; object-fit: cover; }
#zoomName {
  position: absolute;
  left: 0;
  bottom: 0;
  padding: 2px 8px;
  background: var(--panel-strong);
  font-weight: 600;
}

#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 8;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  font-size: 20px;
  font-weight: 600;
  text-align: center;
}
/* In portrait the reference faces get too narrow to see. Mouse users keep whatever window shape they like. */
@media (orientation: portrait) and (hover: none) {
  body.needs-landscape #rotate { display: flex; }
}

#fatal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, .8);
  font-size: 18px;
  text-align: center;
}
