:root {
  --ink: #23190f;
  --paper: #fff8e7;
  --orange: #f28c18;
  --deep-orange: #d94b16;
  --leaf: #2f8c4c;
  --sea: #1c8fc9;
  --night: #182437;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.72), transparent 20rem),
    linear-gradient(135deg, #ffe39a 0%, #f7a94b 44%, #6dc9d8 100%);
  color: var(--ink);
  font-family:
    "Hiragino Maru Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

.game-shell {
  min-height: 100svh;
  width: 100%;
  display: grid;
  justify-items: center;
  align-items: stretch;
  padding: 12px max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-bottom));
}

/* 盤面が残り高さを吸うので、端末の高さが変わっても縦スクロールが出ない。 */
.game-card {
  width: min(100%, 430px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-card > *:not(.playfield) {
  flex: 0 0 auto;
}

.title-bar {
  display: grid;
  gap: 3px;
  text-align: center;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.78);
}

.kicker,
.panel-label {
  margin: 0;
  color: #75450e;
  font-size: 12px;
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  /* 390px 幅でも1行に収まるサイズ。折り返すと盤面の高さを 35px 前後奪う。 */
  font-size: clamp(19px, 5.8vw, 32px);
  line-height: 1.08;
  font-weight: 1000;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.hud > div,
.message-row,
.citrus-board > div {
  border: 2px solid rgba(72, 41, 9, 0.18);
  background: rgba(255, 250, 229, 0.92);
  box-shadow: 0 5px 0 rgba(83, 47, 12, 0.14);
}

.hud > div {
  min-width: 0;
  min-height: 54px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  padding: 6px 3px;
}

.hud span {
  color: #7b561b;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.hud strong {
  max-width: 100%;
  font-size: clamp(16px, 5vw, 22px);
  line-height: 1.05;
  overflow-wrap: anywhere;
  transition: color 0.15s ease;
}

.hud > div.urgent {
  border-color: rgba(217, 75, 22, 0.55);
  animation: urgent-pulse 1s ease-in-out infinite;
}

.hud > div.urgent strong {
  color: var(--deep-orange);
}

.fever-bar {
  position: relative;
  height: 22px;
  overflow: hidden;
  border: 2px solid rgba(72, 41, 9, 0.18);
  border-radius: 999px;
  background: rgba(255, 250, 229, 0.92);
  box-shadow: 0 4px 0 rgba(83, 47, 12, 0.14);
}

.fever-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffe27a 0%, #ffca3a 45%, #f47d18 100%);
  transition: width 0.18s ease-out;
}

.fever-bar > span {
  position: relative;
  display: grid;
  place-items: center;
  height: 100%;
  color: #6f4b18;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.fever-bar.active {
  border-color: rgba(217, 75, 22, 0.6);
  animation: fever-pulse 0.6s ease-in-out infinite alternate;
}

.fever-bar.active > span {
  color: #fff7dd;
}

.playfield {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 320px;
  max-height: 680px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  border: 4px solid #fff6da;
  border-radius: 8px;
  background:
    linear-gradient(to bottom, rgba(255, 255, 255, 0.06), rgba(36, 25, 8, 0.08)),
    url("/assets/ehime-terraces.png") center / cover;
  box-shadow:
    0 14px 0 rgba(87, 51, 15, 0.18),
    0 22px 34px rgba(53, 27, 5, 0.26);
}

.field-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, rgba(255, 255, 255, 0.12) 0 38%, transparent 58%),
    linear-gradient(to top, rgba(32, 20, 8, 0.22), transparent 34%);
  pointer-events: none;
}

.catch-line {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 19%;
  height: 2px;
  border-radius: 999px;
  background: repeating-linear-gradient(
    to right,
    rgba(255, 255, 255, 0.7) 0 12px,
    transparent 12px 22px
  );
  opacity: 0.72;
}

.playfield.fever {
  border-color: #ffd97a;
  box-shadow:
    0 0 0 3px rgba(255, 196, 74, 0.7),
    0 14px 0 rgba(87, 51, 15, 0.18),
    0 22px 40px rgba(224, 122, 20, 0.42);
}

.playfield.fever .field-shade {
  background:
    linear-gradient(to bottom, rgba(255, 214, 120, 0.26), rgba(255, 138, 30, 0.18)),
    linear-gradient(to top, rgba(32, 20, 8, 0.22), transparent 34%);
}

.playfield.shake {
  animation: shake 0.4s ease-out;
}

.player {
  position: absolute;
  bottom: 3%;
  width: 34%;
  max-width: 158px;
  transform: translateX(-50%) rotate(var(--lean, 0deg));
  transform-origin: 50% 90%;
  filter: drop-shadow(0 12px 10px rgba(34, 18, 4, 0.38));
  z-index: 4;
  pointer-events: none;
}

.player.catching {
  animation: catch-squash 0.24s ease-out;
}

.pause-button {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 6;
  width: 40px;
  height: 40px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  background: rgba(32, 18, 5, 0.44);
  color: #fff7dd;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.pause-button[hidden] {
  display: none;
}

.effects-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow: hidden;
  pointer-events: none;
}

