:root {
  --page: #d8c49f;
  --card: #d8bd72;
  --card-edge: #6f582c;
  --hole: #16100a;
  --ink: #111;
  --muted: #665232;
  --good: #248a3d;
  --bad: #9b2f24;
  --card-cell: clamp(24px, min(11.2vw, 7.6dvh), 62px);
  --card-gap: clamp(4px, 1vw, 8px);
  --card-pad: clamp(8px, 1.6vw, 14px);
  --card-width: calc((5 * var(--card-cell)) + (4 * var(--card-gap)) + (2 * var(--card-pad)));
  --mini-cell: clamp(6px, min(2.25vw, 1.75dvh), 12px);
  --mini-gap: 2px;
  --mini-pad: 4px;
  --mini-width: calc((5 * var(--mini-cell)) + (4 * var(--mini-gap)) + (2 * var(--mini-pad)));
  font-family: "Lucida Console", Monaco, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html {
  background: var(--page);
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: clamp(8px, 2vw, 24px);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
  background: #e6d4ae;
  color: #111;
  border: 1px solid #6f582c;
  border-radius: 5px;
}

button {
  min-height: clamp(34px, 5.7dvh, 42px);
  padding: 8px 12px;
  cursor: pointer;
  text-transform: uppercase;
}

button:hover:not(:disabled),
button:focus-visible,
input:focus-visible {
  background: #e6d4ae;
  color: #111;
}

button:focus-visible,
input:focus-visible {
  outline: 1px solid #6f582c;
  outline-offset: 0;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input {
  width: 13ch;
  min-height: clamp(34px, 5.7dvh, 42px);
  padding: 7px 9px;
  text-align: center;
  letter-spacing: 0.08em;
}

.app {
  width: min(100%, 980px);
  min-height: calc(100dvh - clamp(16px, 4vw, 48px));
  display: grid;
  grid-template-rows: auto minmax(0, auto) auto;
  align-content: center;
  gap: clamp(8px, 1.7dvh, 18px);
}

.top {
  display: grid;
  gap: clamp(8px, 1.6dvh, 14px);
  align-content: start;
  margin-top: clamp(6px, 2.2dvh, 46px);
}

.seed-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  text-transform: uppercase;
}

.seed-row label {
  color: #111;
}

.seed-entry {
  display: inline-flex;
  align-items: center;
  background: #e6d4ae;
  border: 1px solid #6f582c;
  border-radius: 5px;
  overflow: hidden;
}

.seed-random {
  min-height: clamp(34px, 5.7dvh, 42px);
  min-width: clamp(36px, 10vw, 44px);
  padding: 0 10px;
  border-right: 1px solid #6f582c;
  border-radius: 5px 0 0 5px;
  margin-right: 0;
  border-left: 0;
  border-top: 0;
  border-bottom: 0;
}

.seed-entry input {
  border: 0;
  border-radius: 0;
}

.seed-enter {
  min-height: clamp(34px, 5.7dvh, 42px);
  padding: 0 12px;
  border: 0;
  border-left: 1px solid #6f582c;
  border-radius: 0;
  min-width: clamp(36px, 10vw, 44px);
}

.objective {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  text-transform: uppercase;
  text-align: center;
}

.play {
  display: grid;
  place-items: center;
  align-content: center;
  gap: clamp(6px, 1.2dvh, 10px);
  min-height: 0;
}

.card-zone {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.submit-bar {
  min-height: clamp(34px, 5.8dvh, 46px);
}

.grid {
  --cell: var(--card-cell);
  display: grid;
  grid-template-columns: repeat(5, var(--cell));
  grid-template-rows: repeat(5, var(--cell));
  gap: var(--card-gap);
  padding: var(--card-pad);
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 8px;
}

.grid.small {
  --cell: clamp(8px, min(3vw, 2.5dvh), 15px);
  gap: 3px;
  padding: 5px;
  border-radius: 5px;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  border: 1px solid rgba(92, 67, 28, 0.35);
  border-radius: 50%;
  background: rgba(248, 222, 145, 0.48);
}

.cell.on {
  background: var(--hole);
  border-color: var(--hole);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.7);
}

.grid.input .cell {
  cursor: pointer;
}

.grid.input .cell:hover,
.grid.input .cell:focus-visible {
  background: rgba(248, 222, 145, 0.48);
  transform: none;
}

.grid.input .cell.on:hover {
  background: var(--hole);
}

.scan-wrap {
  position: relative;
}

.scan-wrap.scanning::after {
  content: "";
  position: absolute;
  inset: 8px;
  background: linear-gradient(90deg, transparent 0 32%, rgba(214, 24, 24, 0.82) 46%, transparent 60% 100%);
  animation: barcodeSweep 620ms ease-in-out forwards;
  pointer-events: none;
  border-radius: 7px;
}

@keyframes barcodeSweep {
  from {
    transform: translateX(-62%);
    opacity: 0.2;
  }

  20% {
    opacity: 1;
  }

  to {
    transform: translateX(62%);
    opacity: 0;
  }
}

.history {
  display: grid;
  gap: clamp(4px, 1dvh, 8px);
  align-content: start;
  justify-items: center;
  margin-top: 0;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(2, var(--history-slot));
  grid-template-rows: repeat(2, var(--history-row));
  gap: clamp(4px, 1vw, 8px);
  min-height: calc((2 * var(--history-row)) + clamp(4px, 1vw, 8px));
  justify-content: center;
  width: min(100%, var(--card-width));
  --history-slot: calc((var(--card-width) - clamp(4px, 1vw, 8px)) / 2);
  --history-row: calc(var(--mini-width) + 10px);
}

.attempt {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(3px, 0.9vw, 6px);
  min-width: 0;
  min-height: var(--history-row);
}

.attempt.empty {
  opacity: 0;
}

.attempt.success .grid:last-child .cell.on {
  background: var(--good);
  border-color: var(--good);
}

.attempt.success .grid:last-child {
  animation: successRight 1200ms ease forwards;
}

@keyframes successRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }

  to {
    transform: translateX(54px);
    opacity: 0;
  }
}

