:root {
  --paper: #fff7e7;
  --ink: #27363b;
  --mint: #a8dac5;
  --yellow: #f5c957;
  --blue: #8bc8e5;
  --orange: #f39a68;
  --coral: #ef7b67;
  --purple: #c4b6dc;
  --card: #fffdf4;
  --shadow: rgba(39, 54, 59, 0.18);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: ui-rounded, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

body {
  background:
    linear-gradient(90deg, rgba(39, 54, 59, 0.035) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(rgba(39, 54, 59, 0.035) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--paper);
}

button {
  appearance: none;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  touch-action: manipulation;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(39, 54, 59, 0.16);
}

button:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 rgba(39, 54, 59, 0.16);
}

button:disabled {
  opacity: 0.42;
  cursor: default;
}

.screen {
  width: 100%;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.view {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 16px);
}

.view.is-active {
  display: flex;
  flex-direction: column;
}

.home-view {
  gap: 14px;
}

.home-head,
.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.home-head {
  min-height: 32px;
  justify-content: flex-end;
}

.icon-btn,
.back-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
}

.back-btn {
  font-size: 34px;
  line-height: 1;
}

.hero {
  position: relative;
  min-height: 245px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 24px 22px;
  background: #ffeecb;
  box-shadow: 0 10px 0 var(--shadow);
  overflow: hidden;
}

.hero h1 {
  position: relative;
  margin: 8px 0 0;
  font-size: 62px;
  line-height: 0.98;
  letter-spacing: 0;
}

.hero p {
  position: relative;
  max-width: 12em;
  margin: 12px 0 0;
  font-size: 19px;
  font-weight: 800;
}

.hero-art {
  position: absolute;
  inset: 0;
}

.paper-grid {
  position: absolute;
  right: 18px;
  top: 32px;
  width: 190px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  transform: rotate(-5deg);
}

.paper-grid span {
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--mint);
  box-shadow: 0 4px 0 rgba(39, 54, 59, 0.12);
}

.paper-grid span:nth-child(3n) { background: var(--yellow); }
.paper-grid span:nth-child(4n) { background: var(--blue); }
.paper-grid span:nth-child(5n) { background: var(--orange); }

.mascot {
  position: absolute;
  right: 42px;
  bottom: 18px;
  width: 116px;
  height: 116px;
}

.mascot-ear {
  position: absolute;
  top: 2px;
  width: 35px;
  height: 38px;
  background: #c9794e;
  border: 2px solid var(--ink);
  border-radius: 9px;
}

.mascot-ear.left { left: 11px; transform: rotate(-15deg); }
.mascot-ear.right { right: 11px; transform: rotate(15deg); }

.mascot-face {
  position: absolute;
  inset: 20px 8px 4px;
  border: 3px solid var(--ink);
  border-radius: 28px;
  background: #d48a5a;
  box-shadow: 0 7px 0 rgba(39, 54, 59, 0.14);
}

.mascot-face::before {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  top: 32px;
  height: 28px;
  border-radius: 18px;
  background: #27363b;
}

.eye {
  position: absolute;
  z-index: 1;
  top: 40px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: white;
}

.eye.left { left: 36px; }
.eye.right { right: 36px; }

.nose {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 57px;
  width: 10px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink);
  transform: translateX(-50%);
}

.panel,
.daily-card,
.stats-row {
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 7px 0 rgba(39, 54, 59, 0.12);
}

.difficulty-panel {
  padding: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.segmented button {
  min-height: 44px;
  box-shadow: none;
}

.segmented button.is-active {
  background: var(--mint);
}

.primary-btn {
  width: 100%;
  min-height: 58px;
  background: var(--mint);
  font-size: 18px;
}

.daily-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 78px;
  padding: 12px 14px;
  text-align: left;
  background: #fff9dd;
}

.daily-card strong,
.daily-card small {
  display: block;
}

.daily-card strong {
  font-size: 19px;
}

.daily-card small {
  margin-top: 4px;
  opacity: 0.72;
}

.daily-card b {
  padding: 8px 10px;
  border: 2px dashed var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  white-space: nowrap;
}

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.1fr;
  gap: 8px;
  padding: 10px;
  align-items: stretch;
}

.stats-row div,
.stats-row button {
  min-height: 58px;
  display: grid;
  place-items: center;
  text-align: center;
}

.stats-row strong,
.stats-row span {
  display: block;
}

.stats-row span {
  font-size: 12px;
  opacity: 0.72;
}

.game-view {
  gap: 10px;
}

.game-head {
  flex: 0 0 auto;
  gap: 10px;
}

.game-head > div {
  min-width: 0;
  text-align: center;
}

.game-head strong,
.game-head span {
  display: block;
}

.game-head span {
  margin-top: 2px;
  font-size: 12px;
  opacity: 0.74;
}

