/* PITTARI — receipt-tape aesthetic.
   Palette: 紙 paper / 墨 ink / 判 stamp red / 罫 rule gray. Two-tone + red only. */

:root {
  --paper: #faf7f0;
  --ink: #211d15;
  --stamp: #d6402e;
  --rule: #cfc7b6;
  --faded: #8d8677;
  --tape: #ffffff;
  --tile: #ffffff;
  --tile-edge: #dcd5c6;
  --mono: 'Space Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #181410;
    --ink: #eae3d4;
    --stamp: #f0553f;
    --rule: #3e382f;
    --faded: #7d7668;
    --tape: #221d17;
    --tile: #26211a;
    --tile-edge: #3a342a;
  }
}

* { box-sizing: border-box; }

/* author display rules (grid/flex) must not defeat the hidden attribute */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app {
  width: 100%;
  max-width: 430px;
  padding: 0 16px 24px;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 14px 0 6px;
  border-bottom: 2px solid var(--ink);
}

.logo {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.18em;
  margin: 0;
}

.puzzle-no {
  font-family: var(--mono);
  color: var(--faded);
  font-size: 14px;
}

.top-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.icon-btn {
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1;
  background: none;
  border: 1.5px solid var(--rule);
  border-radius: 6px;
  color: var(--ink);
  width: 34px;
  height: 34px;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--ink); }

/* ---------- App Store ---------- */
.store-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 50px;
  margin: 12px 0 0;
  padding: 10px 16px;
  color: #fff;
  background: var(--stamp);
  border: 2px solid var(--stamp);
  border-radius: 10px;
  box-shadow: 3px 3px 0 var(--ink);
  text-decoration: none;
  transition: transform 0.12s, box-shadow 0.12s;
}

.store-banner:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ink);
}

.store-banner:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.store-banner-label {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
}

.store-banner-arrow {
  font-family: var(--mono);
  font-size: 20px;
  line-height: 1;
}

@media (prefers-color-scheme: dark) {
  .store-banner { color: #181410; }
}

/* ---------- target ---------- */
.target {
  text-align: center;
  padding: 14px 0 4px;
}

.target-label {
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--faded);
  text-transform: uppercase;
}

.target-num {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 56px;
  line-height: 1.1;
  letter-spacing: 0.06em;
}

.target-num.hit { color: var(--stamp); }

/* ---------- receipt tape ---------- */
.tape-wrap {
  background: var(--tape);
  border: 1px solid var(--tile-edge);
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  margin: 10px 0 14px;
  padding: 10px 14px 4px;
  min-height: 118px;
  position: relative;
}

.tape-wrap::after {
  content: '';
  display: block;
  height: 8px;
  margin: 6px -14px 0;
  background-image: radial-gradient(circle 4px at 8px 0, var(--paper) 97%, transparent);
  background-size: 16px 8px;
  background-repeat: repeat-x;
}

.tape-head {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--faded);
  border-bottom: 1px dashed var(--rule);
  padding-bottom: 5px;
  display: flex;
  justify-content: space-between;
}

.tape {
  list-style: none;
  margin: 0;
  padding: 4px 0 0;
  font-family: var(--mono);
  font-size: 17px;
}

.tape li {
  display: flex;
  align-items: baseline;
  padding: 3px 0;
  animation: print 0.22s ease-out;
}

.tape .expr { white-space: nowrap; }

.tape .leader {
  flex: 1;
  border-bottom: 2px dotted var(--rule);
  margin: 0 8px;
  transform: translateY(-4px);
}

.tape .result { font-weight: 700; }
.tape li.hit .result { color: var(--stamp); }

.tape-empty {
  color: var(--faded);
  font-family: var(--mono);
  font-size: 13px;
  padding: 12px 0;
  text-align: center;
}

