/* Fullerene Reversi — 緑のフェルトに銀の分子模型、黒曜石と真珠の石 */
:root {
  --felt-1: #1f9a5e;
  --felt-2: #0f5a36;
  --felt-3: #06281a;
  --silver: #d9dde1;
  --silver-dim: #9aa4ab;
  --gold: #e9c46a;
  --gold-2: #b98a2e;
  --emerald: #2ee88a;
  --pink: #ff5fa8;
  --ink: #f4f7f5;
  --ink-dim: #b7c9bf;
  --panel: rgba(6, 26, 17, 0.72);
  --panel-line: rgba(217, 221, 225, 0.22);
  --bar-h: 36px;
  --radius: 14px;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Hiragino Sans", "Segoe UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: #04160e;
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }

#site-bar {
  height: var(--bar-h);
  padding: 0 max(12px, env(safe-area-inset-left)) 0 max(12px, env(safe-area-inset-right));
  padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
  display: flex; align-items: center; justify-content: space-between;
  background: #030f09; border-bottom: 1px solid #10301f;
  font-size: 13px;
}
#site-bar a { color: #8fd9b2; text-decoration: none; }
#site-bar a:hover { text-decoration: underline; }
#site-bar .links a + a { margin-left: 14px; }

#layout {
  display: flex; justify-content: center; align-items: stretch; gap: 16px;
  height: calc(100dvh - var(--bar-h) - env(safe-area-inset-top));
}
/* 両脇の広告枠。ステージの横に空いた幅（最大 300px）を使う。160px 未満なら出さない（index.html の mountSideAds） */
.ad-rail {
  display: none; flex-shrink: 0; align-self: center;
  width: clamp(0px, calc((100vw - min(100vw, (100dvh - var(--bar-h)) * 0.62)) / 2 - 28px), 300px);
  height: min(600px, calc(100dvh - var(--bar-h) - 40px));
}
@media (min-width: 900px) { .ad-rail { display: block; } }

/* ── ステージ（縦持ち比率。PC では中央に置く） ── */
/* 高さは画面から直接決める。広告枠を差し込むと AdSense が #layout に height:auto !important を
   書き込むため、親の高さに対する % だとステージが 0 になる（PC の横長画面で盤が消えていた） */
#stage {
  position: relative;
  container-type: inline-size;
  width: min(100vw, calc((100dvh - var(--bar-h)) * 0.62));
  min-width: min(100vw, 360px);
  height: calc(100dvh - var(--bar-h) - env(safe-area-inset-top));
  flex-shrink: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% 42%, var(--felt-1) 0%, var(--felt-2) 55%, var(--felt-3) 100%);
  box-shadow: inset 0 0 0 1px rgba(217, 221, 225, 0.18), inset 0 0 80px rgba(0, 0, 0, 0.45);
  user-select: none; -webkit-user-select: none;
}
@media (min-width: 700px) {
  #stage { border-radius: 18px; margin: 10px 0; height: calc(100dvh - var(--bar-h) - env(safe-area-inset-top) - 20px);
    box-shadow: 0 0 0 3px #7d868c, 0 0 0 5px #3b4246, 0 20px 60px rgba(0,0,0,.6), inset 0 0 80px rgba(0,0,0,.45); }
}
/* フェルトの織り目 */
#stage::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .18; mix-blend-mode: overlay;
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.08) 0 1px, transparent 1px 3px),
                    repeating-linear-gradient(-45deg, rgba(0,0,0,.12) 0 1px, transparent 1px 3px);
}
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#stage[data-screen="home"] .play-only { display: none !important; }
#stage[data-screen="play"] .home-only { display: none !important; }

