:root {
  --brown:   #7c5a3a;
  --brown-d: #5f4630;
  --cream:   #fff6e6;
  --cream-2: #f3e3c4;
  --accent:  #e8954a;
  --accent-d:#cf7a32;
  --ok:      #6fae4b;
  --shadow:  0 4px 14px rgba(95, 70, 48, 0.18);
  --tile-r:  10px;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  color: var(--brown-d);
  background:
    radial-gradient(circle at 30% 18%, #fff4df 0%, transparent 55%),
    linear-gradient(160deg, #f7e6c6 0%, #e9cfa0 100%);
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 14px env(safe-area-inset-bottom);
}

/* ---- ヘッダー ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 2px 6px;
}
.logo {
  font-size: 1.25rem;
  margin: 0;
  letter-spacing: .02em;
}
.paw { filter: drop-shadow(0 1px 1px rgba(0,0,0,.15)); }
.icon-btn {
  width: 34px; height: 34px;
  border: none; border-radius: 50%;
  background: #fff; color: var(--brown);
  font-weight: 700; font-size: 1rem;
  box-shadow: var(--shadow);
}

/* ---- ステータス ---- */
.stats {
  display: flex;
  gap: 8px;
  margin: 4px 0 10px;
}
.stat {
  flex: 1;
  background: rgba(255,255,255,.72);
  border-radius: 14px;
  padding: 8px 6px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat.best { background: linear-gradient(160deg,#fff3d6,#ffe2ab); }
.stat-label {
  display: block;
  font-size: .68rem;
  color: var(--brown);
  opacity: .8;
}
.stat-value {
  display: block;
  font-size: 1.18rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat.best .stat-value { font-size: .92rem; }

/* ---- 盤面 ---- */
.board-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.board {
  position: relative;
  background: #cbb085;
  border-radius: 16px;
  box-shadow: inset 0 0 0 4px rgba(124,90,58,.35), var(--shadow);
  touch-action: none;
}
.tile {
  position: absolute;
  top: 0; left: 0;
  margin: 0; padding: 0;
  border: none;
  border-radius: var(--tile-r);
  background-color: #b89968;
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25), 0 2px 4px rgba(95,70,48,.25);
  transition: transform .16s cubic-bezier(.3,.9,.4,1);
  cursor: pointer;
  overflow: hidden;
}
.tile:active { filter: brightness(1.05); }
.tile.blank {
  opacity: 0;
  pointer-events: none;
}
.tile-num {
  position: absolute;
  left: 4px; top: 3px;
  font-size: .72rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
  background: rgba(124,90,58,.55);
  border-radius: 8px;
  padding: 0 5px;
  transition: opacity .2s;
}
/* お手本モード：完成図を盤面の上に重ねて表示 */
.peek-overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 16px;
  background-size: cover;
  background-position: center;
  box-shadow: var(--shadow), 0 0 0 3px var(--accent);
  z-index: 10;
  animation: fade .2s;
}

/* ---- 操作 ---- */
.controls { padding: 10px 0 6px; }
.difficulty {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.diff-btn {
  flex: 1;
  border: 2px solid transparent;
  border-radius: 14px;
  background: rgba(255,255,255,.7);
  color: var(--brown-d);
  padding: 8px 4px;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: var(--shadow);
}
.diff-btn small { font-size: .62rem; opacity: .75; font-weight: 500; }
.diff-btn.active {
  background: linear-gradient(160deg, var(--accent), var(--accent-d));
  color: #fff;
  border-color: #fff;
}
.main-actions { display: flex; gap: 8px; }
.btn {
  flex: 1;
  border: none;
  border-radius: 14px;
  padding: 13px 10px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--brown-d);
  background: #fff;
  box-shadow: var(--shadow);
  transition: transform .08s;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(160deg, var(--accent), var(--accent-d));
  color: #fff;
}
.peekBtn.active, .btn.active {
  outline: 3px solid var(--accent);
}

/* ---- クリア演出 ---- */
.clear-overlay {
  position: absolute;
  inset: 0;
  background: rgba(95,70,48,.42);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  animation: fade .3s;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.clear-card {
  background: var(--cream);
  border-radius: 22px;
  padding: 18px 18px 20px;
  width: min(90%, 360px);
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
  animation: pop .35s cubic-bezier(.2,1.3,.5,1);
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.clear-card h2 { margin: 2px 0 12px; font-size: 1.4rem; }
.reward-canvas {
  width: 70%;
  max-width: 220px;
  aspect-ratio: 1;
  border-radius: 16px;
  box-shadow: var(--shadow);
  background: var(--cream-2);
}
.clear-stats { font-size: 1rem; font-weight: 700; margin: 12px 0 4px; }
.new-best { color: var(--accent-d); font-weight: 700; margin: 0 0 6px; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.clear-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---- モーダル ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(95,70,48,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 20px;
}
.modal-card {
  background: var(--cream);
  border-radius: 20px;
  padding: 22px;
  width: min(92%, 400px);
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.modal-card h2 { margin-top: 0; }
.modal-card ul { padding-left: 1.1em; line-height: 1.7; font-size: .95rem; }
.modal-card .btn { width: 100%; margin-top: 12px; }

.hidden { display: none !important; }
