/* おえかき (Picross / Nonogram) */

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #333;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* スクリーン */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen--active { display: flex; }

/* トップバー */
.top-bar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 10px;
  color: white;
  flex-wrap: wrap;
}
.top-bar__title {
  flex: 1;
  font-size: 20px;
  font-weight: 800;
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn {
  padding: 8px 14px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.4);
  font-size: 15px;
  font-weight: 700;
  color: white;
  background: rgba(255,255,255,0.15);
  cursor: pointer;
  touch-action: manipulation;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:active { transform: scale(0.96); }
.btn--small { padding: 6px 12px; font-size: 13px; }

.foot-note {
  padding: 20px 16px 40px;
  color: rgba(255,255,255,0.8);
  text-align: center;
  font-size: 13px;
}

/* ワールド選択 */
.world-list {
  padding: 8px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.world-tile {
  background: rgba(255,255,255,0.96);
  border-radius: 20px;
  padding: 18px 20px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s;
}
.world-tile:active { transform: scale(0.98); }
.world-tile__title {
  font-size: 22px;
  font-weight: 900;
  color: #2b1f5b;
}
.world-tile__subtitle {
  font-size: 14px;
  margin-top: 4px;
  color: #666;
}
.world-tile__progress {
  font-size: 13px;
  margin-top: 10px;
  color: #444;
  font-weight: 700;
}
.world-tile__progress .num-done {
  color: #22c55e;
  font-size: 18px;
}

/* パズル選択 */
.puzzle-grid {
  padding: 8px 16px 40px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 12px;
}
.puzzle-tile {
  position: relative;
  background: rgba(255,255,255,0.96);
  border-radius: 16px;
  padding: 14px 6px 10px;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 3px 8px rgba(0,0,0,0.14);
  min-height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.puzzle-tile:active { transform: scale(0.97); }
.puzzle-tile__emoji {
  font-size: 34px;
  line-height: 1;
}
.puzzle-tile__name {
  font-size: 13px;
  margin-top: 6px;
  font-weight: 800;
  color: #333;
}
.puzzle-tile__num {
  font-size: 11px;
  color: #888;
  margin-top: 3px;
  font-weight: 700;
}
.puzzle-tile--locked {
  opacity: 0.55;
  cursor: default;
}
.puzzle-tile--cleared::after {
  content: "✓";
  position: absolute;
  top: 6px;
  right: 8px;
  color: #22c55e;
  font-weight: 900;
  font-size: 20px;
  text-shadow: 0 0 3px white;
}
.puzzle-tile__icon-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
}

/* ドット絵ミニアイコン (面のグリッドをそのまま縮小表示) */
.mini-grid {
  display: grid;
  gap: 1px;
  background: #d5d5d5;
  padding: 2px;
  border-radius: 3px;
  line-height: 0;
}
.mini-cell {
  width: var(--mini-cell, 6px);
  height: var(--mini-cell, 6px);
  background: #f5f5f5;
  border-radius: 1px;
}
.mini-cell--on {
  background: #2b1f5b;
}

/* プレイ画面 */
.play-controls {
  padding: 0 12px 10px;
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}
.mode-btn {
  padding: 9px 14px;
  border-radius: 14px;
  border: 3px solid rgba(255,255,255,0.4);
  font-size: 14px;
  font-weight: 800;
  color: white;
  background: rgba(255,255,255,0.15);
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  gap: 6px;
}
.mode-btn__icon {
  font-size: 18px;
  font-weight: 900;
  display: inline-block;
  width: 20px;
  text-align: center;
  color: white;
}
.mode-btn:active { transform: scale(0.96); }
.mode-btn--active {
  background: white;
  border-color: white;
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
  color: #2b1f5b;
}
/* モードごとにアイコン色を変えて「何色を塗るか」が非アクティブでも分かるように */
.mode-btn[data-mode="fill"].mode-btn--active .mode-btn__icon { color: #2b1f5b; }
.mode-btn[data-mode="tentative"] .mode-btn__icon { color: #7bb0ff; }
.mode-btn[data-mode="tentative"].mode-btn--active { color: #1d4ed8; }
.mode-btn[data-mode="tentative"].mode-btn--active .mode-btn__icon { color: #3b82f6; }
.mode-btn[data-mode="cross"].mode-btn--active { color: #444; }
.mode-btn[data-mode="cross"].mode-btn--active .mode-btn__icon { color: #666; }

.board-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px 24px;
  position: relative;
  min-height: 0;
}
.board-frame {
  background: rgba(255,255,255,0.98);
  border-radius: 18px;
  padding: 6px;
  box-shadow: 0 8px 26px rgba(0,0,0,0.3);
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  gap: 4px;
  max-width: 100%;
}

.hint-corner { grid-column: 1; grid-row: 1; }
.hint-top {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  gap: 2px;
  align-items: end;
}
.hint-left {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  gap: 2px;
  justify-items: end;
}
.board {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  gap: 2px;
}

.hint-top__col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 3px;
  gap: 3px;
  min-height: 40px;
}
.hint-left__row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  padding-right: 4px;
  gap: 3px;
  min-width: 40px;
}
.hint-num {
  font-size: var(--hint-font, 14px);
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: calc(var(--hint-font, 14px) + 6px);
  min-height: calc(var(--hint-font, 14px) + 6px);
  padding: 2px 3px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fef3c7;
  border: 1px solid #f5c445;
  border-radius: 5px;
  color: #6b4a19;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.hint-num--zero {
  background: #f2f2f2;
  border-color: #dedede;
  color: #bbb;
  font-weight: 500;
  box-shadow: none;
}

.cell {
  background: #eaeaea;
  border-radius: 3px;
  touch-action: none;
  position: relative;
  cursor: pointer;
  width: var(--cell-size, 40px);
  height: var(--cell-size, 40px);
}
.cell--filled {
  background: #2b1f5b;
}
.cell--tentative {
  background: #3b82f6;
}
.cell--crossed::after {
  content: "×";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  font-size: calc(var(--cell-size, 40px) * 0.7);
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
}

/* 5マスごとの区切り (10x10 用) */
.cell.sep-r { margin-right: 4px; }
.cell.sep-b { margin-bottom: 4px; }
.hint-top__col.sep-r { margin-right: 4px; }
.hint-left__row.sep-b { margin-bottom: 4px; }

/* クリアオーバーレイ — 上部の操作パネル位置に降ってきて置き換わる */
.clear-overlay {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: auto;
  background: transparent;
  display: none;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: calc(env(safe-area-inset-top) + 60px) 16px 0;
  pointer-events: none;
}
.clear-overlay--active {
  display: flex;
}
.clear-card {
  background: white;
  border-radius: 20px;
  padding: 12px 18px 12px;
  min-width: 280px;
  max-width: 92vw;
  pointer-events: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35), 0 0 0 3px rgba(34, 197, 94, 0.3);
  animation: slideDown 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: grid;
  grid-template-columns: auto auto 1fr;
  grid-template-areas:
    "emoji title name"
    "btns  btns  btns";
  align-items: center;
  column-gap: 10px;
  row-gap: 10px;
}
@keyframes slideDown {
  0% { transform: translateY(-160%); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
.clear-card__emoji {
  grid-area: emoji;
  font-size: 36px;
  line-height: 1;
}
.clear-card__title {
  grid-area: title;
  font-size: 22px;
  font-weight: 900;
  color: #22c55e;
  line-height: 1;
  white-space: nowrap;
}
.clear-card__name {
  grid-area: name;
  font-size: 15px;
  color: #444;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}
.clear-card__btns {
  grid-area: btns;
  display: flex;
  gap: 10px;
  padding-top: 4px;
  border-top: 1px solid #eee;
}
.clear-card__btn {
  flex: 1;
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
.clear-card__btn:active { transform: scale(0.96); }
.clear-card__btn--primary {
  background: #22c55e;
  color: white;
  box-shadow: 0 3px 10px rgba(34, 197, 94, 0.4);
}
.clear-card__btn--secondary {
  background: #eee;
  color: #333;
}
