* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: #E0E0E0;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  color: #1C1B1F;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
.hidden { display: none !important; }

/* ---------- 全体 ---------- */
#app {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- アプリバー ---------- */
#appbar {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px 0 16px;
  background: #F7F2FA;
}
#appbar h1 { font-size: 22px; font-weight: 400; }
.appbar-actions { display: flex; }
.icon-btn { width: 48px; height: 48px; font-size: 22px; border-radius: 50%; }
.icon-btn:hover { background: rgba(0, 0, 0, 0.06); }

/* ---------- ヒントバナー・結果表示 ---------- */
#hint-banner {
  background: #FFA000; color: #fff;
  font-size: 12px; font-weight: bold; text-align: center;
  padding: 6px 12px; cursor: pointer; flex-shrink: 0;
}
#result-msg {
  margin-top: 10px; min-height: 29px; line-height: 29px;
  text-align: center; font-weight: bold; flex-shrink: 0;
}
#result-msg.lose { color: #F44336; font-size: 20px; }
#result-msg.win  { color: #4CAF50; font-size: 24px; }

/* ---------- ステータスパネル ---------- */
#panel {
  margin: 0 20px 10px; padding: 1px 20px;
  background: #BDBDBD; border: 1px solid #757575;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.panel-buttons { display: flex; align-items: center; gap: 8px; }
.panel-buttons .icon-btn { width: auto; height: auto; font-size: 20px; padding: 2px; border-radius: 4px; }
#hint-btn.active { filter: drop-shadow(0 0 4px #FF6D00); }
#hint-btn:disabled { opacity: 0.35; cursor: default; }
#face-btn {
  font-size: 13px; padding: 3px 8px;
  background: #F7F2FA; border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.led {
  background: #000; color: #F44336;
  font: bold 15px/1.2 ui-monospace, Menlo, Consolas, monospace;
  padding: 2px; letter-spacing: 1px;
}

/* ---------- 盤面 ---------- */
#viewport { flex: 1; position: relative; overflow: hidden; touch-action: none; }
#board {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0; will-change: transform;
  display: grid; gap: 2px; padding: 8px;
  background: #BDBDBD;
}
.cell {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: #757575; color: #000;
  font-weight: bold; font-size: 18px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.cell.open { background: #EEEEEE; }
.cell.mine { background: #F44336; }
.n1 { color: #2196F3; } .n2 { color: #4CAF50; } .n3 { color: #F44336; }
.n4 { color: #9C27B0; } .n5 { color: #FF9800; }

/* ---------- 横向き（スマホ横持ち） ---------- */
.landscape-only { display: none !important; }
@media (orientation: landscape) and (max-height: 500px) {
  #appbar { display: none; }
  .landscape-only { display: inline-block !important; }
  #result-msg { margin-top: 0; min-height: 0; line-height: 1.3; }
  #result-msg.lose { font-size: 16px; }
  #result-msg.win  { font-size: 18px; }
  #panel { margin: 0 10px 5px; padding: 1px 15px; }
}

/* ---------- メニュー ---------- */
#menu { position: fixed; inset: 0; z-index: 2000; }
.menu-list {
  position: absolute; min-width: 210px; padding: 8px 0;
  background: #F3EDF7; border-radius: 4px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}
.menu-list button { display: block; width: 100%; text-align: left; padding: 12px 16px; font-size: 15px; }
.menu-list button:hover { background: rgba(0, 0, 0, 0.06); }
.menu-list button.current::after { content: "  ✓"; color: #6750A4; }
.menu-list hr { border: none; border-top: 1px solid #CAC4D0; margin: 8px 0; }

/* ---------- ダイアログ ---------- */
#dialog-backdrop {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.dialog {
  background: #F7F2FA; border-radius: 28px; padding: 24px;
  width: 100%; max-width: 400px; max-height: 90%; overflow: auto;
}
.dialog h2 { font-size: 22px; font-weight: 400; margin-bottom: 16px; }
#dialog-body { font-size: 14px; line-height: 1.7; color: #49454F; }
#dialog-body strong { color: #1C1B1F; }
#dialog-body hr { border: none; border-top: 1px solid #CAC4D0; margin: 10px 0; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.btn-text { color: #6750A4; padding: 10px 12px; border-radius: 20px; font-weight: 500; }
.btn-text:hover { background: rgba(103, 80, 164, 0.08); }
.btn-primary { background: #6750A4; color: #fff; padding: 10px 20px; border-radius: 20px; font-weight: 500; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: #6750A4; }
.field input {
  width: 100%; font-size: 16px; padding: 6px 0;
  border: none; border-bottom: 1px solid #79747E; background: transparent; outline: none;
}
.field input:focus { border-bottom: 2px solid #6750A4; }
input[type="range"] { width: 100%; margin: 8px 0; }
.note { font-size: 12px; color: #9E9E9E; }

/* ---------- スナックバー ---------- */
#snackbar {
  position: absolute; left: 50%; bottom: 16px; z-index: 10;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #313033; color: #F4EFF4;
  padding: 14px 16px; border-radius: 4px; font-size: 14px;
  width: max-content; max-width: calc(100% - 32px);
  transition: opacity 0.2s, transform 0.2s;
}
#snackbar.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 広告 ---------- */
.ad-side { position: fixed; top: 50%; transform: translateY(-50%); width: 160px; z-index: 5; }
.ad-side.left { left: 10px; }
.ad-side.right { right: 10px; }
body.has-side-ads #app { left: 180px; right: 180px; }

/* スマホ用インライン広告（盤面との間を空けて誤タップを防ぐ） */
#ad-sp-inline {
  flex-shrink: 0;
  min-height: 50px;
  margin-top: 12px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  width: 100%;
}
/* 広告の下にできる数pxの隙間をなくす */
#ad-sp-inline iframe,
#ad-sp-inline img {
  display: block;
  vertical-align: bottom;
}
/* 画面下のホームバー用の余白をなくし、広告を一番下に寄せる */
#app { padding-bottom: 0; }


