@charset "UTF-8";
/* ==========================================================================
   しいたけねこ神経衰弱 — style.css
   1. 変数・ベース   2. 背景の飾り   3. タイトル画面   4. HUD
   5. カード（めくる動き）   6. 演出   7. 結果画面   8. スマホ対応
   ========================================================================== */

/* ------------------------------------------------ 1. 変数・ベース */
:root {
  --cream:      #fdf8ec;
  --cream-deep: #f6ecd6;
  --beige:      #efe0c2;
  --brown:      #7c5136;
  --brown-deep: #4e3524;
  --green-deep: #365730;
  --moss:       #8aa86a;
  --orange:     #e08b3c;
  --orange-deep:#c96f24;
  --yellow:     #f3c453;
  --line:       #e3d3b4;

  --shadow-sm: 0 2px 8px rgba(124, 81, 54, .10);
  --shadow-md: 0 8px 22px rgba(124, 81, 54, .14);
  --shadow-lg: 0 18px 44px rgba(124, 81, 54, .18);

  --radius: 22px;
  --radius-lg: 30px;
  --pill: 999px;

  --font: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans",
          "Yu Gothic Medium", "Meiryo", system-ui, sans-serif;
  --ease: cubic-bezier(.22, .68, .3, 1);
  --bounce: cubic-bezier(.34, 1.45, .5, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  font-family: var(--font);
  color: var(--brown-deep);
  background:
    radial-gradient(1200px 600px at 50% -10%, #fffdf6 0%, rgba(255,253,246,0) 70%),
    linear-gradient(180deg, #fbf3e2 0%, #f4ead4 55%, #eee2c6 100%);
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; height: auto; display: block; }

/* ------------------------------------------------ 2. 背景の飾り */
.forest-deco { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.forest-deco .leaf {
  position: absolute; width: 26px; height: 26px;
  background: var(--orange); border-radius: 0 60% 0 60%;
  opacity: .16; animation: leafFloat 14s var(--ease) infinite;
}
.leaf1 { left: 6%;  top: 12%; }
.leaf2 { left: 88%; top: 20%; background: var(--moss); animation-delay: -3s; }
.leaf3 { left: 14%; top: 72%; background: var(--yellow); animation-delay: -6s; }
.leaf4 { left: 78%; top: 66%; animation-delay: -9s; }
.leaf5 { left: 46%; top: 6%;  background: var(--moss); animation-delay: -11s; }
.leaf6 { left: 60%; top: 88%; background: var(--yellow); animation-delay: -5s; }
@keyframes leafFloat {
  0%, 100% { transform: translate3d(0,0,0) rotate(0deg); }
  50%      { transform: translate3d(14px,-22px,0) rotate(28deg); }
}

/* ------------------------------------------------ 画面の切り替え */
.screen { display: none; position: relative; z-index: 1; }
.screen.is-active { display: block; animation: fadeUp .5s var(--ease) both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------ ボタン */
.btn {
  font-family: inherit; font-weight: 700; cursor: pointer; border: none;
  border-radius: var(--pill); touch-action: manipulation;
  transition: transform .18s var(--bounce), box-shadow .18s var(--ease), background-color .18s var(--ease);
}
.btn:active { transform: translateY(2px) scale(.98); }
.btn-main {
  font-size: clamp(18px, 4.4vw, 24px); color: #fff; padding: 18px 54px;
  background: linear-gradient(180deg, #e8974a 0%, var(--orange-deep) 100%);
  box-shadow: 0 6px 0 #a95a19, var(--shadow-md); letter-spacing: .06em;
}
.btn-main:hover { background: linear-gradient(180deg, #eda153 0%, #d17a2a 100%); transform: translateY(-2px); }
.btn-main:active { box-shadow: 0 2px 0 #a95a19, var(--shadow-sm); }
.btn-sub {
  font-size: 16px; color: var(--brown); padding: 14px 32px; background: #fff;
  border: 2px solid var(--line); box-shadow: var(--shadow-sm);
}
.btn-sub:hover { background: var(--cream); border-color: var(--orange); color: var(--orange-deep); }
.btn-ghost {
  font-size: 14px; color: #fff; padding: 11px 20px; white-space: nowrap;
  background: linear-gradient(180deg, #5e8a4f 0%, var(--green-deep) 100%);
  box-shadow: 0 3px 0 #2b451f;
}
.btn-ghost:hover { filter: brightness(1.07); }
.btn-ghost::before { content: "↺ "; }
.btn-sound {
  font-size: 13px; color: var(--brown); padding: 9px 18px; background: #fff;
  border: 2px solid var(--line); box-shadow: var(--shadow-sm);
}
.btn-sound .sound-off { display: none; }
.btn-sound[aria-pressed="false"] .sound-on { display: none; }
.btn-sound[aria-pressed="false"] .sound-off { display: inline; }

/* ------------------------------------------------ 3. タイトル画面 */
#screen-title { display: none; place-items: center; min-height: 100svh; padding: 32px 16px 48px; }
#screen-title.is-active { display: grid; }
.title-card {
  width: min(680px, 100%); text-align: center;
  background: rgba(255,253,246,.92); border: 3px solid #fff;
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: clamp(24px,6vw,44px) clamp(18px,5vw,44px) clamp(28px,6vw,40px);
}
.title-neko { width: clamp(120px,30vw,180px); margin: -14px auto 6px; animation: nekoBob 3.4s var(--ease) infinite; }
@keyframes nekoBob { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-9px) rotate(2deg); } }
.title {
  margin: 0 0 6px; line-height: 1.25; font-size: clamp(28px,7.4vw,46px);
  color: var(--brown-deep); text-shadow: 0 2px 0 #fff, 0 4px 10px rgba(124,81,54,.15);
}
.title span { color: var(--green-deep); }
.subtitle { margin: 0 0 14px; font-size: clamp(13px,3.4vw,16px); color: var(--brown); }
.lead {
  margin: 0 auto 24px; max-width: 30em; font-size: clamp(13px,3.3vw,15px);
  line-height: 1.9; color: #6a513c; background: var(--cream);
  border-radius: var(--radius); padding: 14px 18px;
}
.howto {
  margin: 22px auto 0; padding: 0; list-style: none; max-width: 30em;
  font-size: 12.5px; line-height: 1.9; color: #7a6249; text-align: left;
}
.howto li { position: relative; padding-left: 20px; }
.howto li::before {
  content: ""; position: absolute; left: 2px; top: .62em;
  width: 10px; height: 6px; background: var(--brown); border-radius: 10px 10px 2px 2px;
}
.back-link {
  display: inline-block; margin-top: 18px; font-size: 12.5px; color: var(--brown);
  text-decoration: none; border-bottom: 2px dotted var(--line); padding-bottom: 2px;
}
.back-link:hover { color: var(--orange-deep); border-bottom-color: var(--orange); }

/* ------------------------------------------------ 4. ゲーム画面とHUD */
#screen-game { padding: 18px 12px 40px; max-width: 1060px; margin: 0 auto; }
.game-head { text-align: center; margin-bottom: 12px; }
.game-title { margin: 0; font-size: clamp(18px,4.6vw,28px); color: var(--brown-deep); text-shadow: 0 2px 0 #fff; }
.game-title span { color: var(--green-deep); }
.game-theme { margin: 4px 0 0; font-size: clamp(11px,3vw,13px); color: var(--brown); letter-spacing: .04em; }

.hud {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px;
  background: rgba(255,253,246,.95); border: 2px solid #fff;
  border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 10px 12px;
}
.hud-item {
  display: flex; align-items: center; gap: 7px; background: #fff;
  border: 2px solid var(--line); border-radius: var(--pill); padding: 7px 16px;
}
.hud-item img { width: 26px; height: auto; }
.hud-label { font-size: 11.5px; color: #8a705a; font-weight: 700; letter-spacing: .04em; }
.hud-value { font-size: clamp(20px,5vw,26px); line-height: 1; color: var(--brown-deep); }
.hud-value small { font-size: .62em; margin: 0 2px; color: #a08a6e; }
.hud-unit { font-size: 12px; color: #8a705a; }
.hud-diff { font-size: 11px; color: var(--green-deep); background: #eaf2e2; border-radius: var(--pill); padding: 3px 9px; }
.hud-mush { display: inline-flex; gap: 3px; }
.hud-mush i {            /* むずかしさを、きのこの数で見せます */
  width: 11px; height: 13px; display: block; position: relative;
}
.hud-mush i::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 7px;
  background: var(--brown); border-radius: 9px 9px 3px 3px;
}
.hud-mush i::after {
  content: ""; position: absolute; left: 3.5px; top: 6px; width: 4px; height: 7px;
  background: #d8c6a4; border-radius: 0 0 2px 2px;
}
.hud-time .hud-value { color: var(--orange-deep); font-variant-numeric: tabular-nums; }
.hud-pair .hud-value { color: var(--green-deep); }
.hud-time.is-hurry { border-color: #f0b0a0; background: #fff4f0; animation: hurry 1s steps(2) infinite; }
.hud-time.is-hurry .hud-value { color: #d8452c; }
@keyframes hurry { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }

.timebar { height: 8px; margin: 10px auto 16px; background: #e7dbc2; border-radius: var(--pill); overflow: hidden; }
.timebar span {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--yellow), var(--orange));
  border-radius: var(--pill); transition: width .3s linear;
}
.timebar span.is-hurry { background: linear-gradient(90deg, #f0a07f, #d8452c); }

/* ------------------------------------------------ 5. カード */
.board-wrap {
  width: fit-content; max-width: 100%; margin: 0 auto;   /* カードに合わせて枠も縮みます */
  background: rgba(255,253,246,.85); border: 3px solid #fff;
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  padding: clamp(12px,3vw,22px);
}
.board {
  display: grid; gap: clamp(8px,1.6vw,14px);
  /* 列数は JS が --cols-pc / --cols-sp を入れます（スマホは下のほうで切り替え） */
  grid-template-columns: repeat(var(--cols-pc, 4), minmax(0, 1fr));
  max-width: 880px; margin: 0 auto;
}

.card {
  position: relative; aspect-ratio: 4 / 5; border: none; padding: 0;
  background: none; cursor: pointer; perspective: 800px;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.card:disabled { cursor: default; }
.card-inner {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transition: transform .42s var(--ease);
  border-radius: 16px;
}
.card.is-open .card-inner, .card.is-matched .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-sm);
  display: grid; place-items: center;
}
/* 裏面（全カード共通：きのこのかさと肉球） */
.card-back {
  background: linear-gradient(160deg, #8b6647 0%, #6b4a30 100%);
  border: 3px solid #fff;
}
.card-back::before {            /* 内側の点線の枠 */
  content: ""; position: absolute; inset: 7px;
  border: 2px dotted rgba(255,255,255,.34); border-radius: 11px;
}
.card-back svg { width: 46%; height: auto; opacity: .95; transform: translateY(-6%); }
.card:hover .card-back { filter: brightness(1.06); }

/* 表面 */
.card-front {
  transform: rotateY(180deg);
  background: linear-gradient(170deg, #fffdf6 0%, var(--cream-deep) 100%);
  border: 3px solid #fff;
}
.card-front img { width: 97%; height: 97%; object-fit: contain; }
.card-front::after {           /* 落ち葉のワンポイント */
  content: ""; position: absolute; right: 7%; bottom: 7%;
  width: 12px; height: 12px; background: var(--yellow);
  border-radius: 0 60% 0 60%; opacity: .5;
}

.card.is-matched { animation: cardPop .5s var(--bounce); }
@keyframes cardPop {
  0% { transform: scale(1); } 40% { transform: scale(1.09) translateY(-6px); } 100% { transform: scale(1); }
}
.card.is-matched .card-front {
  box-shadow: 0 0 0 3px var(--yellow), 0 6px 18px rgba(224,139,60,.4);
  background: linear-gradient(170deg, #fffdf2 0%, #fdf0cf 100%);
}
.card.is-matched .card-front::before {
  content: "そろった！"; position: absolute; left: 0; right: 0; bottom: 6%;
  margin: 0 auto; width: max-content; max-width: 94%; white-space: nowrap;
  overflow: hidden; text-overflow: clip;
  font-size: clamp(9px, 1.7vw, 12px); font-weight: 700; color: #fff;
  background: linear-gradient(180deg, #e8974a, var(--orange-deep));
  border-radius: var(--pill); padding: 3px 10px; box-shadow: var(--shadow-sm);
  animation: fadeUp .4s var(--ease) both;
}
.card.is-wrong .card-inner { animation: cardShake .4s var(--ease); }
@keyframes cardShake {
  0%,100% { transform: rotateY(180deg) translateX(0); }
  25% { transform: rotateY(180deg) translateX(-5px); }
  60% { transform: rotateY(180deg) translateX(4px); }
}

/* ------------------------------------------------ 6. 演出 */
.spark {
  position: fixed; width: 10px; height: 10px; margin: -5px 0 0 -5px; z-index: 30;
  background: var(--yellow); border-radius: 0 60% 0 60%; pointer-events: none;
  animation: sparkOut .7s var(--ease) forwards;
}
.spark.leaf { background: var(--orange); }
.spark.green { background: var(--moss); }
@keyframes sparkOut {
  0% { opacity: 1; transform: translate(0,0) scale(.4) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(200deg); }
}

.hint-line { margin: 14px 0 0; text-align: center; font-size: 12.5px; color: #7a6249; min-height: 1.6em; }
.game-foot { margin-top: 14px; display: flex; gap: 14px; align-items: center; justify-content: center; }

.toast {
  position: fixed; left: 50%; top: 16%; transform: translate(-50%,0); z-index: 40;
  pointer-events: none; font-weight: 700; font-size: clamp(18px,5vw,26px); color: #fff;
  padding: 12px 30px; border-radius: var(--pill);
  background: linear-gradient(180deg, #6da35b, #3f6b33); box-shadow: var(--shadow-md);
  animation: toastIn .5s var(--bounce) both;
}
.toast.is-miss { background: linear-gradient(180deg, #d9927f, #b85a44); font-size: clamp(15px,4vw,20px); }
@keyframes toastIn {
  0% { opacity: 0; transform: translate(-50%,14px) scale(.8); }
  60% { opacity: 1; transform: translate(-50%,0) scale(1.04); }
  100% { opacity: 1; transform: translate(-50%,0) scale(1); }
}
.toast.is-out { animation: toastOut .3s var(--ease) both; }
@keyframes toastOut { to { opacity: 0; transform: translate(-50%,-12px) scale(.94); } }

/* ------------------------------------------------ 7. 結果画面 */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  padding: 20px; background: rgba(62,42,28,.58); animation: fadeIn .3s var(--ease) both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.overlay[hidden] { display: none; }
.overlay-card {
  position: relative; z-index: 2; width: min(520px,100%); text-align: center;
  background: var(--cream); border: 4px solid #fff; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 30px clamp(18px,5vw,34px) 28px;
  animation: cardIn .5s var(--bounce) both; max-height: 88svh; overflow-y: auto;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(20px) scale(.94); } to { opacity: 1; transform: none; } }
.ov-neko { width: clamp(100px,26vw,150px); margin: -8px auto 8px; }
.overlay-card.is-all .ov-neko { width: clamp(140px,38vw,210px); animation: nekoBob 2.6s var(--ease) infinite; }
.ov-title { margin: 0 0 6px; font-size: clamp(22px,6vw,32px); color: var(--green-deep); text-shadow: 0 2px 0 #fff; }
.overlay-card.is-over .ov-title { color: var(--orange-deep); }
.ov-text { margin: 0 0 18px; font-size: clamp(13px,3.6vw,16px); color: var(--brown); line-height: 1.8; }
.ov-buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i { position: absolute; top: -20px; width: 12px; height: 12px; border-radius: 0 60% 0 60%; animation: fall linear forwards; }
@keyframes fall {
  0% { opacity: 0; transform: translateY(-10px) rotate(0deg); }
  10% { opacity: 1; }
  100% { opacity: .9; transform: translateY(105svh) rotate(540deg); }
}

/* ------------------------------------------------ 8. スマホ対応 */
@media (max-width: 860px) {
  .hud { gap: 6px; padding: 8px; }
  .hud-item { padding: 6px 12px; gap: 5px; }
  .hud-item img { width: 22px; }
  .hud-label { font-size: 10.5px; }
  .hud-diff { display: none; }
  #btn-retry-top { padding: 9px 14px; font-size: 13px; }
}
@media (max-width: 560px) {
  /* スマホでは、カードが小さくなりすぎないよう列数を抑えます（最大4列） */
  .board { grid-template-columns: repeat(var(--cols-sp, 3), minmax(0, 1fr)); }
  /* カードが小さいので、「そろった！」の帯も小さくします（はみ出し防止） */
  .card.is-matched .card-front::before { font-size: 8px; padding: 2px 6px; bottom: 5%; }
}
@media (max-width: 420px) {
  #screen-game { padding: 14px 10px 32px; }
  .hud-level img { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .card-inner { transition: none; }
}