/* ── 対局中の表示 ── */
#hud {
  position: absolute; top: 10px; left: 10px; right: 10px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; pointer-events: none;
}
.player {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 8px 12px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--panel-line);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: box-shadow .25s, border-color .25s, transform .25s;
}
.player.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 18px rgba(233,196,106,.45); transform: translateY(-1px); }
.player .dot, .dot { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; display: inline-block; vertical-align: -3px; }
img.dot.skin { object-fit: cover; box-shadow: 0 1px 2px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.25); }
.player img.dot.skin { width: 22px; height: 22px; }
.p-black .dot, .dot.b { background: radial-gradient(circle at 35% 30%, #6b6f78 0%, #16171b 45%, #000 100%); box-shadow: 0 1px 2px rgba(0,0,0,.6); }
.p-white .dot, .dot.w { background: radial-gradient(circle at 35% 30%, #fff 0%, #f1ece2 45%, #c9c0b0 100%); box-shadow: 0 1px 2px rgba(0,0,0,.5); }
.player .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--ink-dim); }
.player .pname small { color: var(--silver-dim); }
.player .pscore { font: 700 22px/1 var(--serif); font-variant-numeric: tabular-nums; }
.player .pscore small { font: 600 11px var(--sans); color: var(--gold); margin-left: 3px; vertical-align: top; }

#clock {
  position: absolute; top: 66px; left: 50%; transform: translateX(-50%);
  padding: 3px 12px; border-radius: 99px; font-size: 13px; font-variant-numeric: tabular-nums;
  background: var(--panel); border: 1px solid var(--panel-line);
}
#clock.urgent { color: #ffb4b4; border-color: #ff6b6b; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .55; } }

#coach {
  position: absolute; top: 64px; left: 10px; right: 10px; z-index: 5;
  padding: 10px 12px; border-radius: 14px;
  background: rgba(20, 16, 4, .9); border: 1px solid var(--gold); color: #fff6dc;
  box-shadow: 0 10px 30px rgba(0,0,0,.45); animation: pop .25s cubic-bezier(.2,1.4,.4,1);
}
.coach-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--gold); font-weight: 700; }
.coach-skip { font-size: 12px; color: var(--ink-dim); text-decoration: underline; padding: 4px; }
#coach p { margin-top: 4px; font-size: 14px; line-height: 1.6; }
.coach-buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.coach-buttons .btn { min-height: 38px; }
.lang-pick { display: grid; gap: 10px; text-align: center; }
.lang-title { font-size: 16px; margin-bottom: 4px; }
.lang-title small { color: var(--ink-dim); }

#bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px 10px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(3,18,11,.85), rgba(3,18,11,0));
  pointer-events: none;
}
#hint {
  text-align: center; font-size: 13.5px; color: var(--ink); min-height: 1.5em; margin-bottom: 8px;
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
}
#hint.thinking::after { content: ""; display: inline-block; width: 10px; height: 10px; margin-left: 8px; border-radius: 50%;
  border: 2px solid var(--gold); border-right-color: transparent; animation: spin .8s linear infinite; vertical-align: -1px; }
#actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; pointer-events: auto; }

