@font-face {
  font-family: "Sagyo Brush";
  src: url("./yuji-boku.woff2") format("woff2");
  font-display: swap;
}

:root {
  color-scheme: light;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", Meiryo, sans-serif;
  color: #282723;
  background: #f4f0e5;
  --surface: #f4f0e5;
  --ink: #282723;
  --quiet: #bcb7a9;
  --red: #d94324;
  --mark-size: clamp(60px, 13vw, 92px);
  --panel-height: 430px;
  --cell-size: clamp(32px, 10.5vw, 56px);
  -webkit-text-size-adjust: 100%;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { overflow: hidden; overscroll-behavior: none; touch-action: manipulation; }
body { margin: 0; }
button { color: inherit; font: inherit; touch-action: manipulation; }
button:focus-visible { outline: 2px solid var(--red); outline-offset: 4px; }
[hidden] { display: none !important; }

.console {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(100%, 700px);
  height: min(100svh, 740px);
  height: min(100dvh, 740px);
  margin-inline: auto;
  padding: max(10px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
    calc(max(20px, env(safe-area-inset-bottom)) + var(--cell-size) * 1.25) max(18px, env(safe-area-inset-left));
}

.masthead { position: relative; border-bottom: 2px solid var(--ink); }
.masthead::before {
  position: absolute;
  inset: 0 auto auto 8px;
  width: 28px;
  height: 22px;
  background: var(--red);
  transform: skewX(-39deg);
  content: "";
}

.tools { display: flex; justify-content: end; align-items: center; gap: 5px; min-height: 42px; }
.icon-button, .mode-toggle {
  display: inline-grid;
  place-items: center;
  min-width: 42px;
  min-height: 42px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-button:active { background: #2827230d; }
.tools svg, .icon-button svg {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mode-toggle {
  width: 52px;
  min-height: 32px;
  border-radius: 0;
  background: #000;
  color: #fff;
  font-family: Arial, "Helvetica Neue", sans-serif;
  font-size: 17px;
  font-weight: 800;
}
.book-toggle.is-earned { color: var(--red); }
.results-toggle { color: #9a6818; font-size: 24px; }

.heading { padding: 7px 0 17px; }
.heading h1 {
  margin: 0;
  font-size: clamp(38px, 8.8vw, 66px);
  font-weight: 900;
  line-height: 1.11;
  letter-spacing: -.065em;
}
.heading p {
  margin: 6px 0 0;
  font-size: clamp(16px, 4vw, 25px);
  font-weight: 800;
  line-height: 1.4;
  letter-spacing: -.025em;
}

.play-area {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  max-height: var(--panel-height);
  margin-top: clamp(13px, 2.7svh, 24px);
  touch-action: none;
  user-select: none;
}
.guides { position: absolute; inset: 0; pointer-events: none; }
.guide { position: absolute; border: 1px solid #c8c1b2; border-radius: 13px; }
.guide-outer { inset: 11% 7%; }
.guide-inner { inset: 22% 17%; }
.tick { position: absolute; display: block; background: var(--ink); }
.tick-top, .tick-bottom { left: calc(50% - .5px); width: 1px; height: 10px; }
.tick-top { top: 5%; }
.tick-bottom { bottom: 5%; }
.tick-left, .tick-right { top: calc(50% - .5px); width: 10px; height: 1px; }
.tick-left { left: 3.5%; }
.tick-right { right: 3.5%; }

.marker {
  --marker-hit-padding: 18px;
  position: relative;
  display: block;
  width: calc(var(--mark-size) + 2 * var(--marker-hit-padding));
  height: calc(var(--mark-size) + 2 * var(--marker-hit-padding));
  padding: 0;
  border: 0;
  border-radius: 14%;
  background: transparent;
  touch-action: none;
  cursor: grab;
  -webkit-tap-highlight-color: transparent;
}
.marker:active { cursor: grabbing; }
.marker-face {
  position: absolute;
  inset: var(--marker-hit-padding);
  display: grid;
  place-items: center;
  border: 1px solid #bb351a;
  border-radius: inherit;
  background: #db4725;
  box-shadow: inset 0 1px 0 #fb724c, 0 4px 0 #9d2b17, 0 8px 12px #3f21142b;
  pointer-events: none;
  will-change: transform, opacity;
}
.marker-face::after {
  width: 63%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #cf3d1f;
  box-shadow: inset 0 2px 3px #8c271b65, 0 1px #ef6944;
  content: "";
}
.play-area.is-targeting .marker-face { outline: 2px solid #d9432470; outline-offset: 5px; }
.marker.is-flying .marker-face { opacity: .35; }
.flight-layer {
  position: fixed;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}
.flying-face { inset: auto; border-radius: 14%; }
.mask-flight { --ejected-ink: #595247; position: absolute; background: var(--ink); pointer-events: none; }
.mask-crumble { background: transparent; }
.mask-shard { position: absolute; inset: 0; background: var(--ink); }
.mask-crumble.is-ejected .mask-shard { background: var(--ejected-ink); }

.response {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
}
.ink-message {
  max-width: 11em;
  color: var(--ink);
  font-family: "Sagyo Brush", "Yu Mincho", serif;
  font-size: clamp(32px, 8.6vw, 82px);
  line-height: 1.35;
  text-align: center;
  text-wrap: balance;
  text-shadow: 0 0 5px var(--surface), 0 0 14px var(--surface), 0 0 24px var(--surface);
}
.input-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  min-height: calc(var(--cell-size) + 25px);
  margin-top: clamp(12px, 4svh, 32px);
  border-block: 2px solid var(--ink);
  padding: 11px 0;
}
.cells {
  --cell-gap: clamp(6px, 2vw, 12px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--cell-gap);
  min-height: calc(var(--cell-size) + 8px);
  padding: 4px 8px;
}
.cell {
  flex: none;
  width: min(var(--cell-size), calc((100% - 3 * var(--cell-gap)) / 4));
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 0;
  background: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.cell[aria-pressed="true"] { outline: 2px solid var(--red); outline-offset: 2px; }
.empty-cell, .cell.is-arriving { background: #fff; border-color: var(--quiet); }
.confirm {
  min-width: 44px;
  min-height: 36px;
  margin-right: 5px;
  padding: 0 7px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.confirm:disabled { opacity: .36; cursor: default; }
.undo { min-height: 36px; margin-right: 3px; font: 700 23px/1 Arial, sans-serif; }
.undo:disabled { opacity: .32; cursor: default; }
.input-row.is-correct .cell:not(.empty-cell) { outline: 2px solid #287047; outline-offset: 2px; }
.judge-status {
  position: absolute;
  right: 0;
  bottom: calc(100% + 5px);
  min-height: 20px;
  color: #287047;
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
}
.judge-status:empty { display: none; }
.judge-status.is-unmatched { color: #6d6252; }
.input-row.is-correct .judge-status { animation: correct-in .28s ease-out both; }
@keyframes correct-in {
  from { opacity: 0; transform: translateY(4px) scale(.85); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .input-row.is-correct .judge-status { animation: none; }
}
.reset {
  width: clamp(44px, 12vw, 64px);
  height: var(--cell-size);
  min-height: 36px;
  border-left: 1px solid var(--quiet);
  border-radius: 0;
}
.reset svg { width: 27px; height: 27px; stroke-width: 2.4; }
.reset:disabled { opacity: .32; cursor: default; }

.dialog {
  width: min(calc(100% - 34px), 570px);
  max-height: calc(100svh - 30px);
  padding: 0;
  border: 2px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 14px 36px #28272326;
}
.dialog::backdrop { background: #28272365; }
.dialog-body { padding: 15px clamp(12px, 4vw, 25px) 21px; }
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--ink);
}
.dialog h2 { margin: 0; font-size: clamp(22px, 5vw, 30px); font-weight: 900; letter-spacing: -.035em; }
.close { margin-right: -6px; }
.items {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.item {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid var(--quiet);
  background: #faf6eb;
}
.stamp {
  display: block;
  width: 86%;
  height: 86%;
  background: url("./illustrations.png") var(--sprite-x) center / 493.636% auto no-repeat;
  filter: grayscale(1);
  opacity: .61;
}
/* Each stamp frames one illustration within a 440px square of the original sprite. */
[data-art="watering-can"] { --sprite-x: 1.73%; }
[data-art="rabbit"] { --sprite-x: 26.27%; }
[data-art="coral"] { --sprite-x: 49.94%; }
[data-art="santa"] { --sprite-x: 73.90%; }
[data-art="geta"] { --sprite-x: 98.27%; }
.item[data-found] { border-color: #b95331; }
.item[data-found] .stamp { filter: none; opacity: 1; }
.item-star {
  position: absolute;
  top: 1px;
  right: 3px;
  color: #bc3c21;
  font-size: clamp(17px, 4.6vw, 25px);
  line-height: 1.15;
}
.clear { width: min(calc(100% - 34px), 365px); text-align: center; }
.clear .dialog-body { padding: 27px 20px 22px; }
.clear h2 { margin-bottom: 19px; }
.discovery {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin: 0;
  padding: 12px 18px;
  border: 1px solid var(--quiet);
  background: var(--surface);
  text-align: center;
  font-size: clamp(16px, 4.4vw, 22px);
  font-weight: 800;
}
.discovery .stamp {
  width: clamp(64px, min(32vw, 27svh), 152px);
  height: auto;
  aspect-ratio: 1;
  filter: none;
  opacity: 1;
}
.response .discovery { animation: discovery-in .23s ease-out both; }
@keyframes discovery-in {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to { opacity: 1; transform: none; }
}
.result-extra:not(:empty) { margin: 0 auto 16px; }
.result-nav {
  display: grid;
  grid-template-columns: auto minmax(52px, auto) auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: -4px 0 12px;
}
.result-nav .icon-button { border: 1px solid var(--quiet); font-size: 20px; }
.result-nav .icon-button:disabled { opacity: .36; cursor: default; }
.result-nav output { font-size: 13px; font-variant-numeric: tabular-nums; }
.result-ink {
  display: block;
  margin-inline: auto;
  font-size: clamp(25px, 6.2vw, 42px);
}
@media (prefers-reduced-motion: reduce) {
  .response .discovery { animation: none; }
}
.continue {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  padding: 5px 24px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--ink);
  color: var(--surface);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}
.share { background: #101010; color: #fff; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.menu { width: min(calc(100% - 28px), 410px); }
.menu .close { font-size: 26px; line-height: 1; }
.settings-sound { display: flex; align-items: center; gap: 10px; padding: 2px 0 13px; font-size: .9rem; }
.settings-sound button, .connection-error button {
  min-height: 36px;
  padding: 3px 10px;
  border: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
}
.settings-sound button[aria-pressed="true"] { color: #fff; background: var(--ink); }
.settings-sound input { min-width: 0; flex: 1; accent-color: var(--red); }
.settings-sound input:disabled { opacity: .48; }
.menu-link {
  display: block;
  width: 100%;
  padding: 11px 0;
  border: 0;
  border-top: 1px solid var(--quiet);
  background: transparent;
  color: inherit;
  font-weight: 700;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu-link small { display: block; margin-top: 4px; font-size: .76rem; font-weight: 400; }
.menu-note { margin: 4px 0 0; color: #5d594f; font-size: .76rem; line-height: 1.5; }
#record-output dl { display: grid; grid-template-columns: 1fr auto; gap: 7px 16px; }
#record-output dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 700; }
.connection-error {
  position: fixed;
  z-index: 4;
  bottom: max(8px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: calc(100% - 16px);
  padding: 4px 8px;
  border: 1px solid var(--quiet);
  background: var(--surface);
  font-size: .78rem;
}

@media (max-width: 460px) {
  .items { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cells { --cell-gap: 6px; padding-inline: 5px; }
  .undo, .reset { min-width: 36px; width: 36px; }
}
@media (max-height: 600px) {
  :root { --panel-height: 300px; }
  .heading { padding-block: 3px 12px; }
  .heading h1 { font-size: clamp(33px, 7.8vw, 53px); }
}
@media (max-height: 420px) {
  :root { --mark-size: 50px; --cell-size: 32px; }
  .console { padding-block: max(4px, env(safe-area-inset-top))
    calc(max(10px, env(safe-area-inset-bottom)) + var(--cell-size) * 1.25); }
  .heading { padding-block: 0 6px; }
  .heading h1 { font-size: 30px; }
  .heading p { margin-top: 2px; font-size: 14px; }
  .play-area { margin-top: 4px; }
  .input-row { margin-top: 5px; padding-block: 4px; min-height: 0; }
}
