:root {
  --ink: #f3eee4;        /* クリーム（文字） */
  --ink-deep: #f8f3e6;
  --ink-soft: #8a857a;
  --gold: #8d6638;
  --gold-bright: #c89455;
  --highlight: #6b5a44;
  --paper: #0a0a0a;      /* TK-COFFEEの黒 */
  --paper-dark: #16130e;
  --card: #131312;
  --bad: #a05a45;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
  color: var(--ink);
  background:
    radial-gradient(90% 55% at 50% 0%, rgba(58,43,24,.85), rgba(10,10,10,0) 70%),
    repeating-linear-gradient(93deg, rgba(200,148,85,.02) 0 2px, transparent 2px 7px),
    repeating-linear-gradient(2deg, rgba(200,148,85,.014) 0 3px, transparent 3px 9px),
    var(--paper);
  min-height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}

.screen { display: none; flex-direction: column; align-items: center;
  min-height: 100dvh; padding: 14px 12px calc(20px + env(safe-area-inset-bottom)); }
.screen.active { display: flex; }

h1 { font-size: 26px; font-weight: 500; letter-spacing: .32em; text-indent: .32em;
  background: linear-gradient(180deg, #f5e3bc 0%, #c89455 55%, #8d6638 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: #c89455;
  filter: drop-shadow(0 1px 6px rgba(200,148,85,.25)); }
.subtitle { font-size: 11px; color: var(--ink-soft); letter-spacing: .2em; margin-top: 4px; }

button {
  font-family: inherit; font-size: 14px; letter-spacing: .12em;
  padding: 10px 18px; min-height: 44px;
  border: 1.2px solid rgba(200,148,85,.32); border-radius: 10px;
  background: linear-gradient(180deg, rgba(34,27,18,.75), rgba(18,14,10,.75));
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.35), inset 0 1px 0 rgba(232,200,144,.07);
}
button:active { background: var(--ink); color: var(--paper); }
button:disabled { opacity: .35; cursor: default; }
button.primary { background: var(--ink); color: var(--card); border-color: var(--ink); }
button.primary:active { background: var(--ink-soft); }
button.ghost { border-color: transparent; background: transparent; color: var(--ink-soft); box-shadow: none; }

/* ---------- ホーム ---------- */
#screen-home { justify-content: center; gap: 8px; }
.halo { position: relative; display: grid; place-items: center; margin: 6px 0 2px; }
.halo::before { content: ""; position: absolute; width: 190px; height: 190px; border-radius: 50%;
  background: radial-gradient(circle, rgba(200,148,85,.28) 0%, rgba(200,148,85,.12) 45%, rgba(200,148,85,0) 72%); }
#home-kehare { width: 128px; aspect-ratio: 12/13; position: relative; }
.home-stats { font-size: 12.5px; color: var(--ink-soft); letter-spacing: .1em; margin: 4px 0 14px; }
.home-menu { display: flex; flex-direction: column; gap: 11px; width: min(300px, 86vw); }
.home-menu button { width: 100%; font-size: 15px; padding: 13px 18px; }
.daily-done-mark { color: var(--gold-bright); }

.free-sizes { display: none; gap: 6px; justify-content: center; }
.free-sizes.open { display: flex; }
.size-btn { min-width: 44px; padding: 8px 0; font-size: 14px; }

/* ---------- プレイ画面 ---------- */
.playbar { width: min(500px, 92vw); display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 4px; }
.playbar .title { font-size: 15px; letter-spacing: .18em; }
.playbar .grade { font-size: 11px; color: var(--gold); letter-spacing: .15em; margin-left: 8px; }
.backbtn { min-height: 38px; padding: 6px 12px; font-size: 13px; }

.status { display: flex; align-items: center; gap: 18px; margin: 8px 0 12px;
  font-size: 13px; color: var(--ink-soft); }
.lamps { display: flex; gap: 7px; align-items: center; }
.lamp { width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fbeed0, var(--gold-bright) 55%, #8a6a30);
  box-shadow: 0 0 10px rgba(200,148,85,.65), 0 0 22px rgba(200,148,85,.25),
    inset 0 -1px 2px rgba(90,60,20,.5); transition: all .4s; }
.lamp.off { background: transparent; box-shadow: inset 0 0 0 1.5px rgba(122,108,93,.4); }
.stat-label { letter-spacing: .15em; }
.jikkuri-badge { font-size: 11px; color: var(--gold); border: 1px solid rgba(168,144,95,.6);
  border-radius: 8px; padding: 2px 8px; letter-spacing: .15em; }