@keyframes print {
  from { transform: translateY(-8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* red stamp on win */
.stamp {
  display: inline-block;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.24em;
  color: var(--stamp);
  border: 3px solid var(--stamp);
  border-radius: 4px;
  padding: 4px 10px 4px 14px;
  transform: rotate(-5deg);
  margin: 8px auto 6px;
  animation: thunk 0.32s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.stamp-row { text-align: center; }

@keyframes thunk {
  0% { transform: rotate(-5deg) scale(1.9); opacity: 0; }
  100% { transform: rotate(-5deg) scale(1); opacity: 1; }
}

/* ---------- tiles ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 2px 0 12px;
}

.tile {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 26px;
  color: var(--ink);
  background: var(--tile);
  border: 2px solid var(--tile-edge);
  border-radius: 10px;
  min-height: 64px;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s;
}

.tile:active { transform: scale(0.96); }

.tile.selected {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

.tile.shake { animation: shake 0.3s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ---------- celebration ---------- */
.celebration {
  text-align: center;
  padding: 22px 0 26px;
  animation: print 0.4s ease-out;
}

.celeb-title {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.14em;
  color: var(--stamp);
}

.celeb-title.perfect { font-size: 32px; }

.celeb-sub {
  margin-top: 10px;
  font-size: 15px;
  color: var(--ink);
}

.celeb-ops {
  margin-top: 8px;
  font-size: 18px;
  letter-spacing: 0.3em;
}

/* ---------- operators & actions ---------- */
.ops {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding-bottom: 12px;
}

.op {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 24px;
  background: none;
  color: var(--ink);
  border: 2px solid var(--rule);
  border-radius: 10px;
  min-height: 52px;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s;
}

.op:active { transform: scale(0.96); }

.op.selected {
  border-color: var(--stamp);
  color: var(--stamp);
  box-shadow: inset 0 0 0 1.5px var(--stamp);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.action-btn {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  background: none;
  color: var(--ink);
  border: 2px solid var(--rule);
  border-radius: 10px;
  min-height: 46px;
  cursor: pointer;
}
.action-btn:hover { border-color: var(--ink); }
.action-btn:disabled { opacity: 0.35; cursor: default; }
.action-btn:disabled:hover { border-color: var(--rule); }

.action-btn.primary {
  background: var(--stamp);
  border-color: var(--stamp);
  color: #fff;
}

a.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-sizing: border-box;
}

/* ---------- endless CTA gate ---------- */
.cta-panel {
  text-align: center;
  padding: 34px 4px 10px;
  animation: print 0.4s ease-out;
}

.cta-mark {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 40px;
  color: var(--stamp);
}

.cta-title {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.06em;
  margin: 12px 0 0;
}

.cta-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
  margin: 12px 0 22px;
}

/* ---------- footer ---------- */
.foot {
  margin-top: auto;
  padding-top: 18px;
  text-align: center;
  font-size: 11px;
  color: var(--faded);
}

.foot-links {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}

.foot a,
.foot button {
  appearance: none;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--faded);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  padding: 9px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 50;
}
.toast.show { opacity: 1; }

/* ---------- analytics consent ---------- */
.analytics-consent {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(calc(100vw - 24px), 406px);
  padding: 16px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: var(--tape);
  box-shadow: 4px 4px 0 var(--ink);
}

.analytics-consent p {
  margin: 0 0 7px;
  font-size: 13px;
  line-height: 1.6;
}

.analytics-consent > a {
  color: var(--stamp);
  font-size: 12px;
  text-underline-offset: 2px;
}

.analytics-consent-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.analytics-consent .action-btn {
  min-height: 42px;
  padding: 8px 10px;
  font-size: 13px;
}

/* ---------- modals ---------- */
dialog {
  border: none;
  border-radius: 14px;
  background: var(--tape);
  color: var(--ink);
  width: min(92vw, 380px);
  padding: 22px 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

dialog h2 {
  font-family: var(--mono);
  letter-spacing: 0.12em;
  font-size: 18px;
  margin: 0 0 12px;
}

dialog p { font-size: 14px; line-height: 1.7; margin: 8px 0; }

.rule-example {
  font-family: var(--mono);
  font-size: 14px;
  background: var(--paper);
  border: 1px dashed var(--rule);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.8;
}

.dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
}

/* result modal stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  text-align: center;
  margin: 14px 0;
}

.stat-num {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 26px;
}

.stat-label { font-size: 11px; color: var(--faded); }

.result-ops {
  text-align: center;
  font-size: 22px;
  letter-spacing: 0.2em;
  margin: 6px 0;
}

.countdown {
  text-align: center;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--faded);
  margin-top: 10px;
}

.share-btn {
  width: 100%;
  margin-top: 12px;
  min-height: 48px;
  font-size: 16px;
}

/* ---------- a11y ---------- */
:focus-visible {
  outline: 2.5px solid var(--stamp);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .tape li, .stamp, .tile.shake { animation: none; }
  * { transition: none !important; }
}

/* Crawlable introduction and rules, keeping the daily board compact. */
.logo { color: var(--ink); text-decoration: none; }
.language-link { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; width: auto; padding: 0 6px; font-size: 12px; text-decoration: none; }
.game-intro { padding-top: 14px; }
.game-intro h1 { margin: 0 0 6px; font-size: 19px; line-height: 1.4; letter-spacing: -.025em; }
.game-intro p { margin: 0 0 5px; font-size: 13px; line-height: 1.6; }
.game-intro a { color: var(--ink); font-size: 12px; text-underline-offset: 3px; }
.landing-info { border-top: 2px solid var(--ink); margin-top: 32px; padding-top: 12px; line-height: 1.8; font-size: 14px; }
.landing-info h2 { margin: 24px 0 8px; font-size: 19px; line-height: 1.5; }
.landing-info h3 { margin: 20px 0 6px; font-size: 16px; }
.landing-info p { margin: 8px 0 14px; }
.landing-info a { color: var(--ink); }
.landing-info .store-banner { color: #fff; }
.rules-list { padding-left: 1.5em; }
.rules-list li { margin-bottom: 10px; }
.landing-info .muted { font-size: 12px; }
.landing-info .rule-example { overflow-x: auto; font-size: 16px; line-height: 1.8; }
.landing-info details { border-bottom: 1px solid var(--rule); padding: 12px 0; }
.landing-info summary { font-weight: 600; cursor: pointer; line-height: 1.7; }
.back-to-puzzle { display: inline-block; padding: 8px 0; text-underline-offset: 4px; }
#how-to-play, #daily-puzzle { scroll-margin-top: 16px; }
:focus-visible { outline: 3px solid var(--stamp); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
