/* mweeper — スタイル（Cairn Design System 準拠） */
:root {
  --bg: #f2f2ef;
  --card: #ffffff;
  --fg: #1b1b1d;
  --sub: #a3a3a6;
  --sub2: #c6c6c8;
  --hairline: #e7e7e4;
  --pill: #4a4a4c;
  --toolbar: #3d3d3f;
  --toolbar-hi: #59595c;
  --red: #e5484d;
  --blue: #2f6bff;
  --green: #38b26f;
  --tile: #dededa;
  --tile-hi: #e9e9e5;
  /* 浮いている部品（ツールバー・トースト・名前の札）。
     ライトモードは Safari の下のバー（ページからは色を変えられない）と同じグレーにそろえる */
  --float-bg: #474745;
  --float-fg: #f2f2ef;
  --float-hi: #62625f;
  --float-shadow: 0 6px 20px rgba(0,0,0,0.16);
  /* 決定ボタン。ライトモードはライトグレー */
  --primary-bg: #b9b9b4;
  --primary-fg: #1b1b1d;
  --toggle-on: #8e8e93;
  --logo-bg: #c6c6c1;
  --logo-fg: #84847f;
  --open: #f8f8f6;
  --open-line: #e3e3df;
  --sheet-r: 22px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

.theme-dark {
  --bg: #161618;
  --card: #232326;
  --fg: #ececee;
  --sub: #86868a;
  --sub2: #5a5a5e;
  --hairline: #313134;
  --pill: #4a4a4c;
  --toolbar: #2c2c2e;
  --toolbar-hi: #4c4c50;
  --tile: #2b2b2e;
  --tile-hi: #343437;
  --float-bg: #2c2c2e;
  --float-fg: #ffffff;
  --float-hi: #4c4c50;
  --float-shadow: 0 8px 24px rgba(0,0,0,0.28);
  --primary-bg: #ececee;
  --primary-fg: #161618;
  --toggle-on: #ececee;
  --logo-bg: #111113;
  --logo-fg: #d8d6d0;
  --open: #1c1c1f;
  --open-line: #2a2a2d;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--bg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  /* 長押しで「ペースト・選択」などのメニューや拡大鏡を出さない */
  -webkit-touch-callout: none;
}
canvas { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font: inherit; color: var(--fg); }
.hidden { display: none !important; }

#app {
  height: 100dvh;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-top: calc(10px + env(safe-area-inset-top));
}