.pop {
  position: absolute;
  transform: translate(-50%, -50%);
  color: #fff7dd;
  font-size: clamp(13px, 4vw, 18px);
  font-weight: 1000;
  white-space: nowrap;
  text-shadow:
    0 2px 0 rgba(120, 52, 6, 0.9),
    0 0 10px rgba(255, 168, 60, 0.7);
  animation: pop-rise 0.9s ease-out forwards;
}

.pop-rare {
  color: #ffe9a8;
  font-size: clamp(15px, 5vw, 22px);
}

.burst {
  position: absolute;
  width: 0;
  height: 0;
}

.burst i {
  position: absolute;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 999px;
  background: #ffc247;
  animation: burst-out 0.6s ease-out forwards;
}

.flash {
  position: absolute;
  inset: 0;
  animation: flash-fade 0.55s ease-out forwards;
}

.flash-bad {
  background: radial-gradient(circle at 50% 70%, rgba(217, 45, 22, 0.45), transparent 62%);
}

.flash-fever {
  background: radial-gradient(circle at 50% 60%, rgba(255, 214, 106, 0.75), transparent 68%);
}

.falling {
  position: absolute;
  aspect-ratio: 1;
  z-index: 3;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #4b2207;
  font-size: clamp(8px, 2.7vw, 14px);
  font-weight: 1000;
  line-height: 1;
  text-align: center;
  filter: drop-shadow(0 7px 6px rgba(45, 21, 4, 0.3));
  will-change: top, left, transform;
}

.falling span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding-top: 6%;
  border-radius: inherit;
}

.citrus {
  background:
    radial-gradient(circle at 34% 26%, rgba(255, 255, 255, 0.68), transparent 18%),
    radial-gradient(circle at 56% 58%, rgba(255, 218, 91, 0.34), transparent 38%),
    #f58918;
  border: 2px solid rgba(146, 73, 7, 0.34);
}

.citrus::before {
  content: "";
  position: absolute;
  top: -8%;
  left: 43%;
  width: 28%;
  height: 18%;
  border-radius: 100% 0;
  background: var(--leaf);
  transform: rotate(-26deg);
}

.citrus-iyokan {
  background:
    radial-gradient(circle at 32% 25%, rgba(255, 255, 255, 0.62), transparent 18%),
    #f27319;
}

.citrus-setoka {
  background:
    radial-gradient(circle at 34% 24%, rgba(255, 255, 255, 0.7), transparent 19%),
    linear-gradient(135deg, #ffbd3a, #f05d15);
}

.citrus-benimadonna {
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.72), transparent 19%),
    linear-gradient(135deg, #ff8f3c, #ec3d2a);
  color: #fff7dc;
}

.citrus-kanpei {
  background:
    radial-gradient(circle at 33% 25%, rgba(255, 255, 255, 0.7), transparent 19%),
    linear-gradient(135deg, #ffce3d, #ff7c16);
}

.hazard {
  overflow: visible;
  filter: drop-shadow(0 9px 8px rgba(22, 18, 16, 0.35));
}

.hazard img {
  width: 150%;
  max-width: none;
  pointer-events: none;
  user-select: none;
}

.hazard-storm img {
  animation: spin 1.8s linear infinite;
}

.hazard-crow img {
  width: 170%;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  justify-items: center;
  align-content: safe center;
  overflow-y: auto;
  padding: 12px;
  background: rgba(32, 18, 5, 0.32);
  backdrop-filter: blur(2px);
}

/* `display: grid` は UA の `[hidden] { display: none }` に勝ってしまうので明示的に消す。 */
.overlay[hidden] {
  display: none;
}

.start-panel,
.result-panel {
  width: min(100%, 320px);
  display: grid;
  gap: 9px;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  background: rgba(255, 248, 226, 0.96);
  padding: 14px;
  text-align: center;
  box-shadow: 0 16px 28px rgba(36, 18, 3, 0.34);
}

.start-panel h2 {
  font-size: clamp(17px, 5.2vw, 22px);
  line-height: 1.25;
  font-weight: 1000;
}

.result-panel h2 {
  font-size: clamp(22px, 7vw, 34px);
  line-height: 1.08;
  font-weight: 1000;
}

.start-panel p,
.result-panel p {
  font-size: 13px;
  line-height: 1.5;
  font-weight: 700;
}

.primary-button {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffcf45, #f47d18);
  color: #331804;
  font-size: 17px;
  font-weight: 1000;
  box-shadow: 0 5px 0 #a9460c;
  cursor: pointer;
}

.primary-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #a9460c;
}

.ghost-button {
  width: 100%;
  min-height: 42px;
  border: 2px solid rgba(120, 68, 14, 0.34);
  border-radius: 8px;
  background: transparent;
  color: #75450e;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
}

.primary-button:focus-visible,
.ghost-button:focus-visible,
.pause-button:focus-visible {
  outline: 3px solid #1c8fc9;
  outline-offset: 2px;
}

/* `.start-panel p` と同じ詳細度だと負けるので、パネル配下として指定する。 */
.start-panel .hint {
  color: #7b561b;
  font-size: 11px;
  font-weight: 800;
}

