/* =========================
  Base
========================= */
*{ box-sizing:border-box; }

html, body{ height:100%; }

body{
  font-family:"Hiragino Sans","Yu Gothic",system-ui,sans-serif;
  background:#f9fafb;
  margin:0;
  padding:20px;
  display:flex;
  justify-content:center;
}

.game-wrapper{
  max-width:780px;
  width:100%;
  background:#ffffff;
  border-radius:16px;
  box-shadow:0 4px 16px rgba(0,0,0,0.08);
  padding:20px;
}

h1{
  font-size:1.4rem;
  margin:0 0 6px;
  text-align:center;
}

.desc{
  font-size:0.95rem;
  margin:0 0 12px;
  text-align:center;
  line-height:1.35;
}

/* =========================
  Top Screen
========================= */
.top-screen{ display:block; padding:14px 10px 6px; }

.top-card{
  background:#f1f5f9;
  border:1px solid #e2e8f0;
  border-radius:16px;
  padding:14px;
  max-width:560px;
  margin:0 auto 10px;
}

.top-title{
  font-weight:900;
  font-size:1.05rem;
  margin:0 0 10px;
  text-align:center;
  color:#0f172a;
}

.mode-buttons{
  display:flex;
  gap:10px;
  justify-content:center;
  align-items:stretch;
  margin-top:6px;
}

.mode-btn{
  flex:1 1 0;
  border:none;
  border-radius:16px;
  padding:12px 12px;
  cursor:pointer;
  background:#111827;
  color:#fff;
  font-weight:900;
  font-size:1.0rem;
  transition:transform 0.08s ease, opacity 0.15s ease;
}

.mode-btn:hover{ opacity:0.92; }
.mode-btn:active{ transform:scale(0.98); }

.mode-btn.selected{
  outline:3px solid rgba(14,165,233,0.65);
  box-shadow:0 0 0 5px rgba(14,165,233,0.15);
}

.mini-note{
  text-align:center;
  font-size:0.9rem;
  color:#334155;
  margin-top:10px;
  font-weight:700;
}

.pill{
  display:inline-block;
  padding:4px 10px;
  border-radius:999px;
  background:#ffffff;
  border:1px solid #dbeafe;
  font-weight:800;
}

.pill.hard{
  border-color:#fecaca;
  background:#fff1f2;
  color:#b91c1c;
}

@media (max-width:600px){
  .mode-buttons{ flex-direction:column; }
}

/* =========================
  Game Screen
========================= */
.game-screen{ display:none; }

/* Topbar (back) */
.topbar{
  display:flex;
  justify-content:flex-start;
  margin:4px 0 10px;
}

.back-top-btn{
  border:none;
  border-radius:999px;
  padding:8px 14px;
  font-size:0.95rem;
  cursor:pointer;
  background:#111827;
  color:#fff;
  font-weight:900;
}

.back-top-btn:hover{ opacity:0.9; }

/* Target Section */
.target-section{ position:relative; margin-bottom:12px; }

.target-row{
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  gap:14px;
  position:relative;
}

#clear-banner{
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%) scale(0.7);
  font-size:2.2rem;
  font-weight:900;
  color:#f97316;
  text-shadow:0 0 10px rgba(248,181,0,0.9);
  opacity:0;
  pointer-events:none;
}

#clear-banner.show{
  opacity:1;
  animation:clear-pop 0.6s ease-out;
  transform:translate(-50%,-50%) scale(1);
}

@keyframes clear-pop{
  0%{transform:translate(-50%,-50%) scale(0.4); opacity:0;}
  60%{transform:translate(-50%,-50%) scale(1.1); opacity:1;}
  100%{transform:translate(-50%,-50%) scale(1); opacity:1;}
}

/* Status */
.status-box{
  position: relative;
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  gap:12px;
  margin-bottom:18px;
  padding:10px 12px;
  border-radius:12px;
  background: #ecfdf3;
  border: 1px solid #bbf7d0;
  align-items:center;
}

#tap-item{ display:none !important; }

.status-item{ font-size:0.95rem; }

.topbar-under-status{
  justify-content: center;
  gap: 10px;
  margin: 6px 0 10px;  /* 円の直上感 */
}

