/* まるばつ — 見た目。ライト=クリーム・ダーク=夜。外部フォントは使わない(何も送らないため) */
:root {
  --bg: #fff6e9;
  --ink: #2b2433;
  --sub: #6b6177;
  --maru: #ff5d73;
  --batsu: #2f7cf6;
  --grid: #ffcf70;
  --grid-sh: #e8a93a;
  --cell: #fffdf8;
  --cell-sh: #f1dcb4;
  --card: #ffffff;
  --card-sh: #ecd9b8;
  --gold: #ffb800;
  --focus: #2f7cf6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a27;
    --ink: #f3eefc;
    --sub: #b4abc4;
    --maru: #ff7a8c;
    --batsu: #5b9bff;
    --grid: #4a4166;
    --grid-sh: #2e2843;
    --cell: #2c2840;
    --cell-sh: #1a1726;
    --card: #2c2840;
    --card-sh: #14121c;
    --focus: #ffb800;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow: hidden;
}
#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; }

/* ---- こま・ねこ(どこでも同じ絵) ---- */
.o, .x { fill: none; stroke-width: 13; stroke-linecap: round; }
.o { stroke: var(--maru); }
.x { stroke: var(--batsu); }
.face svg, .duo svg, .mini svg, .st-icon svg { display: block; width: 100%; height: 100%; overflow: visible; }
.fh { fill: #ffb35c; stroke: #2b2433; stroke-width: 4; stroke-linejoin: round; }
.fe { fill: #ff9aa9; }
.ff { fill: #2b2433; }
.fl { fill: none; stroke: #2b2433; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.fn { fill: #ff6b81; }
.fw { stroke: #2b2433; stroke-width: 2.5; stroke-linecap: round; opacity: .65; }
.fz { font: 900 20px sans-serif; fill: var(--sub); }

/* ---- 大きいボタン(カード) ---- */
.big {
  background: var(--card);
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--card-sh);
  transition: transform .06s;
}
.big:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--card-sh); }
.back {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 56px; min-width: 56px; padding: 0 16px 0 10px;
  border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
  font-weight: 800; font-size: 18px;
}
.back span { font-size: 32px; line-height: 1; margin-top: -5px; }
.back:active, .snd:active, .seg:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-sh); }

/* ---- はじめの画面 ---- */
.menu { padding: 4vh 16px 15vh; gap: 3vh; overflow-y: auto; }
/* 中身は上下のまんなかに(はみ出すときは上から) */
.menu > .logo, .level-title { margin-top: auto !important; }
.menu > .opts, .levels { margin-bottom: auto; }
.logo {
  display: flex; align-items: center; gap: .08em;
  font-size: clamp(40px, 11vw, 72px); font-weight: 900; letter-spacing: .02em;
  margin: 2vh 0 0; line-height: 1.1;
}
.logo-mark { width: .95em; height: .95em; }
.logo-mark .o, .logo-mark .x { stroke-width: 14; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: min(100%, 560px); }
.mode { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 18px 8px 16px; min-height: 176px; }
.mode .face, .duo { width: 88px; height: 88px; }
.duo { display: flex; align-items: center; justify-content: center; gap: 4px; }
.duo svg { width: 42px; height: 42px; }
.mode-name { font-size: clamp(22px, 6vw, 30px); font-weight: 900; }
.mode-sub { font-size: 14px; color: var(--sub); }
.opts { display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(100%, 560px); }
.opt { display: flex; align-items: center; gap: 10px; }
.opt-label { font-weight: 800; }
.seg {
  min-height: 52px; min-width: 96px; padding: 0 18px; border-radius: 999px;
  background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
  font-weight: 800; font-size: 19px;
}
.seg[aria-pressed="true"] { background: var(--ink); color: var(--bg); box-shadow: 0 4px 0 rgba(0, 0, 0, .3); }
.rule-note { margin: 0; font-size: 15px; line-height: 1.6; color: var(--sub); text-align: center; max-width: 24em; min-height: 3.2em; }
.link { min-height: 48px; padding: 0 14px; font-size: 16px; color: var(--sub); text-decoration: underline; text-underline-offset: 3px; }

/* ---- ねこのつよさ ---- */
.level { padding: 12px 16px 15vh; gap: 3vh; }
.level .back { align-self: flex-start; }
.level-title { font-size: clamp(26px, 7vw, 40px); margin: 1vh 0 0; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: min(100%, 620px); }
.lv { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 16px 6px; min-height: 156px; }
.lv .face { width: min(96px, 24vw); height: min(96px, 24vw); }
.lv-name { font-size: clamp(20px, 5.5vw, 28px); font-weight: 900; }
.lv.last { box-shadow: 0 6px 0 var(--card-sh), 0 0 0 4px var(--gold); }

