/* Infinite Monkeys: a wood-paneled typing pool. */

:root {
  --wood: #3b2617;
  --wood-2: #4a3020;
  --wood-hi: #6a4630;
  --brass: #c9a24a;
  --brass-hi: #f1d892;
  --brass-lo: #8a6a24;
  --paper: #fbf7ec;
  --ink: #1f1a14;
  --mark: #ffe066;
  --cream: #f3ead2;
  --green: #2f4a3a;
  --type: 'Courier Prime', 'Courier New', monospace;
  --fell: 'IM Fell English', Georgia, serif;
  --fell-sc: 'IM Fell English SC', Georgia, serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--cream);
  font-family: var(--fell);
  /* Wood paneling */
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.18) 0 2px, transparent 2px 160px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 13px),
    linear-gradient(var(--wood-2), var(--wood) 60%, #2c1c10);
}

button,
.quit {
  font: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--brass-hi);
  outline-offset: 3px;
}

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

.skip-link {
  position: absolute;
  top: 8px;
  left: 16px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--brass-hi);
  color: var(--ink);
  text-decoration: none;
  transform: translateY(-200%);
}
.skip-link:focus {
  transform: none;
}

/* Sound and Quit, top right */
.corner {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 5;
  display: flex;
  gap: 8px;
}
.corner button,
.corner .quit,
.hunt button,
.hire button,
dialog .close {
  padding: 6px 12px;
  border: 0;
  border-radius: 4px;
  background: linear-gradient(var(--brass-hi), var(--brass) 55%, var(--brass-lo));
  color: var(--ink);
  font-family: var(--fell-sc);
  font-size: 16px;
  text-decoration: none;
  box-shadow: 0 2px 0 #4a3510, 0 3px 6px rgba(0, 0, 0, 0.35);
}
.corner button[aria-pressed='true'] {
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4), 0 0 0 2px var(--brass-hi);
}
.corner .quit {
  background: linear-gradient(#d9a08a, #a85a44 60%, #7a3a28);
  color: #fff7ef;
}

/* --- Header and plaque ---------------------------------------------------------- */

.top {
  padding: 22px 16px 10px;
  text-align: center;
}
h1 {
  margin: 0;
  font-family: var(--fell-sc);
  font-weight: 400;
  font-size: clamp(34px, 6vw, 58px);
  color: var(--brass-hi);
  text-shadow: 0 2px 0 #1a0f07, 0 0 24px rgba(201, 162, 74, 0.25);
}
.sub {
  margin: 4px auto 18px;
  max-width: 640px;
  font-size: 18px;
  font-style: italic;
  color: #e6d6b4;
}

.plaque {
  position: relative;
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 28px 16px;
  border-radius: 10px;
  color: #2a1d08;
  background:
    radial-gradient(ellipse at 30% 0%, rgba(255, 255, 255, 0.55), transparent 55%),
    linear-gradient(160deg, var(--brass-hi), var(--brass) 45%, #b08a35 70%, var(--brass-lo));
  box-shadow:
    inset 0 0 0 3px rgba(90, 64, 18, 0.55),
    inset 0 0 0 7px rgba(255, 240, 200, 0.35),
    0 8px 18px rgba(0, 0, 0, 0.45);
}
.plaque::before,
.plaque::after {
  /* screws */
  content: '';
  position: absolute;
  top: 12px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff2c4, #7a5a1a);
  box-shadow: inset 0 0 0 1px rgba(60, 40, 10, 0.6);
}
.plaque::before {
  left: 12px;
}
.plaque::after {
  right: 12px;
}
.plaque h2 {
  margin: 0;
  font-family: var(--fell-sc);
  font-weight: 400;
  font-size: 18px;
  letter-spacing: 0.06em;
}
.record-text {
  margin: 6px 0 2px;
  font-family: var(--type);
  font-weight: 700;
  font-size: clamp(26px, 5vw, 44px);
  line-height: 1.15;
  word-break: break-word;
}
.record-meta {
  margin: 0;
  font-size: 17px;
}
.record-context {
  margin: 6px 0 0;
  font-size: 15px;
  font-style: italic;
  color: #4a3510;
  min-height: 1.2em;
}
.record-context mark {
  background: rgba(255, 250, 220, 0.75);
  color: inherit;
  font-style: normal;
  font-weight: 700;
  padding: 0 2px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 26px;
  max-width: 980px;
  margin: 16px auto 0;
}
.stats div {
  min-width: 150px;
}
.stats dt {
  font-size: 14px;
  color: #d8c7a2;
}
.stats dd {
  margin: 2px 0 0;
  font-family: var(--type);
  font-weight: 700;
  font-size: 22px;
  color: var(--cream);
}

/* --- Layout -------------------------------------------------------------------------- */

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 22px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px 16px 40px;
}
.pool {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 12px;
  align-content: start;
}
.pool:focus {
  outline: none;
}

/* --- A desk -------------------------------------------------------------------------- */

.desk {
  position: relative;
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 9px 9px 11px;
  border-radius: 8px;
  background: linear-gradient(#5a3a24, #4a2f1d);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.08),
    0 6px 12px rgba(0, 0, 0, 0.35);
}
.paper {
  position: relative;
  z-index: 2;
  container-type: inline-size;
  width: 100%;
  min-height: 84px;
  margin: 0;
  padding: 6px 8px;
  border: 0;
  border-radius: 2px;
  background:
    linear-gradient(transparent 92%, rgba(0, 0, 0, 0.05)),
    var(--paper);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
  transform: rotate(-0.6deg);
  transition: transform 0.15s;
}
.paper:hover {
  transform: rotate(0deg) translateY(-2px);
}
.lines {
  display: block;
  font-family: var(--type);
  /* 30 monospace characters (0.6em each) exactly fill the paper */
  font-size: calc(100cqw / 18.4);
  line-height: 1.35;
  white-space: pre;
  overflow: hidden;
}
.line {
  display: block;
  min-height: 1.35em;
}
.lines mark {
  background: var(--mark);
  color: inherit;
  border-radius: 2px;
  box-shadow: 0 0 0 1px var(--mark);
}
.desk.eating .paper {
  animation: eaten 1.2s ease-in forwards;
}
@keyframes eaten {
  40% {
    transform: rotate(4deg) scale(0.9, 0.7);
  }
  100% {
    transform: translateY(80px) scale(0.1) rotate(20deg);
    opacity: 0;
  }
}

.monkey {
  width: 82%;
  margin-top: -10px;
}
.monkey-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.arm {
  transition: transform 0.05s;
}
.desk[data-tap='0'] .arm-l,
.desk[data-tap='1'] .arm-r {
  transform: translateY(4px);
}
.eye {
  transform-box: fill-box;
  transform-origin: center;
  animation: blink 4.2s infinite;
}
.desk:nth-child(3n) .eye {
  animation-delay: -1.7s;
}
.desk:nth-child(3n + 1) .eye {
  animation-delay: -3.1s;
}
@keyframes blink {
  0%,
  95%,
  100% {
    transform: scaleY(1);
  }
  97% {
    transform: scaleY(0.1);
  }
}
.mouth-o,
.held-banana {
  display: none;
}
.desk.fed .held-banana,
.desk.fed .mouth-o {
  display: inline;
}
.desk.fed .mouth {
  display: none;
}
.desk.cheer .head {
  animation: hop 0.5s ease-out 2;
}
@keyframes hop {
  50% {
    transform: translateY(-8px);
  }
}

.plate {
  margin-top: 6px;
  padding: 4px 12px 5px;
  border-radius: 4px;
  text-align: center;
  color: #2a1d08;
  background: linear-gradient(var(--brass-hi), var(--brass) 60%, var(--brass-lo));
  box-shadow: 0 2px 0 #3a280a;
  max-width: 100%;
}
.plate h3 {
  margin: 0;
  font-family: var(--fell-sc);
  font-weight: 400;
  font-size: 16px;
}
.best {
  margin: 0;
  font-family: var(--type);
  font-size: 11.5px;
  overflow-wrap: anywhere;
}
.banana {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 5px 12px 5px 8px;
  border: 0;
  border-radius: 20px;
  background: #f8e9b0;
  color: var(--ink);
  font-family: var(--fell);
  font-size: 15px;
  box-shadow: 0 2px 0 #8a6a1a;
}
.banana svg {
  width: 22px;
  height: 22px;
}
.banana:active {
  transform: translateY(2px);
  box-shadow: none;
}

/* --- Side cards ------------------------------------------------------------------------ */

.side {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.card {
  padding: 16px 18px;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.35);
}
.card h2 {
  margin: 0 0 8px;
  font-family: var(--fell-sc);
  font-weight: 400;
  font-size: 22px;
}
.hunt label {
  display: block;
  font-size: 15px;
  margin-bottom: 6px;
}
.hunt .row {
  display: flex;
  gap: 8px;
}
.hunt input {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid #b9a77f;
  border-radius: 4px;
  background: #fffdf6;
  font-family: var(--type);
  font-size: 16px;
}
#hunt-out {
  font-size: 15px;
  line-height: 1.45;
}
#hunt-out p {
  margin: 10px 0 0;
}
#hunt-out .big {
  font-family: var(--type);
  font-weight: 700;
}
#hunt-out .progress {
  font-family: var(--type);
  font-size: 15px;
  word-break: break-all;
}
#hunt-out .progress mark {
  background: var(--mark);
}
.fame ol {
  margin: 0;
  padding-left: 26px;
}
.fame li {
  margin: 8px 0;
  font-size: 14px;
  line-height: 1.35;
}
.fame li .frag {
  display: block;
  font-family: var(--type);
  font-weight: 700;
  font-size: 16px;
}
.fame li .who {
  color: #5a4a30;
  font-style: italic;
}
.fame .empty {
  list-style: none;
  margin-left: -26px;
  font-style: italic;
}
.fine {
  margin: 12px 0 0;
  font-size: 13px;
  color: #5a4a30;
}