.topbar-under-status .reset-btn{
  width: 40px;
  height: 40px;
  font-size: 18px;
  background: rgba(229,231,235,0.95);
  color: #374151;
}

/* Compact variant: HTMLで .status-box compact を付けた時だけ効く */
.status-box.compact{
  display:flex;
  flex-wrap:wrap;
  gap:6px 10px;
  padding:0;
  margin:0 0 10px;
  background:transparent;
  border:none;
  justify-content:center;
  align-items:center;
}

.status-box.compact .status-item{
  font-size:0.85rem;
  white-space:nowrap;
}

/* ===== Chips: PC/共通の基本 ===== */
.chips-area{
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  align-content:flex-start;
  gap:18px;
  margin: 16px 0 12px;
  padding: 0;
}


/* Fraction piece */
.fraction-piece{
  width:160px;
  height:160px;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  user-select:none;
  position:relative;
  margin: 0 !important;
  transition:transform 0.15s ease, filter 0.15s ease;
}

.fraction-piece svg{ overflow:visible; }

.fraction-piece.selected{
  transform:translateY(-4px) scale(1.04);
  filter:drop-shadow(0 0 6px rgba(250,204,21,0.9));
}

.count-badge{
  position:absolute;
  right:6px;
  bottom:6px;
  background:rgba(15,23,42,0.85);
  color:#f9fafb;
  border-radius:999px;
  padding:2px 8px;
  font-size:0.7rem;
  display:none;
}

.fraction-piece.has-count .count-badge{ display:inline-block; }

.message{
  text-align:center;
  min-height:1.4em;
  margin-bottom:12px;
  font-weight:700;
}

