@charset "UTF-8";

:root {
  color-scheme: light;
  --bg: #f4f7f1;
  --panel: #fffdf7;
  --ink: #1f2a24;
  --muted: #66736b;
  --line: #d9e1d7;
  --leaf: #3f8f48;
  --leaf-dark: #2f7139;
  --wood: #8b5a37;
  --wall: #dfb56f;
  --roof: #bf5542;
  --stone: #8fa1a4;
  --sky: #bfe7ff;
  --grass: #6fbf62;
  --accent: #25766a;
  --accent-strong: #e36a3b;
  --danger: #d93f31;
  --shadow: 0 16px 32px rgba(39, 57, 47, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.96);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.support-controls,
.action-row,
.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.support-controls button[aria-pressed="true"] {
  border-color: rgba(37, 118, 106, 0.45);
  background: #e5f4ef;
  color: #15594f;
}

.game-layout {
  width: min(100%, 920px);
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 12px;
  padding: 12px 14px max(14px, env(safe-area-inset-bottom));
}

.world-panel,
.selector-panel,
.practice-panel {
  min-width: 0;
}

.world {
  position: relative;
  height: clamp(220px, 28vh, 300px);
  overflow: hidden;
  border: 1px solid #a7c8d8;
  border-radius: 8px;
  background:
    linear-gradient(#bfe7ff 0 58%, #9ed878 58% 100%);
  box-shadow: var(--shadow);
}

.sun {
  position: absolute;
  top: 8%;
  right: 10%;
  width: 48px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ffd35c;
  box-shadow: 0 0 0 10px rgba(255, 211, 92, 0.24);
}

.cloud {
  position: absolute;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  bottom: 0;
  border-radius: 50%;
  background: inherit;
}

.cloud::before {
  left: 14px;
  width: 30px;
  height: 30px;
}

.cloud::after {
  right: 12px;
  width: 36px;
  height: 36px;
}

.cloud-a {
  top: 16%;
  left: 9%;
  width: 96px;
}

.cloud-b {
  top: 28%;
  right: 22%;
  width: 72px;
  opacity: 0.72;
}

.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28%;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.18) 0 2px, transparent 2px 20px),
    linear-gradient(#75bf5e, #4f9d48);
}

.build-layer,
.particle-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.block {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: calc(var(--w) * 1%);
  height: calc(var(--h) * 1%);
  border: 2px solid rgba(31, 42, 36, 0.2);
  border-radius: 3px;
  background: var(--color);
  box-shadow:
    inset 0 3px rgba(255, 255, 255, 0.28),
    inset -3px -4px rgba(0, 0, 0, 0.12),
    0 6px 0 rgba(45, 67, 50, 0.12);
  animation: block-pop 220ms ease-out both;
}

.block.is-flag {
  border-radius: 2px;
  transform-origin: left center;
}

.block.is-flag::before {
  content: "";
  position: absolute;
  left: -5px;
  bottom: -18px;
  width: 4px;
  height: 28px;
  border-radius: 2px;
  background: #6e6258;
}

.block.is-collapsing {
  animation: block-collapse 520ms cubic-bezier(0.19, 1, 0.22, 1) var(--collapse-delay, 0ms) forwards;
  transform-origin: center bottom;
  z-index: 4;
}

.block.is-collapsing::before {
  animation: flag-collapse 520ms cubic-bezier(0.19, 1, 0.22, 1) var(--collapse-delay, 0ms) forwards;
  transform-origin: center bottom;
}

.world.is-booming {
  animation: boom-shake 360ms ease both;
}

.particle {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--color);
  animation: particle-burst 520ms ease-out forwards;
}