/* ── ボタン ── */
.btn {
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  background: linear-gradient(#2a3a33, #17231e); border: 1px solid var(--panel-line);
  color: var(--ink); font-weight: 600; letter-spacing: .02em;
  box-shadow: 0 2px 0 rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.08);
  transition: transform .08s, filter .15s, opacity .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn.primary {
  background: linear-gradient(#f3d98b, var(--gold) 45%, var(--gold-2)); color: #2a1d05; border-color: #f6e3a8;
  box-shadow: 0 2px 0 #6d4f14, 0 0 18px rgba(233,196,106,.35), inset 0 1px 0 rgba(255,255,255,.6);
}
.btn.ghost { background: rgba(6,26,17,.6); }
.btn.danger { background: linear-gradient(#8a2c2c, #5a1717); border-color: #c26060; }
.btn.big { min-height: 54px; font-size: 18px; width: 100%; margin-top: 6px; }
.btn.icon { min-width: 44px; padding: 0 10px; }
.btn.undo.ad::before { content: "▶"; display: inline-block; font-size: 10px; margin-right: 6px; padding: 2px 5px; border-radius: 4px; background: var(--gold); color: #2a1d05; vertical-align: 2px; }
.link { color: var(--ink-dim); font-size: 14px; padding: 8px 10px; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--ink); }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: 10px; background: rgba(0,0,0,.28); border: 1px solid var(--panel-line); }
.seg button { padding: 6px 10px; min-height: 34px; border-radius: 8px; font-size: 13px; color: var(--ink-dim); }
.seg button[aria-checked="true"] { background: linear-gradient(#e8edf0, #b9c1c6); color: #11201a; font-weight: 700; box-shadow: 0 1px 0 rgba(0,0,0,.4); }

/* ── ホーム ── */
#home { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; padding: 22px 16px max(14px, env(safe-area-inset-bottom)); pointer-events: none; }
#home > * { pointer-events: auto; }
.home-head { text-align: center; pointer-events: none !important; }
/* グラデーション文字＋filter は Safari で文字が消えることがあるため、単色＋影にする */
.logo {
  /* ステージの幅に合わせる（画面幅 vw だと、横長の画面で細いステージからはみ出す） */
  font: 700 clamp(20px, 8vw, 40px)/1.15 var(--serif); letter-spacing: .06em;
  font-size: clamp(18px, 8.4cqw, 40px);
  color: #f3d58a;
  text-shadow: 0 1px 0 #fff3cf, 0 2px 0 #9a6f22, 0 4px 10px rgba(0,0,0,.55);
  white-space: nowrap;
}
.tagline { margin-top: 6px; color: var(--ink-dim); font-size: 13px; text-shadow: 0 1px 2px #000; }
.card {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: var(--radius);
  padding: 12px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; }
.row + .row { border-top: 1px solid rgba(255,255,255,.06); }
.row-label { font-size: 13px; color: var(--ink-dim); white-space: nowrap; }
.home-more { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.home-more .btn.online { display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2; padding: 6px; }
.home-more .btn.online small { font-weight: 400; font-size: 11px; color: var(--gold); }
.home-foot { display: flex; justify-content: center; gap: 8px; margin-top: 4px; }
@media (max-height: 640px) { .tagline { display: none; } #home { padding-top: 12px; } }

/* ── モーダル ── */
#modal {
  position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(2, 10, 6, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade .18s ease-out;
}
.modal-box {
  width: 100%; max-width: 400px; max-height: 100%; overflow: auto;
  background: linear-gradient(#10261b, #081a11); border: 1px solid var(--panel-line); border-radius: 16px;
  padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.06);
  animation: pop .22s cubic-bezier(.2,1.4,.4,1);
}
.modal-box > h2 { font: 700 20px var(--serif); margin-bottom: 12px; color: var(--gold); }
.modal-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-buttons .btn { flex: 1 1 auto; }
.help { white-space: pre-wrap; font-size: 14px; line-height: 1.7; color: var(--ink); }
.menu-list { display: grid; gap: 8px; }
.confirm { white-space: pre-wrap; text-align: center; font-size: 15px; }
.settings .row { padding: 8px 0; }
.settings input[type=range] { width: 50%; accent-color: var(--gold); }

.result { text-align: center; }
.result h2 { font: 800 30px var(--serif); letter-spacing: .04em; margin-bottom: 6px; }
.result.win h2 { color: #f3d58a; text-shadow: 0 2px 0 #9a6f22, 0 4px 10px rgba(0,0,0,.5); }
.result.lose h2 { color: var(--silver-dim); }
.result .reason { display: inline-block; margin-top: 2px; padding: 4px 12px; border-radius: 99px; font-size: 14px; font-weight: 700; color: #fff3cf; background: rgba(233,196,106,.16); border: 1px solid rgba(233,196,106,.45); }
.scores { width: 100%; border-collapse: collapse; margin-top: 12px; font-variant-numeric: tabular-nums; }
.scores th, .scores td { padding: 6px 8px; border-bottom: 1px solid rgba(255,255,255,.07); }
.scores td:first-child { text-align: left; color: var(--ink-dim); font-size: 13px; }
.scores tr.total td { font: 700 20px var(--serif); border-bottom: 0; }
.scores .dot { width: 14px; height: 14px; margin-right: 5px; }
.rating-line { margin-top: 10px; color: var(--gold); font-weight: 600; white-space: pre-line; }

.searching { text-align: center; padding: 4px 0; }
.search-title { font-size: 16px; font-weight: 700; }
.search-title .elapsed { color: var(--gold); font-variant-numeric: tabular-nums; margin-left: 6px; }
.searching .range, .searching .rate, .searching .waiting, .searching .fallback { color: var(--ink-dim); font-size: 13px; margin-top: 4px; }
.searching .fallback { font-size: 12px; }
.search-bar { height: 6px; border-radius: 99px; background: rgba(255,255,255,.08); margin: 12px 8px 0; overflow: hidden; }
.search-bar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--emerald), var(--gold)); transition: width .25s linear; }
/* 探している様子のレーダー */
.radar { position: relative; width: 120px; height: 120px; margin: 4px auto 12px; border-radius: 50%;
  background: radial-gradient(circle, rgba(46,232,138,.18), rgba(46,232,138,.04) 60%, transparent 70%); }
.radar span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(46,232,138,.6); animation: radar 2.4s ease-out infinite; }
.radar span:nth-child(2) { animation-delay: .8s; }
.radar span:nth-child(3) { animation-delay: 1.6s; }
.radar i { position: absolute; inset: 0; border-radius: 50%; animation: spin 2s linear infinite;
  background: conic-gradient(from 0deg, rgba(233,196,106,.55), rgba(233,196,106,0) 25%, transparent); }
.radar::after { content: ""; position: absolute; left: 50%; top: 50%; width: 12px; height: 12px; margin: -6px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 12px var(--gold); }
@keyframes radar { from { transform: scale(.2); opacity: 1; } to { transform: scale(1); opacity: 0; } }

.skins { display: flex; flex-direction: column; gap: 10px; }
.skin-top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.skin-stone { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; min-height: 40px; border-radius: 10px; background: rgba(0,0,0,.28); border: 1px solid var(--panel-line); font-size: 14px; color: var(--ink-dim); }
.skin-stone[aria-pressed="true"] { border-color: var(--gold); color: #fff3cf; background: rgba(233,196,106,.14); }
.skin-mini { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; }
.skin-none { margin-left: auto; min-height: 36px; font-size: 13px; padding: 0 10px; }
.skin-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.skin-tabs::-webkit-scrollbar { display: none; }
.skin-tabs button { flex-shrink: 0; padding: 6px 12px; border-radius: 99px; font-size: 13px; background: rgba(255,255,255,.05); border: 1px solid transparent; color: var(--ink-dim); }
.skin-tabs button[aria-pressed="true"] { background: linear-gradient(#e8edf0, #b9c1c6); color: #11201a; font-weight: 700; }
.skin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 8px; max-height: min(50dvh, 430px); overflow-y: auto; padding: 2px; overscroll-behavior: contain; }
.skin-region { grid-column: 1 / -1; font-size: 12px; color: var(--gold); margin-top: 4px; }
.skin-tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px 6px; border-radius: 12px; background: rgba(255,255,255,.04); border: 1px solid transparent; }
.skin-tile:hover { background: rgba(255,255,255,.08); }
.skin-tile[aria-pressed="true"] { border-color: var(--gold); background: rgba(233,196,106,.16); }
.skin-tile:disabled { opacity: .4; cursor: default; }
.skin-thumb { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; box-shadow: 0 2px 6px rgba(0,0,0,.5), inset 0 0 0 1px rgba(255,255,255,.2); }
.skin-tile.locked .skin-thumb { filter: saturate(.55) brightness(.8); }
.skin-name { font-size: 11.5px; line-height: 1.25; text-align: center; color: var(--ink); }
.skin-tag { font-size: 10.5px; color: var(--gold); min-height: 1em; }
.skin-star { position: absolute; top: 4px; right: 4px; font-size: 9.5px; padding: 1px 5px; border-radius: 99px; background: #5b3fc9; color: #fff; }
.skin-tile.rarity-3 .skin-star { background: linear-gradient(90deg, #f3d58a, #c98a1d); color: #2a1d05; }
.skin-tile.rarity-3 .skin-thumb { box-shadow: 0 0 0 2px #e9c46a, 0 0 12px rgba(233,196,106,.6); }

.name-form { display: grid; gap: 10px; }
.name-form p { font-size: 14px; color: var(--ink-dim); }
.name-form input { min-height: 46px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--panel-line); background: rgba(0,0,0,.35); color: var(--ink); font-size: 16px; }
.name-form input:focus { outline: 2px solid var(--gold); }
.name-error { min-height: 1.4em; color: #ffb4b4 !important; font-size: 13px !important; }
.ranking { display: grid; gap: 10px; }
.rank-me { font-size: 13px; color: var(--gold); padding: 8px 10px; border-radius: 10px; background: rgba(233,196,106,.1); border: 1px solid rgba(233,196,106,.35); }
.rank-list { display: grid; gap: 2px; max-height: min(52dvh, 440px); overflow-y: auto; overscroll-behavior: contain; }
.rank-row { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 8px; align-items: center; padding: 7px 8px; border-radius: 8px; font-size: 14px; }
.rank-row:nth-child(odd) { background: rgba(255,255,255,.03); }
.rank-row.me { background: rgba(233,196,106,.18); outline: 1px solid var(--gold); }
.rank-no { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-rate { font: 700 16px var(--serif); font-variant-numeric: tabular-nums; }
.rank-games { font-size: 11px; color: var(--ink-dim); min-width: 52px; text-align: right; }
.rank-empty, .rank-loading { color: var(--ink-dim); font-size: 14px; text-align: center; padding: 16px 0; }

.review-range { flex: 1 1 120px; accent-color: var(--gold); min-width: 100px; }

#toast {
  position: absolute; left: 50%; top: 76px; z-index: 12; transform: translate(-50%, -10px);
  padding: 8px 16px; border-radius: 99px; max-width: calc(100% - 32px); text-align: center;
  background: rgba(20, 16, 4, .88); border: 1px solid var(--gold); color: #fff3cf; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(233,196,106,.25); border-top-color: var(--gold); animation: spin .9s linear infinite; }

/* ── もう一方のゲーム（リバーシ ⇄ スピン）への案内。Spin もこのファイルを読み込む ── */
.promo { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 6px; padding: 6px 10px; border-radius: 99px;
  font-size: 12.5px; color: var(--ink-dim); text-decoration: none; background: rgba(0,0,0,.22); border: 1px solid var(--panel-line); }
.promo:hover { color: var(--ink); }
.promo b { color: var(--gold); }
.promo-dot { width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #6b6f78, #000 70%); box-shadow: 7px 0 0 -1px #f1ece2; margin-right: 8px; }
.promo-dot.spin { box-shadow: none; margin-right: 2px; background: conic-gradient(#f2283a 0 120deg, #12b85a 0 240deg, #1f5cff 0); }
.result .promo { margin-top: 14px; }


@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