.message.ok{ color:#16a34a; }
.message.ng{ color:#dc2626; }

.selected-list{
  font-size:0.9rem;
  text-align:center;
  min-height:1.4em;
  margin-bottom:10px;
}

.btn-row{
  text-align:center;
  margin-top:6px;
  display:flex;
  gap:10px;
  justify-content:center;
  flex-wrap:wrap;
}

button{
  border:none;
  border-radius:999px;
  padding:8px 16px;
  font-size:0.95rem;
  cursor:pointer;
  background:#0ea5e9;
  color:#ffffff;
  font-weight:900;
}

button:hover{ opacity:0.9; }

.ghost-btn{ background:#111827; }

/* Reset button (if you still use target-controls in HTML) */
.target-controls{
  position:absolute;
  top: 10px;
  right: 10px;
  z-index: 50;
  display:flex;
  gap:8px;
  align-items:center;
}

.reset-btn{
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 0;
  background: rgba(229,231,235,0.95);
  color: #374151;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  padding:0;
}

.reset-btn:hover{ background: rgba(209,213,219,0.98); }

/* Left fraction label */
.piece-wrap{
  position: relative;
  display: inline-flex;
  align-items: center;
}

.frac-label{
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-68px, -50%);
  width: 30px;
  text-align: center;
  color: #111827;
  font-weight: 900;
  font-size: 16px;
  line-height: 1;
  pointer-events: none;
}

.frac-label .num,
.frac-label .den{ display:block; white-space: nowrap; }

.frac-label .bar{
  display:block;
  height:2px;
  background:#111827;
  margin:3px 4px;
  border-radius:2px;
}

/* Hard mode hidden */
.mode-btn[data-mode="hard"]{ display:none !important; }

/* Failbar */
.failbar{
  display: flex;
  justify-content: center;
  align-items: center;

  background: none !important;
  border: none !important;
  padding: 4px 0 !important;
  margin: 6px 0 10px !important;
}

.failbar-text{
  color: #dc2626;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
}

.failbar-retry{
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  background: #fff;
  color: #111827;
}

.failbar-retry:active{ transform: translateY(1px); }

/* =========================
  Mobile Optimization
  目的：見切れ防止 + ピースを下に固定 + 1画面で遊びやすく
========================= */
@media (max-width:600px){

  /* WPで body overflow:hidden は事故りやすいので使わない */
  body{
    padding: 10px;
    overflow: visible;
    }

  .game-wrapper{
    padding: 12px;
    }

  /* iPhone安定のsvh */
  .game-screen{
    height: 100svh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    }

  /* 目標は横スクロール化 */
  .target-row{
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    padding: 6px 6px 10px;
    gap: 10px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    }

  .target-row > svg{
    flex: 0 0 auto;
    scroll-snap-align: center;
	}

  .fraction-piece{
    width: 110px;
    height: 90px;
    }

  .fraction-piece svg{
    width: 84px;
    height: 84px;
   }

  .piece-wrap{ gap:3px; }

  .frac-label{
    font-size: 13px;
    width: 24px;
    transform: translate(-42px, -50%);
    }

  .topbar{ margin:2px 0 8px; }

  .selected-list, .message{
    padding: 6px 8px;
    font-size: 0.9rem;
	}
	
	  .chips-area{
    position: sticky;
    bottom: 0;
    z-index: 20;
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(6px);
    border-top: 1px solid #e5e7eb;

    margin: 0 -12px;
    padding: 8px 8px 10px;

    display: grid;
    grid-template-columns: repeat(3, minmax(0,1fr));
    gap: 8px;
    justify-items: center;

    align-content: start;   /* ←これ追加 */
    place-content: start;   /* ←これ追加 */
    }

  .fraction-piece{
    width: 110px;
    height: 90px;
    margin: 0;
    }

  .fraction-piece svg{
    width: 84px;
    height: 84px;
	}
	
  .game-layout{
    overflow: visible !important;
    }
	
}

/* =========================
  PATCH 20251221_2
  - target-row右の余白カット + センター寄せ
  - status-box: ねらい/ノーマル非表示
  - status-box: 薄緑背景（compactでも）
========================= */

/* status-box：ねらい と ノーマル を非表示（DOMは残す） */
#target-item{ display:none !important; }
#mode-pill{ display:none !important; }

/* compactでも薄緑背景を維持 */
.status-box.compact{
  background:#ecfdf3 !important;
  border:1px solid #bbf7d0 !important;
  padding:8px 10px !important;
  border-radius:12px !important;
}

/* ついでに間隔ちょい詰め（見やすさUP） */
.status-box.compact .status-item{
  font-size:0.88rem !important;
}

/* ===== スマホ：target-rowの右側の余白いらない問題 ===== */
@media (max-width:600px){
  .target-row{
    padding: 6px 0 10px !important;   /* ←左右padding消す */
    justify-content: center !important; /* ←1個の時も中央へ */
    gap: 10px !important;
  }
  /* 横スクロール自体は残す（複数円の時に必要） */
  .target-
	
/* =========================
  Failbar: status-boxの直下に出す（sticky解除）
========================= */

/* failbarを通常のDOMフローに戻す */
.failbar{
  position: static !important;
  top: auto !important;
  z-index: auto !important;
  margin: 6px auto 10px !important;   /* status-boxの直下感 */
  width: 100%;
  max-width: 780px;
  order: 2; /* flexの並び順を後ろに（親がflexの場合だけ効く） */
}

/* status-boxの直下に来た時に見栄えよく */
.status-box + .failbar{
  margin-top: 6px !important;
	}
	
	/* =========================
  PATCH 20251221_failbar_under_status
  - failbarを上固定(sticky)やめて status-boxの直下に見せる
  - target-row右余白カット
  - status-box: ねらい/ノーマル非表示 + 薄緑
========================= */

/* status-box：ねらい と ノーマル を非表示（DOMは残す） */
#target-item{ display:none !important; }
#mode-pill{ display:none !important; }

/* compactでも薄緑背景を維持（今の compact が transparent にしてるのを戻す） */
.status-box.compact{
  background:#ecfdf3 !important;
  border:1px solid #bbf7d0 !important;
  padding:8px 10px !important;
  border-radius:12px !important;
  margin:0 0 8px !important;
}

/* ===== failbar: sticky解除して通常フローに戻す ===== */
.failbar{
  position: static !important;
  top: auto !important;
  z-index: auto !important;
  margin: 6px 0 10px !important; /* status-boxのすぐ下っぽく */
  width: 100%;
}

/* ===== スマホ：target-rowの左右余白を消して右のスカスカをなくす ===== */
@media (max-width:600px){
  .target-row{
    padding-left: 0 !important;
    padding-right: 0 !important;
    justify-content: center !important; /* 円が1個の時も中央 */
  }
	}
	
	.failbar{
  position: static !important;
  top: auto !important;
}