.stage-progress {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(34px, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.stage-chip {
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-weight: 800;
  font-size: 15px;
}

.stage-chip.is-current {
  border-color: var(--accent);
  background: #e5f4ef;
  color: #15594f;
}

.stage-chip.is-done {
  border-color: rgba(63, 143, 72, 0.45);
  background: #e9f7e5;
  color: #2f7139;
}

.practice-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.selector-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 10px 22px rgba(39, 57, 47, 0.08);
}

.selector-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.search-box {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.search-box input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  background: #fffdf7;
}

.selector-count {
  min-width: 76px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(37, 118, 106, 0.28);
  border-radius: 8px;
  color: #15594f;
  background: #e5f4ef;
  text-align: center;
  font-size: 13px;
  font-weight: 800;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 6px;
}

.tab {
  min-height: 38px;
  padding: 0 8px;
  font-size: 13px;
}

.tab.is-active {
  border-color: rgba(37, 118, 106, 0.45);
  background: #e5f4ef;
  color: #15594f;
}

.character-list {
  max-height: 170px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
  overflow: auto;
  padding: 2px;
}

.character-button {
  min-width: 0;
  min-height: 44px;
  padding: 0 6px;
  font-size: 22px;
  line-height: 1;
}

.character-button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.empty-list {
  grid-column: 1 / -1;
  margin: 0;
  padding: 12px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.status-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.status-box {
  min-width: 0;
  min-height: 62px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.status-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-box strong {
  font-size: 25px;
  line-height: 1;
}

.message {
  min-height: 32px;
  margin: 0;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 20px;
  font-weight: 800;
}

.message.is-error {
  color: var(--danger);
}

.character-meta {
  min-height: 20px;
  margin: -4px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.write-board {
  position: relative;
  width: min(100%, 500px);
  aspect-ratio: 1;
  justify-self: center;
  overflow: hidden;
  border: 2px solid #9f907f;
  border-radius: 8px;
  background:
    linear-gradient(to right, transparent calc(50% - 1px), #d8d0c2 calc(50% - 1px), #d8d0c2 calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to bottom, transparent calc(50% - 1px), #d8d0c2 calc(50% - 1px), #d8d0c2 calc(50% + 1px), transparent calc(50% + 1px)),
    #fffef9;
  touch-action: none;
}

.guide-svg,
.drawing-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.guide-svg {
  z-index: 1;
  pointer-events: none;
}

.drawing-canvas {
  z-index: 2;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.write-explosion {
  position: absolute;
  z-index: 3;
  height: auto;
  transform: translate(-50%, -50%);
  transform-origin: center;
  pointer-events: none;
  user-select: none;
  animation: write-explosion-pop 620ms ease-out forwards;
}

.guide-stroke {
  fill: none;
  stroke: rgba(31, 42, 36, 0.18);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.guide-stroke.is-done {
  stroke: rgba(37, 118, 106, 0.32);
}

.guide-stroke.is-animation-complete {
  stroke: rgba(37, 118, 106, 0.48);
}

.guide-stroke.is-current {
  stroke: var(--accent-strong);
  stroke-dasharray: 5 5;
  animation: guide-pulse 900ms ease-in-out infinite;
}

.guide-dot {
  fill: var(--accent-strong);
  stroke: #ffffff;
  stroke-width: 2;
}

.guide-end {
  fill: #25766a;
  stroke: #ffffff;
  stroke-width: 2;
}

.guide-animation-stroke {
  fill: none;
  stroke: var(--accent-strong);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.guide-animation-badge {
  fill: var(--accent);
  stroke: #ffffff;
  stroke-width: 1.5;
}

.guide-animation-number {
  fill: #ffffff;
  font-size: 7px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
}

.trace-help {
  margin: -2px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.action-row {
  justify-content: center;
  flex-wrap: wrap;
}

.action-row button {
  min-width: 132px;
}

#strokeAnimationButton {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

#strokeAnimationButton[aria-pressed="true"] {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

#skipSuccessButton {
  background: #f3f6f2;
  color: #59665f;
}

.app-credit {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px max(14px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 253, 247, 0.94);
  font-size: 11px;
  font-weight: 700;
}

.app-credit p {
  margin: 0;
}

.app-credit a {
  color: #15594f;
}

@keyframes block-pop {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.86);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes boom-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-8px);
  }
  42% {
    transform: translateX(7px);
  }
  64% {
    transform: translateX(-5px);
  }
  82% {
    transform: translateX(4px);
  }
}

@keyframes block-collapse {
  0% {
    opacity: 1;
    transform: translate(0, 0) rotate(0) scale(1);
  }
  34% {
    opacity: 1;
    transform: translate(var(--recoil-x), -10px) rotate(var(--recoil-rotate)) scale(1.03);
  }
  100% {
    opacity: 0.28;
    transform: translate(var(--fall-x), var(--fall-y)) rotate(var(--fall-rotate)) scale(0.82);
  }
}

@keyframes flag-collapse {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(22deg);
  }
}

@keyframes particle-burst {
  from {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(var(--tx), var(--ty)) rotate(160deg) scale(0.45);
  }
}

@keyframes write-explosion-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(-12deg) scale(0.15);
  }
  22% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(4deg) scale(1.15);
  }
  45% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0) scale(0.92);
  }
  72% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.08);
  }
}

@keyframes guide-pulse {
  0%,
  100% {
    stroke-width: 8;
    opacity: 0.82;
  }
  50% {
    stroke-width: 10;
    opacity: 1;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .support-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .game-layout {
    grid-template-rows: auto auto auto;
    padding-inline: 10px;
  }

  .world {
    height: clamp(200px, 28vh, 260px);
  }

  .status-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .selector-top {
    grid-template-columns: 1fr;
  }

  .selector-count {
    width: 100%;
  }

  .tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .status-box {
    min-height: 58px;
  }

  .status-box strong {
    font-size: 22px;
  }
}

/* LiNest v3: ゲーム世界と書字判定色は維持し、操作面を統一する。 */
body.linest-themed {
  --bg: var(--linest-bg);
  --panel: var(--linest-surface);
  --ink: var(--linest-text);
  --muted: var(--linest-muted);
  --line: var(--linest-border);
  --leaf: var(--linest-green);
  --leaf-dark: var(--linest-green-dark);
  --accent: var(--linest-green);
  --shadow: var(--linest-shadow);
}

body.linest-themed .topbar {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.96);
}

body.linest-themed :where(.selector-panel, .practice-panel, .status-box) {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed .status-box {
  box-shadow: 0 4px 14px rgba(74, 55, 40, 0.05);
}

body.linest-themed :where(button, .search-box input) {
  border-color: var(--linest-border);
  background-color: #ffffff;
  color: var(--linest-text);
}

body.linest-themed :where(.tab.is-active, .character-button.is-active) {
  border-color: var(--linest-green);
  background: var(--linest-green);
  color: #ffffff;
}

body.linest-themed .support-controls button[aria-pressed="true"] {
  border-color: var(--linest-green);
  background: var(--linest-green-soft);
  color: var(--linest-green-dark);
}

body.linest-themed :where(.selector-count, .stage-chip.is-current) {
  border-color: rgba(37, 120, 54, 0.35);
  background: var(--linest-green-soft);
  color: var(--linest-green-dark);
}

body.linest-themed .app-credit {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.94);
}

body.linest-themed .app-credit a {
  color: var(--linest-green-dark);
}

@media (max-width: 430px) {
  body.linest-themed .support-controls button,
  body.linest-themed .tab,
  body.linest-themed .action-row button {
    min-width: 0;
    padding-inline: 6px;
    white-space: normal;
    word-break: keep-all;
  }

  body.linest-themed .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body.linest-themed .action-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }
}