/* --- Page dialog --------------------------------------------------------------------------- */

dialog {
  width: min(92vw, 720px);
  max-height: 88vh;
  padding: 22px 26px;
  border: 0;
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}
dialog::backdrop {
  background: rgba(20, 12, 6, 0.7);
}
dialog h2 {
  margin: 0;
  font-family: var(--fell-sc);
  font-weight: 400;
  font-size: 26px;
}
dialog h3 {
  margin: 18px 0 6px;
  font-family: var(--fell-sc);
  font-weight: 400;
  font-size: 19px;
}
.page-note {
  margin: 2px 0 12px;
  font-style: italic;
  color: #5a4a30;
}
.page-text {
  max-height: 42vh;
  overflow: auto;
  padding: 10px 12px;
  background: #fff;
  box-shadow: inset 0 0 0 1px #e0d6bd;
  font-family: var(--type);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}
.page-text mark {
  background: var(--mark);
  color: inherit;
}
.finds {
  margin: 0;
  padding-left: 20px;
  font-size: 15px;
  line-height: 1.5;
}
.finds b {
  font-family: var(--type);
}
.finds i {
  color: #5a4a30;
}
dialog .close {
  margin-top: 16px;
}

/* --- Small screens ------------------------------------------------------------------------- */

@media (max-width: 960px) {
  main {
    grid-template-columns: minmax(0, 1fr);
  }
}
@media (max-width: 520px) {
  .corner {
    position: static;
    justify-content: flex-end;
    padding: 10px 16px 0;
  }
  .top {
    padding-top: 6px;
  }
  .pool {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .desk {
    padding: 6px 5px 8px;
  }
  .paper {
    min-height: 56px;
    padding: 4px 5px;
  }
  .plate {
    padding: 3px 6px;
  }
  .plate h3 {
    font-size: 13px;
  }
  .best {
    font-size: 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .arm,
  .paper {
    transition: none;
  }
  .desk[data-tap] .arm-l,
  .desk[data-tap] .arm-r {
    transform: none;
  }
  .eye,
  .desk.cheer .head,
  .desk.eating .paper {
    animation: none;
  }
}

/* Narrow desks: the banana button keeps its label for screen readers only */
@container (max-width: 150px) {
  .banana span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .banana {
    padding: 4px 8px;
  }
}

.hire p {
  margin: 0 0 10px;
  font-size: 16px;
}
.hire .row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.hire button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.desk.new {
  animation: seated 0.6s ease-out;
}
@keyframes seated {
  from {
    transform: translateY(16px) scale(0.92);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .desk.new {
    animation: none;
  }
}

/* ---------- the proprietor's plate ---------- */

.proprietor {
  display: flex;
  justify-content: center;
  padding: 0 16px calc(28px + env(safe-area-inset-bottom));
}
.brass-plate {
  position: relative;
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 0 0.6em;
  padding: 8px 30px 7px;
  border-radius: 6px;
  color: #2a1d08;
  font-family: var(--fell-sc);
  font-size: 15px;
  letter-spacing: 0.06em;
  text-align: center;
  text-decoration: none;
  background:
    radial-gradient(ellipse at 30% 0%, rgba(255, 255, 255, 0.5), transparent 60%),
    linear-gradient(160deg, var(--brass-hi), var(--brass) 70%);
  box-shadow:
    inset 0 0 0 2px rgba(90, 64, 18, 0.55),
    inset 0 0 0 5px rgba(255, 240, 200, 0.3),
    0 4px 10px rgba(0, 0, 0, 0.45);
}
.brass-plate span {
  font-size: 12px;
}
.brass-plate::before,
.brass-plate::after {
  /* screws */
  content: '';
  position: absolute;
  top: 50%;
  left: 11px;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff2c4, #7a5a1a);
  box-shadow: inset 0 0 0 1px rgba(60, 40, 10, 0.6);
}
.brass-plate::after {
  left: auto;
  right: 11px;
}
.brass-plate:hover {
  text-decoration: underline;
}
.brass-plate:focus-visible {
  outline: 3px solid var(--mark);
  outline-offset: 3px;
}
