/* ぽっぷナンプレ — 見た目の調整はこの先頭の変数から */
:root {
  --cream: #fff7e6;
  --cream-2: #fff0d4;
  --paper: #fffdf8;
  --ink: #2b2633;
  --ink-soft: #5d5566;
  --mint: #5ccfae;
  --mint-l: #d8f5ea;
  --mint-d: #17806a;
  --coral: #ff7a66;
  --coral-l: #ffe1db;
  --coral-d: #b83a26;
  --sun: #ffd166;
  --sel: #ffe9a8;
  --area: #eef9f4;
  --same: #c8f0e1;
  --line: #d9cbb4;
  --line-strong: #4a4152;
  --radius: 14px;
  --shadow: 0 4px 0 rgba(43, 38, 51, 0.12);
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
}
[hidden] { display: none !important; }

/* 背景の水玉（自作CSS） */
.bg-deco {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 8% 12%, var(--mint-l) 0 46px, transparent 47px),
    radial-gradient(circle at 92% 8%, var(--coral-l) 0 34px, transparent 35px),
    radial-gradient(circle at 96% 78%, var(--mint-l) 0 60px, transparent 61px),
    radial-gradient(circle at 4% 88%, #ffeab8 0 40px, transparent 41px),
    radial-gradient(circle, rgba(255, 209, 102, 0.25) 2px, transparent 3px) 0 0 / 28px 28px,
    var(--cream);
}

#app {
  max-width: 500px;
  margin: 0 auto;
  padding: 8px 8px 24px;
}

/* ---------- ボタン ---------- */
.btn {
  font: inherit;
  font-weight: 700;
  min-height: 44px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(43, 38, 51, 0.12); }
.btn.primary { background: var(--coral); color: #fff; border-color: var(--coral-d); text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15); }
.btn.big { min-height: 56px; font-size: 1.15rem; width: 100%; }
.btn.small { min-height: 44px; padding: 6px 14px; font-size: 0.95rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible + span {
  outline: 3px solid #2f6fdf;
  outline-offset: 2px;
}

/* ---------- 開始画面 ---------- */
.start { text-align: center; padding-top: 4vh; }
.logo-wrap { display: flex; align-items: center; justify-content: center; gap: 10px; }
.logo-mark { width: 56px; height: 56px; }
.logo {
  margin: 0;
  font-size: clamp(2rem, 9vw, 2.8rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: var(--coral);
  text-shadow: 3px 3px 0 var(--sun);
}
.logo span { color: var(--mint-d); }
.lead { margin: 12px 0 20px; color: var(--ink-soft); }
.sub { color: var(--ink-soft); font-size: 0.9rem; margin: 6px 0; }

.diff-picker {
  border: 0;
  padding: 0;
  margin: 0 0 18px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.diff-picker legend { font-weight: 700; margin: 0 auto 8px; }
.diff { position: relative; }
.diff input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.diff span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--paper);
  font-weight: 700;
  box-shadow: var(--shadow);
}
.diff input:checked + span { border-color: var(--ink); background: var(--mint-l); }
.diff input:checked + span::before { content: "✓ "; white-space: pre; }
.diff.normal input:checked + span { background: #fff1c2; }
.diff.hard input:checked + span { background: var(--coral-l); }
.diff-picker.compact span { min-height: 46px; font-size: 0.95rem; }

.start-actions { display: grid; gap: 10px; }
.start-sub { display: flex; gap: 10px; justify-content: center; margin: 18px 0 8px; }
.error-box { background: var(--coral-l); border: 2px solid var(--coral-d); border-radius: var(--radius); padding: 10px; text-align: left; }
.foot { margin-top: 18px; font-size: 0.85rem; }
.foot a { color: var(--mint-d); }

/* ---------- プレイ画面 ---------- */
.topbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}
.tbtn {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  min-height: 48px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.85);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  touch-action: manipulation;
  padding: 2px;
}
.tbtn .ic { font-size: 1.05rem; line-height: 1; }
.tbtn[aria-pressed="true"] { background: var(--mint-l); border-color: var(--mint-d); }

.info { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 6px; }
.chip {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--mint-l);
  border: 2px solid var(--mint-d);
  font-variant-numeric: tabular-nums;
}
.chip.normal { background: #fff1c2; border-color: #a57a00; }
.chip.hard { background: var(--coral-l); border-color: var(--coral-d); }
.chip.ghost { background: rgba(255, 253, 248, 0.85); border-color: var(--line); }

.banner { border-radius: var(--radius); padding: 8px 12px; margin-bottom: 6px; font-size: 0.9rem; }
.banner.warn { background: var(--coral-l); border: 2px solid var(--coral-d); }
.banner.won { background: #fff1c2; border: 2px solid #a57a00; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.banner-actions { display: flex; gap: 8px; margin-left: auto; }

/* 盤面 */
.board-wrap { display: flex; justify-content: center; }
.board {
  width: min(100%, 460px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--paper);
  border: 3px solid var(--line-strong);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 6px 0 rgba(43, 38, 51, 0.15);
}
.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  margin: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n + 73) { border-bottom: 0; }
.cell.br { border-right: 2.5px solid var(--line-strong); }
.cell.bb { border-bottom: 2.5px solid var(--line-strong); }
.cell .v { font-size: clamp(1.15rem, 5.6vw, 1.7rem); line-height: 1; }
.cell.fixed .v { font-weight: 800; color: var(--ink); }
.cell.user .v { font-weight: 500; color: var(--mint-d); }
.cell.area { background: var(--area); }
.cell.same { background: var(--same); box-shadow: inset 0 0 0 2px var(--mint); }
.cell.sel { background: var(--sel); box-shadow: inset 0 0 0 3px #e0a100; }
.cell:focus-visible { outline: 3px solid #2f6fdf; outline-offset: -3px; z-index: 1; }
.cell.conflict { background-image: repeating-linear-gradient(135deg, rgba(255, 122, 102, 0.22) 0 4px, transparent 4px 8px); }
.cell.conflict::after {
  content: "";
  position: absolute;
  inset: 2px;
  border: 2px dashed var(--coral-d);
  border-radius: 4px;
  pointer-events: none;
}
.cell.conflict .v { color: var(--coral-d); }
.cell .mark {
  position: absolute;
  top: 1px;
  right: 2px;
  font-size: 0.62rem;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  background: var(--coral-d);
  border-radius: 999px;
  padding: 1px 4px;
}
.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 1px;
}
.notes span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.5rem, 2.4vw, 0.72rem);
  line-height: 1;
  color: var(--ink-soft);
  font-weight: 600;
}
.board.celebrate { animation: pop 0.6s ease-out; }
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.04) rotate(-0.6deg); }
  100% { transform: scale(1); }
}