.attempt .grid.small {
  --cell: var(--mini-cell);
  gap: var(--mini-gap);
  padding: var(--mini-pad);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: clamp(5px, 1.4vw, 8px);
  width: min(100%, var(--card-width));
}

.message {
  min-height: 0;
  height: 0;
  overflow: hidden;
  color: #111;
  text-align: center;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--page);
  padding: clamp(14px, 3vw, 28px);
  z-index: 20;
}

.modal-card {
  width: min(100%, var(--card-width));
  min-height: min(100%, 720px);
  background: var(--page);
  border: 0;
  border-radius: 0;
  padding: 20px;
  display: grid;
  gap: 18px;
  align-content: center;
  text-align: center;
  box-shadow: none;
}

.serial {
  line-height: 1.55;
  color: #111;
}

@media (max-width: 720px) {
  :root {
    --card-cell: min(11vw, 7.2dvh);
    --card-gap: min(1.2vw, 5px);
    --card-pad: min(2vw, 8px);
    --mini-cell: min(1.8vw, 1.45dvh);
  }

  body {
    padding: 6px;
    font-size: clamp(10px, 2.8vw, 14px);
  }

  .app {
    min-height: calc(100dvh - 12px);
    gap: clamp(6px, 1.15dvh, 10px);
  }

  .top {
    margin-top: 0;
  }

  .seed-row,
  .objective {
    gap: 7px;
  }

  .seed-row label {
    width: 100%;
    text-align: center;
  }

  .seed-entry {
    max-width: 100%;
  }

  .seed-entry input {
    width: min(13ch, 48vw);
  }

  .objective {
    line-height: 1.25;
  }

  .button-row button {
    padding: 6px 4px;
    min-width: 0;
    font-size: clamp(9px, 2.55vw, 12px);
  }

  .modal {
    padding: 8px;
  }

  .modal-card {
    padding: 12px 0;
    gap: 12px;
  }
}

@media (max-height: 660px) {
  :root {
    --card-cell: min(10.2vw, 6.4dvh);
    --card-gap: 4px;
    --card-pad: 6px;
    --mini-cell: min(1.45vw, 1.15dvh);
  }

  body {
    padding-top: 4px;
    padding-bottom: 4px;
    font-size: 11px;
  }

  .app {
    min-height: calc(100dvh - 8px);
    gap: 5px;
  }

  .top {
    gap: 6px;
  }

  .play {
    gap: 5px;
  }

  button,
  input,
  .seed-random,
  .seed-enter,
  .submit-bar {
    min-height: 32px;
  }

  .history-list {
    --history-row: calc(var(--mini-width) + 6px);
  }

  .modal-card {
    gap: 10px;
  }
}