.board {
  position: relative;
  display: grid;
  border: none;
  border-radius: 18px;
  padding: 7px;
  background: linear-gradient(160deg, #221b12 0%, #14100a 55%, #0d0a06 100%);
  box-shadow:
    0 0 0 1px rgba(240,217,168,.6),
    0 0 0 3.5px #0a0806,
    0 0 0 5px rgba(141,102,56,.5),
    0 0 0 5.8px rgba(232,200,144,.18),
    0 22px 60px rgba(0,0,0,.7),
    0 0 90px rgba(200,148,85,.11),
    inset 0 1px 0 rgba(232,200,144,.14);
  touch-action: none;
}
.board .islands { position: absolute; top: 7px; left: 7px; z-index: 0; pointer-events: none; }
.cell, .cell * { touch-action: none; }
.cell { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.cell:active { filter: brightness(.97); }
.cell .mark { font-family: sans-serif; font-size: calc(var(--cell) * .36);
  color: rgba(26,17,8,.62); transform: rotate(-4deg); pointer-events: none; }
.cell .mark.auto { font-size: calc(var(--cell) * .28); color: rgba(26,17,8,.32); }

/* 駒の足元に温かい光暈を敷いて、暗い体を地に馴染ませる */
.cell.haspiece::before { content: ""; position: absolute; inset: 4%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 58%, rgba(36,22,8,.30) 0%, rgba(36,22,8,.14) 48%, rgba(36,22,8,0) 74%);
  pointer-events: none; }

.cell.bad::after { content: ""; position: absolute; inset: 5%; border-radius: 10px;
  box-shadow: inset 0 0 0 2px rgba(178,112,95,.6); pointer-events: none; }
.cell.adv::after { content: ""; position: absolute; inset: 5%; border-radius: 10px;
  box-shadow: inset 0 0 0 2px rgba(200,155,75,.7), 0 0 10px rgba(200,155,75,.35); pointer-events: none; }
.cell .hintglow { position: absolute; inset: 6%; border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(200,155,75,.8), 0 0 14px rgba(200,155,75,.6);
  animation: hintpulse 1.1s ease-in-out 3; pointer-events: none; }
@keyframes hintpulse { 50% { box-shadow: 0 0 0 2px rgba(200,155,75,.35), 0 0 4px rgba(200,155,75,.25); } }

.kehare-piece { width: 86%; height: 86%; object-fit: contain; object-position: center 54%;
  pointer-events: none; position: relative; transform-origin: 50% 82%;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.5)); }
/* 常時の尻尾ゆらぎ */
@keyframes sway { from { transform: rotate(-2.4deg); } to { transform: rotate(2.4deg); } }
/* 尻尾ぶんぶん */
@keyframes wiggle { 0%,100% { transform: rotate(0); } 22% { transform: rotate(-7deg); }
  48% { transform: rotate(6deg); } 74% { transform: rotate(-4deg); } }
.kehare-sprite { width: 86%; aspect-ratio: 12 / 13; position: relative;
  background-image: url("./assets/kehare-spritesheet.png");
  background-repeat: no-repeat; background-size: 800% 900%; pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.5)); }

.controls { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; justify-content: center; }

/* 助言カード */
.advice { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  width: min(440px, 94vw);
  background: var(--card); border: 1.5px solid rgba(141,102,56,.5); border-radius: 14px;
  box-shadow: 0 10px 32px rgba(0,0,0,.5);
  padding: 16px 18px 14px;
  opacity: 0; pointer-events: none; transition: all .35s; z-index: 40; }
.advice.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.advice .adv-title { font-size: 12px; color: var(--gold); letter-spacing: .2em; margin-bottom: 6px; }
.advice p { font-size: 13.5px; line-height: 1.9; }
.advice .btns { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; }
.advice .btns button { min-height: 40px; padding: 8px 14px; font-size: 13px; }

/* ---------- デイリー ---------- */
#screen-daily .month-title { font-size: 16px; letter-spacing: .3em; margin: 18px 0 10px; }
.cal { display: grid; grid-template-columns: repeat(7, 44px); gap: 4px; }
.cal .dow { font-size: 11px; color: var(--ink-soft); text-align: center; padding: 4px 0; }
.cal .day { width: 44px; height: 44px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 13px;
  border-radius: 10px; color: var(--ink-soft); position: relative; }
.cal .day.done { background: rgba(200,155,75,.16); color: var(--ink); }
.cal .day.done::after { content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #eed3a0, var(--gold-bright) 60%, #9a7a3e);
  margin-top: 2px; }
.cal .day.today { outline: 1.5px solid rgba(90,79,68,.7); outline-offset: -1.5px; }
.cal .day.future { opacity: .3; }
.daily-stats { margin: 16px 0; font-size: 13px; color: var(--ink-soft);
  letter-spacing: .1em; text-align: center; line-height: 2; }

/* ---------- 設定 ---------- */
.settings-list { width: min(420px, 92vw); margin-top: 20px; display: flex; flex-direction: column; gap: 4px; }
.setting-row { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 6px; border-bottom: 1px solid rgba(122,108,93,.18); }
.setting-row .lab { font-size: 14px; letter-spacing: .1em; }
.setting-row .desc { font-size: 11px; color: var(--ink-soft); margin-top: 4px; line-height: 1.7; }
.toggle { width: 52px; height: 30px; border-radius: 15px; border: 1.2px solid rgba(122,108,93,.55);
  background: transparent; position: relative; flex-shrink: 0; cursor: pointer; padding: 0; min-height: 30px; box-shadow: none; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 4px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--ink-soft); transition: all .25s; }