/* ---------- ブランドタグ ---------- */
.brand-tag {
  position: absolute;
  top: calc(4px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--sub);
  z-index: 6;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.brand-dot { width: 9px; height: 9px; border-radius: 3px; background: var(--sub2); display: inline-block; }

/* ---------- ヘッダー ---------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px 6px;
  min-height: 56px;
  flex-shrink: 0;
  z-index: 5;
}
.title-wrap { min-width: 0; }
.page-title {
  font-size: 27px;
  font-weight: 800;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-align: left;
}
.page-header { cursor: pointer; }
.page-header:active .title-wrap { opacity: 0.55; }
.stat-line { font-size: 12px; color: var(--sub); margin-top: 1px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat-line b { color: var(--fg); font-weight: 700; }
/* まだ地雷の回数を数えていない間は、少し沈んだ色 */
.stat-line .muted { opacity: 0.45; }

.header-pill {
  background: var(--pill);
  border-radius: 999px;
  display: flex;
  align-items: center;
  padding: 4px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.12);
  flex-shrink: 0;
}
.pill-icon { width: 42px; height: 36px; display: grid; place-items: center; border-radius: 999px; }
.pill-icon svg { width: 19px; height: 19px; stroke: #fff; }
.pill-icon:active { opacity: 0.6; }

/* ---------- 盤面 ---------- */
.board-wrap { flex: 1; position: relative; overflow: hidden; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
#board.grabbing { cursor: grabbing; }
.coord-chip {
  position: absolute;
  left: 20px;
  bottom: calc(96px + env(safe-area-inset-bottom));
  font-size: 11px;
  color: var(--sub);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.conn-chip {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--sub);
  background: var(--card);
  padding: 4px 12px;
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.07);
  pointer-events: none;
}

/* ---------- ツールバー ---------- */
.toolbar {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: 524px;
  margin: 0 auto;
  background: var(--float-bg);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  box-shadow: var(--float-shadow);
  z-index: 10;
}
.tb-btn {
  width: 58px;
  height: 48px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  position: relative;
  transition: background 0.25s ease, transform 0.12s;
}
.tb-btn:active { transform: scale(0.9); }
.tb-btn svg { width: 21px; height: 21px; stroke: var(--float-fg); opacity: 0.95; }
.tb-btn.active { background: var(--float-hi); }
.tb-btn.active svg { fill: rgba(127,127,127,0.18); }
.tb-btn .dot {
  position: absolute;
  top: 8px;
  right: 11px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

/* ---------- オーバーレイ ---------- */
.dim { position: fixed; inset: 0; background: rgba(0,0,0,0.22); z-index: 30; animation: fade-in 0.18s ease; }
.dim.clear { background: transparent; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { transform: scale(0.7); opacity: 0; } to { transform: none; opacity: 1; } }

.ctx-menu {
  position: fixed;
  z-index: 35;
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 10px 36px rgba(0,0,0,0.16);
  padding: 5px;
  min-width: 220px;
  animation: pop-in 0.18s var(--ease);
  transform-origin: top right;
}
.ctx-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  font-size: 14.5px;
  border-radius: 9px;
  text-align: left;
}
.ctx-row:active { background: var(--bg); }
.ctx-row .ic { width: 18px; height: 18px; display: grid; place-items: center; }
.ctx-row .ic svg { width: 16px; height: 16px; stroke: var(--fg); }
.ctx-row.danger { color: var(--red); }
.ctx-sep { border-top: 1px solid var(--hairline); margin: 4px 10px; }

/* ボトムシート */
.sheet {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border-radius: var(--sheet-r) var(--sheet-r) 0 0;
  z-index: 34;
  padding: 16px 20px calc(24px + env(safe-area-inset-bottom));
  animation: sheet-up 0.3s var(--ease);
  max-height: 86dvh;
  overflow-y: auto;
  -webkit-user-select: text;
  user-select: text;
}
@keyframes sheet-up { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.sheet-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg);
  display: grid;
  place-items: center;
  transition: transform 0.12s;
  z-index: 1;
}
.sheet-close:active { transform: scale(0.9); }
.sheet-close svg { width: 16px; height: 16px; stroke: var(--fg); }
.theme-dark .sheet-close { background: #1c1c1f; }
.sheet-body { padding-top: 6px; }
.sheet h2 { font-size: 17px; font-weight: 700; text-align: center; margin-bottom: 14px; }
.sheet .hint { font-size: 12.5px; color: var(--sub); line-height: 1.7; text-align: center; margin-top: 12px; }
.sheet .sec { font-size: 13px; font-weight: 700; color: var(--sub); padding: 14px 2px 6px; }
.sheet .empty { color: var(--sub); text-align: center; padding: 26px 0; font-size: 14px; }

/* ランキング行 */
.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 2px;
  font-size: 16.5px;
}
.rank-row + .rank-row { border-top: 1px solid var(--hairline); }
.rank-row .rank { width: 26px; color: var(--sub); font-size: 13px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.rank-row .avatar { width: 21px; height: 21px; border-radius: 50%; flex-shrink: 0; position: relative; }
.rank-row .avatar.off { opacity: 0.35; }
.rank-row .avatar .on { position: absolute; right: -2px; bottom: -2px; width: 8px; height: 8px; border-radius: 50%; background: var(--green); border: 2px solid var(--card); }
.rank-row .body { flex: 1; min-width: 0; }
.rank-row .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row.me .name { font-weight: 800; }
.rank-row .meta { font-size: 12px; color: var(--sub); margin-top: 2px; }
.rank-row .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.rank-row .pts small { font-size: 11px; color: var(--sub); font-weight: 500; margin-left: 2px; }
.rank-row .go {
  background: var(--primary-bg);
  color: var(--primary-fg);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  padding: 7px 13px;
  transition: transform 0.12s;
}
.rank-row .go:active { transform: scale(0.92); }

/* 設定カード */
.set-card { background: var(--bg); border-radius: 18px; overflow: hidden; margin-bottom: 12px; }
.theme-dark .set-card { background: #1c1c1f; }
.set-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  font-size: 15px;
  text-align: left;
  position: relative;
}
.set-row + .set-row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--hairline); }
.set-row .grow { flex: 1; }
.set-row .val { color: var(--sub); font-size: 13.5px; }
.set-row .chev-r { color: var(--sub2); font-size: 16px; }
.set-row .sub-l { display: block; font-size: 12px; color: var(--sub); margin-top: 2px; }

