:root {
  --bg: #000;
  --panel: #1c1c1e;
  --line: #38383a;
  --text: #f2f2f7;
  --muted: #98989f;
  --accent: #0a84ff;
  --paper: #fbfaf6;
  --ink: #1c1c1e;
  --solved: #0a66d6;
  --warn: #ff9f0a;
  --bad: #ff453a;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* A fixed full-screen app: nothing scrolls, nothing zooms. */
html,
body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: var(--bg);
  color: var(--text);
  font:
    17px / 1.35 -apple-system,
    system-ui,
    "Segoe UI",
    Roboto,
    sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
label {
  font: inherit;
  color: inherit;
  touch-action: none;
}

svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}
.screen[hidden] {
  display: none;
}

/* camera */
.cam-view {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #000;
}
.cam-view video,
.cam-view img,
.cam-view canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cam-view img {
  object-fit: contain;
}
.pill {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  margin: 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: 15px;
  white-space: nowrap;
  transition: background 0.2s;
}
.pill.ok {
  background: rgb(48 209 88 / 0.85);
  color: #000;
}
.cam-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 30px;
  text-align: center;
  color: var(--muted);
}
.cam-msg[hidden] {
  display: none;
}
.cam-msg b {
  color: var(--text);
  font-size: 19px;
}
.cam-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 112px;
  flex: none;
  padding: 0 18px;
}
.round {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 0;
  background: var(--panel);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.round[hidden] {
  display: none;
}
.shutter {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: #fff;
  box-shadow: inset 0 0 0 3px #000;
  cursor: pointer;
  transition: transform 0.1s;
}
.shutter:active {
  transform: scale(0.92);
}

/* top bar */
.top {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  height: 50px;
  flex: none;
  padding: 0 6px;
}
.top h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}
.icon {
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  font-size: 34px;
  line-height: 1;
  display: grid;
  place-items: center;
  color: var(--accent);
  cursor: pointer;
}
.msg {
  margin: 0 16px 8px;
  min-height: 1.35em;
  font-size: 15px;
  text-align: center;
  color: var(--muted);
  flex: none;
}
.msg.bad {
  color: var(--bad);
}
.msg.warn {
  color: var(--warn);
}

/* board: as large as fits, always square */
.board-wrap {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
  padding: 0 12px;
}
.board {
  --b: min(100cqw, 100cqh);
  width: var(--b);
  height: var(--b);
  display: grid;
  grid-template: repeat(9, 1fr) / repeat(9, 1fr);
  background: var(--paper) center / 100% 100% no-repeat;
  border: 3px solid var(--ink);
  border-radius: 4px;
  overflow: hidden;
  container-type: size;
}
.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid #b9b6ad;
  border-bottom: 1px solid #b9b6ad;
  color: var(--ink);
  font-size: 7.4cqw;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.cell:nth-child(9n) {
  border-right: 0;
}
.cell:nth-child(9n + 3),
.cell:nth-child(9n + 6) {
  border-right: 2px solid var(--ink);
}
.cell:nth-child(n + 73) {
  border-bottom: 0;
}
.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid var(--ink);
}
.cell.sol {
  color: var(--solved);
  font-weight: 400;
}
.cell.sel {
  background: rgb(10 132 255 / 0.28);
}
.cell.peer {
  background: rgb(10 132 255 / 0.08);
}
.cell.unsure {
  background: rgb(255 159 10 / 0.35);
}
.cell.conflict {
  background: rgb(255 69 58 / 0.4);
}

/* photo mode: the rectified photo is the paper, our digits are badges */
.board.photo {
  border-color: transparent;
}
.board.photo .cell {
  border-color: transparent;
}
.board.photo .cell.sol {
  color: #0057d9;
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  text-shadow:
    0 0 3px #fff,
    0 0 3px #fff;
}
.cell .badge {
  position: absolute;
  right: 4%;
  top: 2%;
  font-size: 3.6cqw;
  font-weight: 700;
  line-height: 1;
  padding: 2px 3px;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
}
.cell.unsure .badge {
  background: var(--warn);
  color: #000;
}
.cell.conflict .badge {
  background: var(--bad);
}

/* number pad */
.pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 12px 12px 0;
  flex: none;
}
.pad button {
  height: 48px;
  border: 0;
  border-radius: 10px;
  background: var(--panel);
  font-size: 23px;
  cursor: pointer;
}
.pad button:active,
.btn:active,
.round:active {
  filter: brightness(1.4);
}

.actions {
  display: flex;
  gap: 10px;
  padding: 12px;
  flex: none;
}
.btn {
  flex: 1;
  height: 50px;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary {
  background: var(--accent);
  color: #fff;
}

.busy {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 0.45);
}
.busy[hidden] {
  display: none;
}
.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid rgb(255 255 255 / 0.25);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* short landscape screens (phones turned sideways): pad beside the board */
@media (orientation: landscape) and (max-height: 560px) {
  #review,
  #solution {
    display: grid;
    grid-template: auto auto 1fr auto / 1fr minmax(240px, 40%);
  }
  #review[hidden],
  #solution[hidden] {
    display: none;
  }
  .top,
  .msg {
    grid-column: 1 / -1;
  }
  .board-wrap {
    grid-row: 3 / 5;
  }
  .pad,
  .actions {
    align-self: end;
  }
}

/* handwritten entries found in the photo */
.cell .badge.hand {
  background: #bf5af2;
}
.cell.wrong {
  background: rgb(255 69 58 / 0.3);
}
.cell.wrong .badge.hand {
  background: var(--bad);
  text-decoration: line-through;
}
.msg.good {
  color: #30d158;
}