.status-strip,
.tutorial-tip,
.context-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 38px;
  padding: 7px 10px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--card);
  font-weight: 800;
}

.tutorial-tip {
  background: #fff3b3;
}

.tutorial-tip button,
.context-bar button {
  min-height: 32px;
  padding: 0 10px;
  box-shadow: none;
}

.board-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  align-items: center;
}

.board-card {
  position: relative;
  width: min(100%, calc(100dvh - 248px));
  max-width: 488px;
  min-width: 288px;
  aspect-ratio: 1;
  margin: 0 auto;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fffdf4;
  padding: 8px;
  box-shadow: 0 10px 0 rgba(39, 54, 59, 0.14);
}

.board-svg {
  position: absolute;
  top: 8px;
  left: 8px;
  width: calc(100% - 16px);
  height: calc(100% - 16px);
  touch-action: none;
  user-select: none;
}

.grid-lines line {
  stroke: rgba(39, 54, 59, 0.2);
  stroke-width: 3;
  stroke-linecap: round;
}

.placed {
  transition: opacity 0.16s ease;
}

.placed.is-selected rect:first-child {
  stroke: #4d967e;
  stroke-dasharray: 12 8;
}

.placed.is-dim {
  opacity: 0.35;
}

.clue text,
.preview-text {
  fill: var(--ink);
  font: 800 42px ui-rounded, system-ui, sans-serif;
  pointer-events: none;
}

.preview-text {
  font-size: 34px;
  paint-order: stroke;
  stroke: #fffdf4;
  stroke-width: 8px;
}

.guide-box {
  animation: pulseGuide 1.2s infinite;
}

.board-mascot {
  position: absolute;
  z-index: 2;
  top: -4px;
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
  pointer-events: none;
}

.board-mascot span {
  display: block;
  padding: 5px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fffdf4;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 4px 0 rgba(39, 54, 59, 0.14);
}

.toolbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1.1fr 1fr 1.4fr 1fr;
  gap: 8px;
}

.toolbar button {
  position: relative;
  min-height: 58px;
  padding: 5px 2px 6px;
  font-size: 13px;
}

.toolbar span {
  display: block;
  font-size: 21px;
  line-height: 1;
}

.hint-btn {
  background: var(--yellow);
}

.hint-btn em {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--coral);
  color: white;
  font-size: 12px;
  font-style: normal;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  max-width: min(88vw, 420px);
  padding: 10px 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: white;
  font-weight: 800;
  opacity: 0;
  transform: translate(-50%, 18px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal {
  width: min(92vw, 430px);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 0;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 16px 0 rgba(39, 54, 59, 0.18);
}

.modal::backdrop {
  background: rgba(39, 54, 59, 0.42);
}

.modal form {
  position: relative;
  padding: 22px 16px 16px;
}

.modal h2 {
  margin: 0 42px 12px 0;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  padding: 0;
  box-shadow: none;
}

.finish-mark {
  display: inline-grid;
  grid-template-columns: repeat(3, auto);
  gap: 4px;
  margin-bottom: 12px;
  font-size: 30px;
  font-weight: 1000;
}

.finish-mark::first-letter {
  color: var(--coral);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .primary-btn {
  min-height: 46px;
}

.sheet label {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px dashed rgba(39, 54, 59, 0.25);
  font-weight: 800;
}

.sheet input {
  width: 22px;
  height: 22px;
  accent-color: var(--mint);
}

.sheet details {
  margin-top: 12px;
  line-height: 1.7;
}

#shareCanvas {
  display: block;
  width: 100%;
  height: auto;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
}

.share-note {
  margin-bottom: 0;
  font-size: 13px;
  line-height: 1.6;
  opacity: 0.76;
}

.footprints {
  display: grid;
  gap: 8px;
  max-height: 55dvh;
  overflow-y: auto;
}

.footprints button {
  min-height: 44px;
  text-align: left;
  padding: 0 12px;
  box-shadow: none;
}

.shake {
  animation: shake 0.24s ease;
}

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

@keyframes pulseGuide {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@media (max-height: 720px) {
  .hero {
    min-height: 188px;
    padding-top: 16px;
  }

  .hero h1 {
    font-size: 50px;
  }

  .paper-grid {
    width: 146px;
  }

  .mascot {
    transform: scale(0.78);
    transform-origin: right bottom;
  }

  .board-mascot {
    display: none;
  }

  .toolbar button {
    min-height: 52px;
  }
}

@media (max-width: 340px) {
  .view {
    padding-left: 10px;
    padding-right: 10px;
  }

  .hero h1 {
    font-size: 48px;
  }

  .stats-row {
    grid-template-columns: 1fr 1fr;
  }

  .stats-row button {
    grid-column: 1 / -1;
  }
}

body.reduce-motion * {
  animation-duration: 0.001ms !important;
  transition-duration: 0.001ms !important;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