.toggle {
  width: 46px; height: 28px; border-radius: 999px; background: var(--sub2);
  position: relative; transition: background 0.2s; flex-shrink: 0; display: inline-block;
}
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: transform 0.2s var(--ease);
}
.toggle.on { background: var(--toggle-on); }
.toggle.on::after { transform: translateX(18px); }

.seg { background: rgba(0,0,0,0.055); border-radius: 999px; padding: 3px; display: inline-flex; }
.theme-dark .seg { background: rgba(255,255,255,0.08); }
.seg button { font-size: 12.5px; padding: 6px 13px; border-radius: 999px; color: var(--sub); transition: background 0.2s, color 0.2s, box-shadow 0.2s; }
.seg button.on { background: var(--card); color: var(--fg); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,0.12); }

/* 遊び方 */
.howto { font-size: 14.5px; line-height: 1.7; }
.howto .item { display: flex; gap: 12px; padding: 9px 0; }
.howto .item + .item { border-top: 1px solid var(--hairline); }
.howto .k { flex-shrink: 0; width: 76px; font-weight: 700; font-size: 13px; padding-top: 2px; }
.howto .d { flex: 1; color: var(--fg); }
.howto .d small { color: var(--sub); display: block; font-size: 12.5px; }

/* ダイアログ */
.ml-alert {
  position: fixed;
  left: 50%; top: 50%;
  translate: -50% -50%;
  width: calc(100% - 60px);
  max-width: 330px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.22);
  padding: 22px 20px 16px;
  z-index: 40;
  animation: pop-in 0.2s var(--ease);
}
.ml-alert .ttl { font-size: 17px; font-weight: 800; text-align: center; margin-bottom: 6px; }
.ml-alert .msg { font-size: 14.5px; line-height: 1.65; margin-bottom: 16px; text-align: center; color: var(--sub); }
.ml-alert .field {
  width: 100%; background: var(--bg); border: none; border-radius: 10px;
  padding: 12px 14px; outline: none; font-size: 16px; margin-bottom: 8px; text-align: center;
}
.ml-alert .a-btn {
  display: block; width: 100%; padding: 12px; border-radius: 12px; font-size: 14.5px;
  margin-top: 8px; background: var(--bg); text-align: center; transition: transform 0.12s;
}
.ml-alert .a-btn:active { transform: scale(0.97); }
.ml-alert .a-btn.primary { background: var(--primary-bg); color: var(--primary-fg); font-weight: 700; }
.ml-alert .a-btn.warn { color: var(--red); background: rgba(229,72,77,0.08); }
.ml-alert .a-row { display: flex; gap: 10px; }
.ml-alert .a-row .a-btn { flex: 1; }
/* 初回のチュートリアル */
.tut .tut-view { overflow: hidden; margin: 0 -20px; padding: 0 20px; touch-action: pan-y; }
.tut .tut-slide { will-change: transform; }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 200; }
.tut .tut-pic { position: relative; display: flex; justify-content: center; margin: 4px 0 14px; }
.tut .tut-board { max-width: 100%; height: auto; }
.tut .tut-bulb { position: absolute; right: 14px; bottom: -6px; width: 36px; height: 36px; border-radius: 50%; background: var(--float-bg); display: grid; place-items: center; box-shadow: var(--float-shadow); }
.tut .tut-bulb svg { width: 20px; height: 20px; stroke: var(--float-fg); }
.tut .msg { min-height: 48px; }
.tut-dots { display: flex; justify-content: center; gap: 6px; margin: -4px 0 6px; }
.tut-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--sub2); }
.tut-dots span.on { background: var(--fg); }
.ml-alert .pebble { width: 56px; height: 56px; border-radius: 16px; background: var(--logo-bg); margin: 0 auto 14px; display: grid; place-items: center; }
.ml-alert .pebble svg rect, .ml-alert .pebble svg circle { fill: var(--logo-fg); }
.ml-alert .pebble svg { width: 34px; height: 34px; }

