/* Common screen geometry follows game/public/nazotte-okaeri. */
:root {
  --font-ui: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  --font-round: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --ink: #1f3550;
  --ink-soft: #5a6f86;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: var(--font-ui);
  color: var(--ink);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { background: var(--paper, #edf5fc); -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button { font: inherit; cursor: pointer; border: 0; color: inherit; }
button:disabled { cursor: default; opacity: .42; }
button:focus-visible, a:focus-visible { outline: 3px solid #267da5; outline-offset: 4px; }
p, h1, h2 { margin: 0; }
[hidden] { display: none !important; }
.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  background: var(--paper);
}
.theme-paper { background: radial-gradient(circle, #b37f7420 1px, transparent 1.5px) 0 0 / 24px 24px, linear-gradient(160deg, #fff5e9, #f5dfd5); }
.theme-magnet { background: linear-gradient(#7ba6b710 1px, transparent 1px) 0 0 / 32px 32px, linear-gradient(90deg, #7ba6b710 1px, transparent 1px) 0 0 / 32px 32px, linear-gradient(160deg, #eff6ed, #dcedee); }
.theme-animals { background: repeating-linear-gradient(0deg, transparent 0 27px, #8aa4740a 27px 54px), repeating-linear-gradient(90deg, transparent 0 27px, #8aa4740a 27px 54px), linear-gradient(155deg, #f4f6e7, #e3edda); }
.theme-mosaic { background: radial-gradient(circle, #a989b218 1px, transparent 1.5px) 0 0 / 20px 20px, linear-gradient(150deg, #f9efed, #eee5f1); }
.topbar { position: absolute; inset: 0; z-index: 18; pointer-events: none; }
.round {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  pointer-events: auto;
}
.round svg, .pause-control svg { width: 24px; height: 24px; }
.home-link {
  top: calc(var(--safe-top) + 12px);
  left: calc(var(--safe-left) + 12px);
  border: 1px solid rgba(58, 47, 40, .15);
  background: rgba(255, 255, 255, .94);
  color: #514636;
  box-shadow: 0 3px 10px rgba(41, 57, 85, .12);
  text-decoration: none;
}
.help-toggle {
  right: calc(var(--safe-right) + 64px);
  background: rgba(20, 50, 80, .3);
  color: #fff;
  font: 900 22px var(--font-round);
}
.sound-toggle { right: calc(var(--safe-right) + 12px); background: rgba(20, 50, 80, .28); color: #fff; }
.sound-toggle .icon-off, .sound-toggle[aria-pressed="false"] .icon-on { display: none; }
.sound-toggle[aria-pressed="false"] .icon-off { display: block; }
.pause-control {
  position: absolute;
  right: calc(var(--safe-right) + 12px);
  bottom: calc(var(--safe-bottom) + 12px);
  z-index: 12;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #244565;
  color: #fff;
}
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(var(--safe-top) + 72px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 28px) calc(var(--safe-left) + 16px);
  text-align: center;
}
.screen > :not(.title-space, .result-space, .board-area) { flex-shrink: 0; }
.title-screen, .result-screen { overflow-y: auto; overscroll-behavior: contain; }
.title {
  font: 900 clamp(40px, 12.5vw, 64px)/1.08 var(--font-round);
  color: var(--accent);
  letter-spacing: .02em;
  text-shadow: 0 3px 0 #fff, 0 5px 0 rgba(80, 55, 40, .2), 0 8px 18px rgba(30, 45, 65, .16);
}
.title span { font-size: .62em; }
.title-space, .result-space {
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  margin: 12px 0;
  display: grid;
  place-items: center;
  container-type: size;
}
.demo, .result-art { width: min(74vw, 300px); aspect-ratio: 1; }
@supports (width: 1cqh) { .demo, .result-art { width: min(100cqw, 100cqh, 300px); } }
.demo { filter: drop-shadow(0 12px 12px #5c5b5717); transform: rotate(-3deg); }
.theme-stars .demo { transform: rotate(3deg); }
.theme-animals .demo { transform: rotate(-2deg); }
.demo svg, .board > svg, .result-art svg { display: block; width: 100%; height: 100%; }
.card {
  width: min(100%, 340px);
  margin-top: 14px;
  padding: 14px 18px;
  border-radius: 18px;
  background: rgba(255, 253, 247, .96);
  border: 1px solid #fff;
  box-shadow: 0 7px 20px rgba(65, 64, 49, .10);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.7;
}
.best { margin-top: 6px; color: var(--accent); }
.cta {
  display: block;
  flex-shrink: 0;
  max-width: 100%;
  min-height: 44px;
  margin: 16px auto 0;
  padding: 12px 30px;
  border-radius: 999px;
  background: #ffd84d;
  color: #5a3b00;
  box-shadow: 0 5px 0 #d9a300;
  font: 900 18px var(--font-round);
}
.cta:active, .btn-gold:active { transform: translateY(3px); box-shadow: 0 2px #d9a300; }
#continue-button:not([hidden]) + #start-button { margin-top: 12px; padding: 10px 24px; font-size: 16px; background: rgba(20, 50, 80, .42); color: #fff; box-shadow: none; }
.key-guide { margin-top: 10px; font-size: 12px; }
.more-games {
  align-self: center;
  margin-top: 10px;
  padding: 6px 10px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(255, 255, 255, .9);
  text-underline-offset: 3px;
}
.challenge { border: 2px solid #eaaa57; color: #955130; }
.hud { position: absolute; top: calc(var(--safe-top) + 8px); left: 0; right: 0; height: 96px; pointer-events: none; }
.hud-main { position: absolute; top: 0; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; }
.hud-score { font: 900 52px/1 var(--font-round); white-space: nowrap; font-variant-numeric: tabular-nums; text-shadow: 0 2px 0 rgba(255, 255, 255, .85); }
.hud-score strong { font: inherit; }
#level[data-digits="3"] { font-size: 34px; }
#level[data-digits="4"] { font-size: 24px; }
.hud-score { min-height: 52px; line-height: 52px; }
.hud-unit { margin-left: 2px; font-size: 20px; }
.hud-next { margin-top: 8px; padding: 3px 12px; border-radius: 999px; background: rgba(31, 53, 80, .72); color: #fff; font-size: 13px; font-weight: 800; }
.play-screen { padding-top: calc(var(--safe-top) + 112px); padding-bottom: calc(var(--safe-bottom) + 64px); }
.board-area { flex: 1 1 0; min-height: 0; width: min(100%, 420px); display: grid; place-items: center; container-type: size; }
.board { width: min(100%, calc(100svh - 360px)); aspect-ratio: 1; position: relative; touch-action: none; }
@supports (width: 1cqh) { .board { width: min(100cqw, 100cqh, 420px); } }
.board > svg { filter: drop-shadow(0 8px 9px #4f534a12); }
.board-hit { position: absolute; background: transparent; border-radius: 10px; padding: 0; min-width: 0; min-height: 0; }
.board-hit:hover:not(:disabled) { background: #ffffff25; }
.board-hit:active:not(:disabled) { background: #f9ce6733; }
.board-hit:focus-visible { outline: 3px solid #cf771b; outline-offset: -3px; }
.board-hit[aria-pressed=true] { box-shadow: inset 0 0 0 3px #cf771b; }
.theme-animals .board-hit[aria-pressed=true], .theme-stars .board-hit[aria-pressed=true] { box-shadow: none; }
.theme-stars .board-hit { border-radius: 50%; }
.board.preview > svg { opacity: .75; filter: drop-shadow(0 4px 6px #31445b33); }
.board-status { width: min(100%, 370px); min-height: 45px; margin: 10px 0 6px; font-size: 14px; font-weight: 700; line-height: 1.6; text-wrap: pretty; }
.board-status:focus { outline: none; }
.board-actions { display: flex; justify-content: center; gap: 10px; width: min(100%, 340px); }
.btn { min-height: 44px; padding: 12px 20px; border: 0; border-radius: 999px; background: #fff; font: 900 17px/1.3 var(--font-round); }
.btn-gold { background: #ffd84d; color: #5a3b00; box-shadow: 0 5px 0 #d9a300; }
.btn-sub { background: rgba(20, 50, 80, .42); color: #fff; }
.board-actions .btn { flex: 1; padding: 12px 8px; font-size: 15px; background: #fffcf4; border: 1px solid #697a8324; box-shadow: 0 3px 0 rgba(20, 50, 80, .12); }
.board-actions .btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(20, 50, 80, .12); }
.quiet { margin: 10px 0 0; color: var(--ink-soft); font-size: 12px; line-height: 1.7; }
.reference { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 4px; font-size: 13px; font-weight: 700; color: #6f6470; }
.reference svg { width: 84px; height: 84px; box-shadow: 0 3px 0 #c9bda7, 0 5px 10px #31445b12; border: 4px solid #fffaf0; border-radius: 6px; transform: rotate(2deg); }
.puzzle-controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; width: min(100%, 390px); margin-top: 6px; }
.puzzle-controls button { min-height: 48px; border: 1px solid #dbc2b7; border-radius: 14px; background: #fffaf0; font-size: 16px; font-weight: 800; color: #966173; box-shadow: 0 3px 0 #c8a89b; }
.puzzle-controls button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #c8a89b; }
.puzzle-controls button span { display: block; font-size: 12px; font-weight: 600; }
#extra { width: min(100%, 390px); }
.clues { display: grid; gap: 5px; list-style: none; padding: 0; margin: 0 0 8px; text-align: left; font-size: 14px; font-weight: 700; line-height: 1.5; }
.clues li { padding: 7px 12px; border: 1px solid #d6dfc8; border-radius: 14px; background: #fffdf2; box-shadow: 0 2px 0 #78906912; }
.clues li.met { color: #346a55; border-color: #b9d3bb; background: #e7f0dd; }
.clues li span { display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 4px; border-radius: 50%; background: #eeeadd; color: #6e775f; }
.clues li.met span { background: #698e70; color: white; }
.result-card { margin-top: 0; }
.result-label { color: var(--ink-soft); font-size: 14px; }
.result-score { color: var(--accent); font: 900 64px/1.1 var(--font-round); font-variant-numeric: tabular-nums; }
.result-unit { margin-left: 4px; font-size: 24px; white-space: nowrap; }
#result-score[data-digits="4"] { font-size: 48px; }
.result-detail { margin-top: 8px; color: var(--ink-soft); font-size: 13px; }
.result-art { animation: celebrate .6s ease-out; }
.result-actions { display: flex; flex-direction: column; align-items: stretch; gap: 10px; width: min(100%, 340px); margin-top: auto; }
.result-actions .more-games { margin-top: 0; }
.sheet {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 16px);
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: center;
}
.sheet[open] { display: flex; justify-content: center; align-items: center; }
.sheet::backdrop { background: rgba(14, 36, 60, .55); }
.help-panel { width: min(100%, 360px); max-height: 100%; overflow-y: auto; padding: 20px 18px 16px; border-radius: 22px; background: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.help-title { font: 900 21px var(--font-round); }
.help-steps { list-style: none; margin: 10px 0 0; padding: 0; counter-reset: step; text-align: left; }
.help-steps li { position: relative; margin-top: 10px; padding-left: 34px; font-size: 15px; font-weight: 700; line-height: 1.6; }
.help-steps li::before { counter-increment: step; content: counter(step); position: absolute; top: 1px; left: 0; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 900; }
.help-close { display: block; min-height: 44px; margin: 16px auto 0; padding: 10px 34px; border-radius: 999px; background: #ffd84d; color: #5a3b00; box-shadow: 0 4px #d9a300; font: 900 16px var(--font-round); }
.pause-screen::backdrop { background: rgba(16, 20, 52, .4); }
.pause-card { max-height: 100%; overflow-y: auto; margin: 0; }
.pause-card h2 { margin-bottom: 8px; font: 900 24px var(--font-round); }

/* Shared game share panel. Native dialog retains focus trapping. */
.share-panel {
  width: min(100%, 440px);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px;
  border: 1px solid #e5edf7;
  border-radius: 28px;
  background: #fff;
  color: #1d3b66;
  box-shadow: 0 18px 60px rgba(4, 24, 56, 0.28);
  text-align: left;
  overscroll-behavior: contain;
}

.share-panel::before {
  content: "";
  display: block;
  width: 36px;
  height: 4px;
  margin: -6px auto 20px;
  border-radius: 2px;
  background: #d9e3ef;
}

.share-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.share-heading-icon {
  display: grid;
  place-items: center;
  flex: 0 0 46px;
  height: 46px;
  border-radius: 15px;
  background: #e8f2ff;
  color: #286bce;
}

.share-heading-icon svg {
  width: 24px;
  height: 24px;
}

.share-title {
  font-family: var(--font-round);
  font-size: 20px;
  font-weight: 900;
  line-height: 1.4;
}

.share-subtitle {
  margin-top: 3px;
  color: #526984;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.share-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 72px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 18px;
  font-family: var(--font-ui);
  text-align: left;
  box-shadow: 0 3px 0 rgba(18, 43, 75, 0.08);
  transition: transform 140ms ease, box-shadow 140ms ease;
  cursor: pointer;
}

.share-option[data-share="x"] {
  background: #171c26;
  color: #fff;
}

.share-option[data-share="threads"] {
  border-color: #e1e6ee;
  background: #f2f4f8;
  color: #202b3a;
}

.share-option[data-share="line"] {
  background: #06c755;
  color: #062f1e;
}

.share-option[data-share="image"] {
  background: #2468c6;
  color: #fff;
}

.share-mark {
  display: grid;
  place-items: center;
  flex: 0 0 36px;
  height: 36px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.14);
  pointer-events: none;
}

.share-mark svg {
  width: 25px;
  height: 25px;
}

.share-option[data-share="threads"] .share-mark {
  background: #fff;
}

.share-option[data-share="line"] .share-mark svg {
  width: 32px;
  height: 32px;
}

.share-option-label {
  min-width: 0;
  pointer-events: none;
}

.share-option-name,
.share-option-action {
  display: block;
}

.share-option-name {
  font-size: 16px;
  font-weight: 900;
  line-height: 1.35;
}

.share-option-action {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

.share-option[data-share="x"] .share-option-action {
  color: #d2dbe9;
}

.share-option[data-share="threads"] .share-option-action {
  color: #536276;
}

.share-option:active {
  transform: scale(0.97);
  box-shadow: none;
}

@media (hover: hover) {
  .share-option:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(18, 43, 75, 0.12);
  }
}

.share-option[hidden] {
  display: none;
}

.share-wide {
  grid-column: 1 / -1;
}

.share-status {
  margin-top: 14px;
  font-size: 13px;
  font-weight: 700;
  color: #4a6a94;
  line-height: 1.6;
}

.share-status:empty {
  display: none;
}

.share-copy {
  width: 100%;
  margin-top: 6px;
  padding: 8px;
  border: 1px solid #d5deea;
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  user-select: text;
  -webkit-user-select: text;
}

.share-copy[hidden] {
  display: none;
}

.share-close {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  margin-top: 14px;
  padding: 10px 16px;
  border: 1px solid #dce5ef;
  border-radius: 14px;
  background: #f6f8fc;
  color: #46617f;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.share-close svg {
  width: 16px;
  height: 16px;
}

.share-option:focus-visible,
.share-close:focus-visible {
  outline: 3px solid #2d6cb5;
  outline-offset: 2px;
}

/* How to play: a round "?" button next to the sound one, and a sheet of short steps */
.sheet.share-sheet { padding: calc(var(--safe-top) + 20px) calc(var(--safe-right) + 12px) calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 12px); }
.sheet.share-sheet[open] { align-items: flex-end; }
.share-sheet::backdrop { background: rgba(5, 20, 45, .55); }
.theme-stars { background: radial-gradient(circle, #fffdf8 1.5px, transparent 2px) 15px 20px / 97px 109px, radial-gradient(circle, #928cad20 1px, transparent 1.5px) 43px 58px / 107px 89px, linear-gradient(#ebe7f3, #dde6ed); }
@keyframes celebrate { 0% { transform: scale(.85) rotate(-4deg); } 65% { transform: scale(1.05) rotate(2deg); } 100% { transform: none; } }
/* Keep the shared anchors while reserving room for the puzzle's own controls. */
@media (max-height: 680px) {
  .title-space { margin: 4px 0; }
  .title-screen .card { padding: 10px 18px; margin-top: 8px; font-size: 14px; }
  .title-screen .best { font-size: 12px; }
  .title-screen .key-guide { display: none; }
  .reference svg { width: 64px; height: 64px; }
  .board-status { min-height: 23px; margin-top: 6px; font-size: 12px; }
  .clues { gap: 3px; font-size: 12px; }
  .clues li { padding: 4px 10px; }
  .play-screen .quiet { margin-top: 6px; }
}
@media (max-height: 540px) and (min-width: 600px) {
  .play-screen { padding-left: max(16px, calc((100% - 780px) / 2)); padding-right: max(16px, calc((100% - 780px) / 2)); display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr auto auto auto; column-gap: 24px; }
  .board-area { grid-column: 1; grid-row: 1 / -1; width: 100%; height: 100%; }
  .play-screen > :not(.board-area, .hud, .pause-control) { grid-column: 2; width: 100%; }
  .title-space { margin: 4px 0; }
  .title-screen .card { padding: 8px 18px; margin-top: 8px; }
  .title-screen .best, .title-screen .key-guide { display: none; }
  .title-screen .cta { margin-top: 10px; }
  .result-space { margin: 4px 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
