:root {
  --ink: #4a4038;        /* 墨→焦げ茶。線の硬さを抜く */
  --ink-deep: #3a332d;
  --ink-soft: #7a6c5d;
  --gold: #a8905f;
  --gold-bright: #c89b4b;
  --highlight: #c0a993;
  --paper: #f2ead9;      /* ひと呼吸あたたかい生成り */
  --paper-dark: #e7ddc8;
  --card: #f7f1e4;
  --bad: #b2705f;
}
* { 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(120% 90% at 50% 0%, rgba(255,250,238,.75), rgba(255,250,238,0) 60%),
    repeating-linear-gradient(93deg, rgba(122,108,93,.02) 0 2px, transparent 2px 7px),
    repeating-linear-gradient(2deg, rgba(122,108,93,.016) 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: 25px; font-weight: 500; letter-spacing: .32em; text-indent: .32em; color: var(--ink-deep); }
.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(122,108,93,.55); border-radius: 10px;
  background: rgba(255,252,244,.6); color: var(--ink);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(74,64,56,.08);
}
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(255,248,230,.95) 0%, rgba(240,226,198,.55) 45%, rgba(240,226,198,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: 13px; height: 13px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #eed3a0, var(--gold-bright) 60%, #9a7a3e);
  box-shadow: 0 0 8px rgba(200,155,75,.45); 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: var(--paper-dark);
  box-shadow: 0 4px 20px rgba(90,79,68,.13);
  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(122,108,93,.55); transform: rotate(-4deg); pointer-events: none; }

/* 駒の足元に温かい光暈を敷いて、暗い体を地に馴染ませる */
.cell.haspiece::before { content: ""; position: absolute; inset: 4%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 58%, rgba(255,248,230,.85) 0%, rgba(248,236,212,.45) 48%, rgba(248,236,212,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;
  filter: drop-shadow(0 1px 3px rgba(90,79,68,.28)); }
.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 1px 3px rgba(90,79,68,.28)); }

.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(122,108,93,.5); border-radius: 14px;
  box-shadow: 0 10px 32px rgba(90,79,68,.25);
  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(58,51,45,.45);
  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(122,108,93,.5); border-radius: 16px;
  padding: 28px 30px 24px; text-align: center; max-width: 340px; width: 100%;
  box-shadow: 0 14px 44px rgba(58,51,45,.3); }
.card h2 { font-size: 23px; letter-spacing: .4em; text-indent: .4em; margin-bottom: 4px; color: var(--ink-deep); }
.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,155,75,.6); border-radius: 14px;
  box-shadow: 0 10px 32px rgba(90,79,68,.25);
  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; }

/* お散歩中のケハリス（盤上を歩く） */
.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(74,64,56,.94); color: var(--card); 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; }
}