/* トースト */
.toast {
  position: fixed;
  bottom: calc(100px + env(safe-area-inset-bottom));
  left: 50%;
  translate: -50% 0;
  background: var(--float-bg);
  color: var(--float-fg);
  box-shadow: var(--float-shadow);
  font-size: 13px;
  padding: 10px 20px;
  border-radius: 999px;
  z-index: 100;
  width: max-content;
  max-width: calc(100% - 40px);
  text-align: center;
  line-height: 1.5;
  white-space: pre-line;
  animation: pop-in 0.2s ease;
  pointer-events: none;
}
.toast.good { background: rgba(56,178,111,0.95); color: #fff; }
.toast.bad { background: rgba(229,72,77,0.95); color: #fff; }
/* スペシャルエリアを埋めたとき: 水色のきらきらした札が弾む */
.toast.special {
  background: linear-gradient(120deg, #3bb5e8, #7fd3f5 45%, #3bb5e8);
  color: #fff; font-size: 16px; font-weight: 800; padding: 12px 26px;
  box-shadow: 0 8px 26px rgba(59,181,232,0.45), 0 0 0 1px rgba(255,255,255,0.4) inset;
  animation: special-pop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes special-pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- テーマカラー・線の色の選択 ---------- */
.swatches { display: grid; grid-template-columns: repeat(6, 30px); gap: 10px 12px; justify-content: center; margin: 2px 0 6px; }
#s-line.swatches { display: flex; flex-wrap: nowrap; justify-content: space-between; gap: 8px; padding: 4px; }
/* 設定のテーマカラーも、線の色と同じく横幅いっぱいに均等に並べる */
#s-color.swatches { justify-content: space-between; padding: 4px; }
/* 狭い画面でも一列に収まるよう、丸を少しだけ小さくする */
#s-line .sw { width: auto; height: auto; flex: 0 1 30px; min-width: 0; aspect-ratio: 1; }
.sw-name { font-size: 12.5px; color: var(--sub); text-align: center; min-height: 18px; margin-bottom: 12px; }
.set-row .sw-name { text-align: left; margin: -4px 0 0; }
.set-row .swatches { justify-content: flex-start; margin: 0; }
.sw {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
  transition: transform 0.12s, box-shadow 0.15s;
}
.sw:active { transform: scale(0.88); }
.sw.on { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--fg); }
.sw.auto { background: linear-gradient(135deg, var(--sub2) 0 50%, var(--hairline) 50% 100%); }
.set-row.col { flex-direction: column; align-items: stretch; gap: 10px; }
.sw-label { font-size: 13px; font-weight: 700; text-align: center; margin: 6px 0 10px; }
.sw-label small { display: block; font-weight: 400; color: var(--sub); font-size: 11.5px; margin-top: 2px; }
.me-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

/* ---------- コメント ---------- */
.cm-now { font-size: 13px; color: var(--fg); background: var(--bg); border-radius: 10px; padding: 8px 12px; margin: -6px 0 12px; text-align: center; }
.cm-count { font-size: 11.5px; color: var(--sub); text-align: right; margin: -2px 2px 8px; font-variant-numeric: tabular-nums; }
.cm-warn { font-size: 12.5px; color: var(--red); text-align: center; margin-bottom: 4px; }
.ml-alert .a-btn:disabled { opacity: 0.4; }
.ml-alert .field:disabled { opacity: 0.5; }

/* ---------- アカウントリセット ---------- */
.set-row.danger { color: var(--red); }
.reset-list { font-size: 13px; line-height: 1.6; color: var(--fg); margin: -6px 0 16px 18px; }
.reset-list li + li { margin-top: 4px; }

/* ---------- 引き継ぎコード ---------- */
.ml-alert .a-btn.link { background: none; color: var(--sub); font-size: 13.5px; margin-top: 4px; }
.ml-alert .field.code { font-size: 22px; letter-spacing: 3px; font-weight: 700; font-variant-numeric: tabular-nums; text-transform: uppercase; }
.code-val { font-weight: 700; color: var(--fg) !important; letter-spacing: 1px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- 招待（QR コード） ---------- */
.qr-wrap { display: flex; justify-content: center; margin: 4px 0 12px; }
.qr { width: min(72vw, 280px); height: auto; border-radius: 14px; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,0.08); }
.invite-url { font-size: 13px; text-align: center; margin: 6px 0 14px; font-variant-numeric: tabular-nums; word-break: break-all; }
.invite-actions { gap: 10px; }
.sheet .a-btn { display: block; width: 100%; padding: 12px; border-radius: 12px; font-size: 14.5px; background: var(--bg); text-align: center; transition: transform 0.12s; }
.sheet .a-btn:active { transform: scale(0.97); }
.sheet .a-btn.primary { background: var(--primary-bg); color: var(--primary-fg); font-weight: 700; }
.sheet .a-row { display: flex; gap: 10px; }
.sheet .a-row .a-btn { flex: 1; }
.invite-btn { display: inline-block !important; width: auto !important; margin-top: 14px; padding: 10px 20px !important; }

.cm-view { font-size: 18px; font-weight: 600; text-align: center; line-height: 1.5; padding: 14px 8px 18px; word-break: break-all; }