.mode-line { text-align: center; margin: 8px 0 6px; font-size: 0.9rem; color: var(--ink-soft); }
.mode-line strong { color: var(--ink); }
.mode-line strong.memo { color: var(--mint-d); }

/* 数字ボタン（5＋4） */
.pad {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  margin: 0 auto 8px;
  max-width: 460px;
}
.num {
  grid-column: span 2;
  font: inherit;
  min-height: 52px;
  border-radius: var(--radius);
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
}
.num:nth-child(6) { grid-column: 2 / span 2; }
.num .d { font-size: 1.5rem; font-weight: 800; }
.num:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(43, 38, 51, 0.12); }
.pad.note-mode .num { background: var(--mint-l); border-style: dashed; border-color: var(--mint-d); }
.pad.note-mode .num .d { font-size: 1.1rem; color: var(--mint-d); }

.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-width: 460px; margin: 0 auto; }
.tool {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  min-height: 56px;
  border-radius: var(--radius);
  border: 2px solid var(--line-strong);
  background: var(--cream-2);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  touch-action: manipulation;
}
.tool .ic { font-size: 1.15rem; line-height: 1; }
.tool[aria-pressed="true"] { background: var(--mint); border-color: var(--mint-d); color: #08372c; }

/* トースト */
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- ダイアログ ---------- */
.dlg {
  width: min(92vw, 420px);
  max-height: 88vh;
  overflow: auto;
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: var(--paper);
  color: var(--ink);
  padding: 18px 18px 16px;
  box-shadow: 0 8px 0 rgba(43, 38, 51, 0.2);
}
.dlg::backdrop { background: rgba(43, 38, 51, 0.45); }
.dlg.cover::backdrop { background: var(--cream); } /* 一時停止・説明は盤面を隠す */
.dlg h2 { margin: 0 0 10px; font-size: 1.25rem; color: var(--coral-d); }
.dlg-body p { margin: 0 0 8px; }
.dlg-body ul { padding-left: 1.2em; margin: 0 0 8px; }
.dlg-body li { margin-bottom: 6px; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.dlg-actions.col { flex-direction: column; }
.dlg-actions.col .btn { width: 100%; }
.mark-demo { display: inline-block; background: var(--coral-d); color: #fff; border-radius: 999px; padding: 0 6px; font-weight: 900; font-size: 0.8em; }

.clear { text-align: center; position: relative; overflow: hidden; }
.clear h2 { font-size: 1.6rem; color: var(--coral); text-shadow: 2px 2px 0 var(--sun); }
.result { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 4px; }
.result div { background: var(--mint-l); border-radius: 12px; padding: 8px 4px; }
.result dt { font-size: 0.8rem; color: var(--ink-soft); }
.result dd { margin: 0; font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.confetti i {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  background: var(--coral);
  animation: fall 1.6s ease-in forwards;
}
.confetti i:nth-child(2n) { background: var(--mint); }
.confetti i:nth-child(3n) { background: var(--sun); }
.confetti i:nth-child(1) { left: 8%; animation-delay: 0s; }
.confetti i:nth-child(2) { left: 20%; animation-delay: 0.15s; }
.confetti i:nth-child(3) { left: 33%; animation-delay: 0.05s; }
.confetti i:nth-child(4) { left: 46%; animation-delay: 0.25s; }
.confetti i:nth-child(5) { left: 59%; animation-delay: 0.1s; }
.confetti i:nth-child(6) { left: 72%; animation-delay: 0.3s; }
.confetti i:nth-child(7) { left: 84%; animation-delay: 0.2s; }
.confetti i:nth-child(8) { left: 93%; animation-delay: 0.35s; }
@keyframes fall {
  to { transform: translateY(420px) rotate(320deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .board.celebrate { animation: none; }
  .confetti { display: none; }
  .toast { transition: none; }
}

@media (min-width: 700px) {
  #app { padding-top: 16px; }
}