.rules {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

.rules li {
  border-radius: 6px;
  padding: 4px 8px;
  background: rgba(255, 226, 160, 0.5);
  color: #5b3208;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.rules b {
  color: var(--deep-orange);
}

.new-record {
  justify-self: center;
  border-radius: 999px;
  padding: 4px 14px;
  background: linear-gradient(180deg, #ffd45a, #f47d18);
  color: #3a1c03;
  font-size: 12px;
  font-weight: 1000;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
}

.result-stats > div {
  border-radius: 8px;
  padding: 4px;
  background: rgba(255, 233, 179, 0.6);
}

.result-stats dt {
  color: #7b561b;
  font-size: 10px;
  font-weight: 900;
}

.result-stats dd {
  margin: 0;
  color: #4b2207;
  font-size: 14px;
  font-weight: 1000;
}

.message-row {
  min-height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

.message-row strong,
.message-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.message-row span {
  color: #6f4b18;
  font-weight: 900;
}

.citrus-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.citrus-board > div {
  min-width: 0;
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 2px;
  border-radius: 8px;
  padding: 6px 3px;
  text-align: center;
}

.citrus-board span,
.citrus-board strong,
.citrus-board em {
  min-width: 0;
  overflow-wrap: anywhere;
}

.citrus-board span {
  color: #704713;
  font-size: 10px;
  font-weight: 900;
}

.citrus-board strong {
  color: #d94b16;
  font-size: 13px;
}

.citrus-board em {
  color: #1d5d35;
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

.citrus-board .rare {
  background: linear-gradient(180deg, rgba(255, 251, 223, 0.97), rgba(255, 219, 123, 0.96));
  border-color: rgba(205, 116, 8, 0.4);
}

.stamp-prize {
  display: grid;
  gap: 4px;
  justify-items: center;
}

.stamp-prize img {
  width: min(40%, 108px);
  border-radius: 8px;
  filter: drop-shadow(0 8px 10px rgba(56, 28, 4, 0.2));
}

.stamp-prize span,
.no-stamp {
  color: #71410c;
  font-size: 13px;
  font-weight: 900;
}

.local-note {
  border-radius: 8px;
  padding: 7px 10px;
  background: rgba(16, 70, 89, 0.84);
  color: #fff7dd;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 5px 0 rgba(11, 45, 58, 0.3);
}

@keyframes spin {
  to {
    rotate: 360deg;
  }
}

@keyframes pop-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.7);
  }
  22% {
    opacity: 1;
    transform: translate(-50%, -70%) scale(1.12);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -190%) scale(1);
  }
}

@keyframes burst-out {
  from {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.3);
  }
}

@keyframes flash-fade {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes catch-squash {
  0% {
    transform: translateX(-50%) rotate(var(--lean, 0deg)) scale(1, 1);
  }
  45% {
    transform: translateX(-50%) rotate(var(--lean, 0deg)) scale(1.1, 0.88);
  }
  100% {
    transform: translateX(-50%) rotate(var(--lean, 0deg)) scale(1, 1);
  }
}

@keyframes shake {
  0%,
  100% {
    translate: 0 0;
  }
  20% {
    translate: -6px 2px;
  }
  40% {
    translate: 5px -2px;
  }
  60% {
    translate: -4px 1px;
  }
  80% {
    translate: 3px 0;
  }
}

@keyframes urgent-pulse {
  0%,
  100% {
    background: rgba(255, 250, 229, 0.92);
  }
  50% {
    background: rgba(255, 214, 190, 0.96);
  }
}

@keyframes fever-pulse {
  from {
    box-shadow: 0 4px 0 rgba(83, 47, 12, 0.14);
  }
  to {
    box-shadow:
      0 4px 0 rgba(83, 47, 12, 0.14),
      0 0 14px rgba(255, 176, 51, 0.9);
  }
}

@media (prefers-reduced-motion: reduce) {
  .hazard-storm img,
  .hud > div.urgent,
  .fever-bar.active,
  .playfield.shake,
  .player.catching {
    animation: none;
  }

  .pop {
    animation-duration: 0.5s;
  }
}

/* 縦の短い端末では説明を削って、開始パネルが盤面からはみ出さないようにする。 */
@media (max-height: 700px) {
  .start-panel .hint,
  .local-note {
    display: none;
  }

  .start-panel h2 {
    font-size: clamp(16px, 4.6vw, 19px);
  }

  .rules li {
    font-size: 11px;
    padding: 3px 7px;
  }

  .primary-button {
    min-height: 46px;
  }
}

@media (max-width: 370px) {
  .game-shell {
    padding: 8px;
  }

  .game-card {
    gap: 6px;
  }

  .playfield {
    min-height: 280px;
  }

  .fever-bar {
    height: 18px;
  }

  .fever-bar > span {
    font-size: 10px;
  }

  .hud > div {
    min-height: 47px;
  }

  .hud span {
    font-size: 10px;
  }

  .citrus-board {
    gap: 4px;
  }

  .citrus-board > div {
    min-height: 52px;
  }
}

@media (min-width: 740px) {
  .game-shell {
    padding: 24px;
  }
}