.toggle.on { background: var(--ink); border-color: var(--ink); }
.toggle.on::after { left: 25px; background: var(--card); }

/* ---------- 幕・チュートリアル ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity .45s; }
.overlay.show { opacity: 1; pointer-events: auto; }
.card { background: var(--card); border: 1.5px solid rgba(141,102,56,.5); border-radius: 16px;
  padding: 28px 30px 24px; text-align: center; max-width: 340px; width: 100%;
  box-shadow: 0 14px 44px rgba(0,0,0,.55); }
.card h2 { font-size: 23px; letter-spacing: .4em; text-indent: .4em; margin-bottom: 4px;
  background: linear-gradient(180deg, #f5e3bc 0%, #c89455 55%, #8d6638 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: #c89455; }
.card p { font-size: 13px; color: var(--ink-soft); line-height: 1.9; margin: 10px 0 16px; }
.card .kehare-sprite, .card .kehare-piece { width: 110px; margin: 4px auto; display: block; }
.card .btns { display: flex; flex-direction: column; gap: 9px; }

.guide { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(440px, 94vw);
  background: var(--card); border: 1.5px solid rgba(200,148,85,.6); border-radius: 14px;
  box-shadow: 0 10px 32px rgba(0,0,0,.5);
  padding: 16px 18px 14px; z-index: 45; display: none; }
.guide.show { display: block; }
.guide .g-title { font-size: 12px; color: var(--gold); letter-spacing: .2em; margin-bottom: 6px; }
.guide p { font-size: 13.5px; line-height: 1.9; }
.guide .btns { display: flex; justify-content: flex-end; margin-top: 10px; }

/* 置かれたぁー！の衝撃演出（盤の揺れは画面酔い防止のため廃止） */
.impact-ring { position: absolute; inset: 8%; border-radius: 50%; pointer-events: none; z-index: 4;
  border: 3px solid rgba(200,155,75,.85);
  animation: ringout .55s ease-out forwards; }
.impact-ring.bad-ring { border-color: rgba(178,112,95,.7); }
@keyframes ringout { from { transform: scale(.3); opacity: .95; } to { transform: scale(1.7); opacity: 0; } }
.spark { position: absolute; left: 50%; top: 55%; width: 8px; height: 8px; margin: -4px;
  border-radius: 2px 7px 2px 7px; pointer-events: none; z-index: 4;
  animation: sparkfly .62s ease-out forwards; }
@keyframes sparkfly {
  from { transform: translate(0,0) rotate(0) scale(1); opacity: 1; }
  to { transform: translate(var(--sx), var(--sy)) rotate(200deg) scale(.35); opacity: 0; } }
.cry { position: absolute; left: 50%; bottom: 92%; transform: translateX(-50%);
  background: var(--card); border: 1.5px solid var(--ink-soft); border-radius: 10px;
  padding: 3px 10px; font-size: 12px; letter-spacing: .08em; white-space: nowrap;
  color: var(--ink); pointer-events: none; z-index: 5;
  animation: cryup .95s ease-out forwards; }
@keyframes cryup {
  0% { transform: translateX(-50%) translateY(6px) scale(.5); opacity: 0; }
  18% { transform: translateX(-50%) translateY(-4px) scale(1.08); opacity: 1; }
  75% { opacity: 1; }
  100% { transform: translateX(-50%) translateY(-22px) scale(1); opacity: 0; } }

/* クリア幕の見出しをドンと出す */
.card h2 { animation: titlepop .55s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes titlepop { from { transform: scale(.4); opacity: 0; } }

/* お散歩中のケハリス（盤上を歩く） */
.walker { position: absolute; z-index: 3; pointer-events: none;
  filter: drop-shadow(0 1px 3px rgba(90,79,68,.3)); }
/* ホーム画面を横切るケハリス */
.stroller { position: fixed; bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 4; pointer-events: none; opacity: .92; }
/* 盤を開いたときの入場 */
@keyframes piecein { from { transform: scale(.6); opacity: 0; } }

/* 金の葉の紙吹雪 */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 55; overflow: hidden; }
.confetti i { position: absolute; top: 0; width: 9px; height: 13px;
  border-radius: 2px 9px 2px 9px; opacity: .9;
  animation: confetti-fall linear forwards; }
@keyframes confetti-fall {
  from { transform: translate(0, -14vh) rotate(0deg); }
  to   { transform: translate(var(--dx), 114vh) rotate(var(--rot)); }
}

.toast { position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(36,28,18,.96); color: var(--ink); border: 1px solid rgba(141,102,56,.5); font-size: 13px; letter-spacing: .1em;
  padding: 10px 22px; border-radius: 10px; opacity: 0; transition: all .4s;
  pointer-events: none; z-index: 60; white-space: nowrap; }
.toast.show { opacity: .97; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .lamp, .overlay, .toast, .advice { transition: none; }
  .hintglow { animation: none; }
}