/* ---- あそぶ画面 ---- */
.game {
  display: grid; width: 100%; align-items: stretch;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas: "top" "status" "board" "act";
  /* 画面の下 15% には押すものを置かない(手首が当たる) */
  padding: 10px 12px 15vh; gap: 8px;
}
.top { grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.top .back, .snd { flex-shrink: 0; }
.score { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--sub); white-space: nowrap; min-width: 0; }
@media (max-width: 374px) { .sc.d { display: none; } }
.sc { display: inline-flex; align-items: center; gap: 4px; }
.sc b { font-size: 26px; color: var(--ink); font-variant-numeric: tabular-nums; }
.sc.d b { font-size: 16px; }
.mini { display: inline-block; width: 30px; height: 30px; }
.mini .o, .mini .x { stroke-width: 15; }
.snd { width: 56px; height: 56px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; }
.snd svg { width: 34px; height: 34px; }
.spk { fill: var(--ink); }
.wave, .slash { fill: none; stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; }
.snd.off .wave, .snd:not(.off) .slash { display: none; }

.status {
  grid-area: status;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 66px; font-size: clamp(22px, 6vw, 30px); font-weight: 900; text-align: center;
}
.st-icon { display: inline-flex; gap: 2px; height: 54px; }
.st-icon svg { width: 54px; height: 54px; }
.st-icon .o, .st-icon .x { stroke-width: 14; }
.status.p1 .st-text { color: var(--maru); }
.status.p2 .st-text { color: var(--batsu); }
.status.p1 .st-icon, .status.p2 .st-icon { animation: bob 1.2s ease-in-out infinite; }
.status.think .st-icon { animation: bob .7s ease-in-out infinite; }
.status.think .st-text::after { content: "…"; }
.status.win .st-text { animation: pop .45s ease-out; }
.status.over:not(.win) .st-text { color: var(--ink); }
@keyframes bob { 50% { transform: translateY(-5px); } }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.12); } }

.board-wrap { grid-area: board; min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
.board {
  --s: 300px;
  position: relative;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: calc(var(--s) * .035); gap: calc(var(--s) * .03);
  background: var(--grid); border-radius: calc(var(--s) * .08);
  box-shadow: 0 calc(var(--s) * .025) 0 var(--grid-sh);
}
.cell {
  position: relative; min-width: 0; min-height: 0;
  background: var(--cell); border-radius: calc(var(--s) * .055);
  box-shadow: inset 0 calc(var(--s) * -.018) 0 var(--cell-sh);
}
.cell:not(.filled):active { transform: scale(.95); }
@media (hover: hover) {
  .board:not(.done) .cell:not(.filled):hover { box-shadow: inset 0 calc(var(--s) * -.018) 0 var(--cell-sh), inset 0 0 0 3px var(--grid-sh); }
}
.cell .pc { position: absolute; inset: 9%; display: block; }
.cell .o, .cell .x { stroke-dasharray: 100 100; }
.pc.new .o { animation: draw .3s ease-out both; }
.pc.new .x1 { animation: draw .15s ease-out both; }
.pc.new .x2 { animation: draw .15s .13s ease-out both; }
@keyframes draw { from { stroke-dashoffset: 100; } to { stroke-dashoffset: 0; } }
.pc.gone { animation: gone .3s ease-in forwards; }
@keyframes gone { to { transform: scale(.2); opacity: 0; } }
/* きえるルール: 次に消える こま */
.cell.next-gone .pc:not(.gone) { opacity: .35; animation: blink 1.1s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .12; } }
.cell.nope { animation: shake .25s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.cell.win { animation: hop .5s ease-out .2s both; }
@keyframes hop { 40% { transform: scale(1.08); } }
.winline { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.winline path { fill: none; stroke: var(--gold); stroke-width: 12; stroke-linecap: round; stroke-dasharray: 100 100; animation: draw .35s ease-out both; }

.act { grid-area: act; display: flex; align-items: center; justify-content: center; min-height: 76px; }
.again {
  min-height: 70px; min-width: min(80vw, 320px); padding: 0 24px;
  font-size: clamp(22px, 6vw, 28px); font-weight: 900;
  background: var(--gold); color: #3a2a00; box-shadow: 0 6px 0 #c98a00;
  animation: pop .35s ease-out;
}
.again:active { box-shadow: 0 2px 0 #c98a00; }
.again:disabled { opacity: .55; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px;
  animation-name: fall; animation-timing-function: cubic-bezier(.3, .6, .6, 1); animation-fill-mode: forwards;
}
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }

/* スマホを横にしたとき: 盤を左、ようすとボタンを右。はじめの画面は 2つのボタンとルールを横にならべる */
@media (orientation: landscape) and (max-height: 600px) {
  .game {
    grid-template-columns: 1fr minmax(210px, 40%);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "top top" "board status" "board act";
  }
  .status { flex-direction: column; gap: 4px; }
  .menu {
    display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    grid-template-areas: "logo logo" "modes opts";
    align-content: start; justify-items: center; column-gap: 20px; row-gap: 2vh; padding-top: 2vh;
  }
  .logo { grid-area: logo; font-size: 40px; margin: 0 !important; }
  .modes { grid-area: modes; }
  .opts { grid-area: opts; margin-bottom: 0 !important; }
  .rule-note { min-height: 0; }
  .mode { min-height: 120px; padding: 10px 8px; }
  .mode .face, .duo { width: 60px; height: 60px; }
  .duo svg { width: 30px; height: 30px; }
  .lv { min-height: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important; }
}
