/* じゅくご橋(§7)。色は :root の変数だけで決める */
:root {
  --paper: #F5EEDF; --paper-2: #EADFC8; --tile: #FFFCF5; --tile-edge: #D6C6A4;
  --ink: #2A2520; --ink-soft: #6B6157; --gold: #B8902A; --gold-glow: #F3D682; --gold-text: #7D5C10;
  --miss: #B0443A; --seal: #C0392B; --shadow: rgba(60, 40, 10, .12);
  --mincho: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", "Noto Serif CJK JP", serif;
  --gothic: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", "Meiryo", "Noto Sans JP", sans-serif;
  --fsm: 1;  /* 札の字の倍率(文字サイズの設定) */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1D1A17; --paper-2: #27231F; --tile: #2E2A25; --tile-edge: #4A4239;
    --ink: #EEE6D8; --ink-soft: #A89E90; --gold: #DDB653; --gold-glow: #6E5418; --gold-text: #DDB653;
    --miss: #E07A6E; --seal: #B8463A; --shadow: rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
/* --tile は札の色。札の大きさは --ts(main.js が盤ごとに入れる) */
:root { --ts: 60px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  margin: 0; background: var(--paper); color: var(--ink); font-family: var(--gothic);
  line-height: 1.5; overscroll-behavior: none; -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
#app { max-width: 430px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.scr { flex: 1; display: flex; flex-direction: column; padding: 0 16px calc(20px + env(safe-area-inset-bottom)); animation: fadein .18s ease-out; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---- 上の帯 ---- */
.top { height: 56px; display: flex; align-items: center; gap: 4px; flex: none; }
.top h1 { flex: 1; margin: 0; font: 600 1.1rem/1.2 var(--mincho); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .side { width: 48px; display: flex; justify-content: center; flex: none; font-size: .9rem; color: var(--ink-soft); }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: 12px; display: grid; place-items: center;
  font-size: 1.4rem; cursor: pointer; color: var(--ink);
}
.icon-btn:active { background: var(--paper-2); }

/* ---- ボタン ---- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 48px; padding: 10px 16px;
  border-radius: 14px; border: 1px solid var(--tile-edge); background: var(--tile); color: var(--ink);
  font-size: 1rem; font-weight: 600; cursor: pointer; box-shadow: 0 2px 0 var(--tile-edge); transition: transform .08s;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); box-shadow: 0 3px 0 var(--gold); }
.btn.big { min-height: 60px; font-size: 1.2rem; }
.btn.small { min-height: 44px; font-size: .9rem; width: auto; padding: 6px 14px; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn[disabled] { opacity: .5; cursor: default; transform: none; }
.btn .sub { font-weight: 400; font-size: .8rem; color: inherit; opacity: .8; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--ink-soft); font-size: .9rem; }
.center { text-align: center; }

/* ---- ホーム ---- */
.home-head { display: flex; align-items: flex-start; padding-top: 12px; }
.home-head .ttl { flex: 1; }
.home-head h1 { margin: 6px 0 0; font: 700 2rem/1.2 var(--mincho); letter-spacing: .08em; }
.home-head p { margin: 2px 0 0; color: var(--ink-soft); font-size: .9rem; }
.rank { display: inline-block; margin-top: 6px; padding: 1px 10px; border-radius: 99px; background: var(--paper-2); font-size: .8rem; color: var(--ink-soft); }
.card { background: var(--paper-2); border-radius: 18px; padding: 16px; position: relative; }
.card h2 { margin: 0; font: 600 1rem/1.3 var(--gothic); color: var(--ink-soft); }
.card .big-n { font: 700 1.9rem/1.2 var(--mincho); margin: 4px 0; }
.card .state { font-size: 1rem; margin-bottom: 12px; }
.card.today { border: 2px solid var(--gold); }
.card.today.glow { animation: cardglow 2.4s ease-in-out infinite; }
@keyframes cardglow { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 0 5px var(--gold-glow); } }
.card.today.done { border-width: 1px; border-color: var(--tile-edge); padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.card.today.done .grow { flex: 1; }
.card.today.done .big-n { font-size: 1.2rem; margin: 0; }
.card.today.done .state { margin: 0; font-size: .9rem; }
.card.prac.hero { border: 2px solid var(--gold); }
.bar { height: 10px; border-radius: 99px; background: var(--paper); overflow: hidden; margin: 8px 0 12px; border: 1px solid var(--tile-edge); }
.bar > i { display: block; height: 100%; background: var(--gold); border-radius: 99px; transition: width .4s; }
.streak { display: flex; align-items: center; gap: 12px; padding: 4px 4px; min-height: 44px; flex-wrap: wrap; }
.streak b { font-size: 1.05rem; }
.qbtn { position: relative; width: 44px; height: 44px; margin: 0 -8px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; padding: 0; font: 700 .9rem/1 var(--gothic); color: var(--ink-soft); }
.qbtn::after { content: ""; position: absolute; left: 10px; top: 10px; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--ink-soft); box-sizing: border-box; }
.dan .free { display: block; font-size: .8rem; font-weight: 600; color: var(--gold-text); }
.tip {
  position: relative; background: var(--ink); color: var(--paper); border-radius: 12px; padding: 8px 12px; font-size: .9rem;
  margin: 0 0 10px; animation: fadein .3s;
}
.tip::after { content: ""; position: absolute; left: 32px; bottom: -8px; border: 8px solid transparent; border-bottom: 0; border-top-color: var(--ink); }
.menu3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.menu3 .btn { flex-direction: column; gap: 2px; min-height: 76px; font-size: .9rem; padding: 8px 4px; }
.menu3 .btn .ic { font-size: 1.4rem; line-height: 1; }

/* ---- 盤 ---- */
.play { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.msg { height: 30px; display: flex; align-items: center; justify-content: center; font-size: .95rem; color: var(--ink-soft); text-align: center; flex: none; }
.msg.err { color: var(--miss); font-weight: 600; }
.msg.gold { color: var(--gold-text); font-weight: 700; }
.msg.soft { color: var(--ink-soft); font-weight: 600; }
.board-wrap { display: flex; justify-content: center; flex: none; }
.board {
  position: relative; display: grid; gap: 6px; padding: 8px; border-radius: 18px; background: var(--paper-2);
  touch-action: none; user-select: none; -webkit-user-select: none; box-shadow: inset 0 1px 3px var(--shadow);
}
.tile {
  position: relative; width: var(--ts); height: var(--ts); display: grid; place-items: center;
  background: var(--tile); border: 1px solid var(--tile-edge); border-radius: calc(var(--ts) * .14);
  box-shadow: 0 2px 0 var(--tile-edge), 0 3px 6px var(--shadow);
  font: 500 calc(var(--ts) * .58 * var(--fsm)) / 1 var(--mincho); color: var(--ink); cursor: pointer;
  transition: box-shadow .15s, background .2s;
}
.tile .ch { position: relative; z-index: 2; pointer-events: none; text-shadow: 0 0 3px var(--tile), 0 0 3px var(--tile), 0 0 6px var(--tile); }
.tile.on { box-shadow: inset 0 0 0 2px var(--gold), 0 2px 0 var(--tile-edge), 0 3px 6px var(--shadow); }
.tile.end { background: color-mix(in srgb, var(--tile) 80%, var(--gold-glow)); }
.tile.goal::after {
  content: ""; position: absolute; inset: 3px; border-radius: calc(var(--ts) * .11); border: 1.5px dashed var(--seal); opacity: .55; pointer-events: none;
}
.tile.glow { animation: glow .25s ease-out; }
@keyframes glow { 0% { box-shadow: 0 0 0 0 var(--gold-glow); } 50% { box-shadow: inset 0 0 0 2px var(--gold), 0 0 0 5px var(--gold-glow), 0 0 16px var(--gold-glow); } 100% { box-shadow: inset 0 0 0 2px var(--gold), 0 2px 0 var(--tile-edge); } }
.tile.won { animation: won .5s ease-out forwards; }
@keyframes won { 0% { background: var(--tile); } 40% { background: var(--gold-glow); box-shadow: 0 0 0 4px var(--gold-glow), 0 0 18px var(--gold-glow); } 100% { background: color-mix(in srgb, var(--tile) 70%, var(--gold-glow)); box-shadow: inset 0 0 0 2px var(--gold); } }
.tile.softshake { animation: softshake .28s ease-in-out; }
@keyframes softshake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
.tile.miss { animation: shake .24s linear; box-shadow: inset 0 0 0 2px var(--miss), 0 2px 0 var(--tile-edge); }
@keyframes shake { 0%, 100% { transform: translateX(0); } 16% { transform: translateX(-4px); } 33% { transform: translateX(4px); } 50% { transform: translateX(-4px); } 66% { transform: translateX(4px); } 83% { transform: translateX(-4px); } }
.tile .x { position: absolute; right: 3px; top: 0; font: 700 calc(var(--ts) * .26)/1 var(--gothic); color: var(--miss); animation: xfade .5s forwards; }
@keyframes xfade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
.tile.hint::before {
  content: ""; position: absolute; inset: -4px; border-radius: calc(var(--ts) * .18); border: 3px dashed var(--gold);
  animation: hintp 1.2s ease-in-out 2; pointer-events: none; opacity: 0;
}
@keyframes hintp { 0%, 100% { opacity: 0; transform: scale(.94); } 50% { opacity: 1; transform: scale(1.04); } }
.seal {
  position: absolute; left: -5px; top: -5px; width: calc(var(--ts) * .36); height: calc(var(--ts) * .36); min-width: 18px; min-height: 18px;
  border-radius: 50%; background: var(--seal); color: #fff; display: grid; place-items: center;
  font: 700 max(10px, calc(var(--ts) * .2))/1 var(--gothic); box-shadow: 0 1px 2px var(--shadow); z-index: 2; pointer-events: none;
}
.ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 1; }
.ink line { stroke: var(--ink); stroke-opacity: .8; stroke-linecap: round; }
/* 線は字の後ろ:字が読めるように、札の上では少し薄く見える */
.ink line.new { animation: draw .12s linear forwards; }
.ink line.ans { stroke: var(--gold); stroke-opacity: .55; animation: draw .25s linear forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.hand {
  position: absolute; width: 34px; height: 34px; border-radius: 50%; background: var(--ink); opacity: .35; z-index: 3; pointer-events: none;
  left: 0; top: 0; animation: hand 2.2s ease-in-out infinite; box-shadow: 0 0 0 6px color-mix(in srgb, var(--ink) 15%, transparent);
}
@keyframes hand {
  0% { transform: translate(var(--x0), var(--y0)) scale(1.2); opacity: 0; }
  15% { transform: translate(var(--x0), var(--y0)) scale(1); opacity: .4; }
  60% { transform: translate(var(--x1), var(--y1)) scale(1); opacity: .4; }
  80%, 100% { transform: translate(var(--x1), var(--y1)) scale(1.2); opacity: 0; }
}
.chips { display: flex; gap: 8px; overflow-x: auto; height: 64px; align-items: center; flex: none; padding: 6px 2px; scrollbar-width: none; margin-top: 10px; }
.chips::-webkit-scrollbar { display: none; }
.chips .empty { color: var(--ink-soft); font-size: .85rem; width: 100%; text-align: center; }
.chip { flex: none; display: flex; flex-direction: column; align-items: center; padding: 4px 12px; border-radius: 12px; background: var(--paper-2); border: 1px solid var(--tile-edge); }
.chip .w { font: 600 1.15rem/1.2 var(--mincho); }
.chip .r { font-size: .7rem; color: var(--ink-soft); line-height: 1.2; }
.chip.new { animation: chipin .2s ease-out; }
.chip.lit { background: var(--gold-glow); border-color: var(--gold); transition: background .3s; }
.chip.lit .r { color: var(--ink); }
@keyframes chipin { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.mid { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-bottom: 8px; }
.play-foot { display: flex; align-items: center; gap: 10px; padding-top: 8px; }
.play-foot .count { flex: none; min-width: 64px; font: 700 1.1rem var(--mincho); }
.play-foot .btn { flex: 1; white-space: nowrap; padding: 10px 8px; font-size: .95rem; }
.play-foot .btn.hintb { flex: 1.5; }

/* ---- 結果 ---- */
.res-head { text-align: center; padding: 8px 0 4px; }
.res-head h2 { margin: 0; font: 700 2rem/1.3 var(--mincho); }
.stars { font-size: 2.2rem; letter-spacing: .1em; color: var(--gold-text); line-height: 1.2; }
.stars .off { color: var(--tile-edge); }
.nums { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.num { background: var(--paper-2); border-radius: 14px; padding: 8px 12px; }
.num .k { font-size: .8rem; color: var(--ink-soft); }
.num .v { font: 700 1.4rem/1.2 var(--mincho); }
.num.wide { grid-column: span 2; }
.badge { display: inline-block; background: var(--gold-text); color: var(--paper); border-radius: 99px; padding: 0 10px; font-size: .8rem; font-weight: 700; vertical-align: middle; margin-left: 6px; }
.newwords { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.next-line { text-align: center; font-size: .9rem; color: var(--ink-soft); margin: 6px 0 -2px; }
.flash { position: fixed; left: 50%; top: 30%; transform: translate(-50%, 0); background: var(--gold); color: var(--paper); padding: 8px 18px; border-radius: 99px; font-weight: 700; z-index: 50; animation: flash 1.6s forwards; pointer-events: none; }
@keyframes flash { 0% { opacity: 0; transform: translate(-50%, 10px); } 15%, 75% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -10px); } }
.ans-wrap { display: flex; justify-content: center; margin: 4px 0 12px; }
.ans-wrap .board { --ts: 40px; gap: 4px; padding: 6px; }
.ans-wrap .tile { cursor: default; }

/* ---- 練習・過去 ---- */
.dan { display: flex; align-items: center; gap: 12px; text-align: left; justify-content: flex-start; min-height: 76px; }
.dan .dn { font: 700 1.6rem/1 var(--mincho); width: 40px; text-align: center; }
.dan .grow { flex: 1; }
.dan .grow > span { display: block; }
.dan .grow > .bar { display: block; width: 100%; margin: 6px 0 0; height: 8px; }
.dan.locked { opacity: .55; }
.list { display: flex; flex-direction: column; gap: 8px; }
.past { display: flex; align-items: center; gap: 10px; justify-content: space-between; min-height: 56px; }
.past .st { color: var(--gold-text); }

/* ---- 熟語帳 ---- */
.book-sum { text-align: center; padding: 8px 0; }
.book-sum .n { font: 700 2rem/1.2 var(--mincho); }
.seg { display: flex; background: var(--paper-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 44px; border: 0; background: transparent; border-radius: 10px; font-size: .9rem; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--tile); box-shadow: 0 1px 2px var(--shadow); font-weight: 700; }
.words { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; margin-top: 12px; }
.wcard { background: var(--tile); border: 1px solid var(--tile-edge); border-radius: 12px; padding: 4px 4px 6px; text-align: center; }
.wcard .ks { display: flex; justify-content: center; }
.wcard .k { min-width: 44px; min-height: 44px; border: 0; background: transparent; font: 600 1.5rem/1 var(--mincho); border-radius: 8px; cursor: pointer; }
.wcard .k:active { background: var(--paper-2); }
.wcard .r { font-size: .72rem; color: var(--ink-soft); }
.graph { width: 100%; max-width: 340px; display: block; margin: 0 auto; }
.graph text { font-family: var(--mincho); fill: var(--ink); }
.graph .c-ring { fill: var(--tile); stroke: var(--tile-edge); }
.graph .c-mid { fill: var(--gold-glow); stroke: var(--gold); stroke-width: 2; }
.graph line.got { stroke: var(--gold); stroke-width: 2.5; }
.graph line.no { stroke: var(--ink-soft); stroke-width: 1.2; stroke-dasharray: 4 4; opacity: .7; }
.legend { display: flex; justify-content: center; gap: 14px; font-size: .8rem; color: var(--ink-soft); flex-wrap: wrap; }

/* ---- 設定・ページ ---- */
.set { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; border-bottom: 1px solid var(--paper-2); }
.set .lbl { font-weight: 600; }
.set .seg { min-width: 170px; }
.switch { width: 70px; height: 44px; border: 5px solid transparent !important; background-clip: padding-box !important; border-radius: 99px; border: 0; background: var(--tile-edge); position: relative; cursor: pointer; flex: none; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 28px; height: 28px; border-radius: 50%; background: var(--tile); transition: left .15s; box-shadow: 0 1px 2px var(--shadow); }
.switch[aria-checked="true"] { background: var(--gold); }
.switch[aria-checked="true"]::after { left: 29px; }
.link { display: flex; justify-content: space-between; align-items: center; min-height: 52px; border: 0; border-bottom: 1px solid var(--paper-2); background: transparent; width: 100%; text-align: left; font-size: 1rem; cursor: pointer; padding: 0; }
.link.danger { color: var(--miss); }
.page p { margin: 0 0 12px; }
.mini { display: grid; grid-template-columns: repeat(3, 48px); gap: 5px; justify-content: center; margin: 16px 0; padding: 8px; background: var(--paper-2); border-radius: 14px; width: max-content; margin-left: auto; margin-right: auto; }
.mini span { width: 48px; height: 48px; display: grid; place-items: center; background: var(--tile); border: 1px solid var(--tile-edge); border-radius: 8px; font: 500 1.6rem var(--mincho); }
.mini span.on { box-shadow: inset 0 0 0 2px var(--gold); background: color-mix(in srgb, var(--tile) 75%, var(--gold-glow)); }
pre.dbg { font-size: .7rem; white-space: pre-wrap; background: var(--paper-2); padding: 8px; border-radius: 8px; overflow: auto; }

/* ---- 重ね画面・お知らせ ---- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 100; animation: fadein .15s; }
.sheet { background: var(--paper); width: 100%; max-width: 430px; border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 88vh; overflow: auto; }
.sheet h3 { margin: 0 0 8px; font: 700 1.3rem var(--mincho); text-align: center; }
.sheet .stack { margin-top: 12px; }
#toast {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translate(-50%, 10px); max-width: calc(100% - 32px);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 99px; font-size: .95rem; opacity: 0;
  pointer-events: none; transition: opacity .2s, transform .2s; z-index: 200; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
textarea.manual { width: 100%; height: 120px; font: 1rem var(--gothic); background: var(--tile); color: var(--ink); border: 1px solid var(--tile-edge); border-radius: 10px; padding: 8px; }

/* ---- 仮の広告(ads.js が作る) ---- */
.ad-ov { position: fixed; inset: 0; z-index: 1000; background: #111; color: #f2f2f2; display: flex; align-items: center; justify-content: center; padding: 24px; }
.ad-box { width: 100%; max-width: 380px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.ad-top { margin: 0; font-size: 1rem; background: #2b2b2b; padding: 8px 14px; border-radius: 10px; }
.ad-main { font: 700 2.6rem/1.3 var(--gothic); margin-top: 40px; letter-spacing: .05em; }
.ad-sub { margin: 0; color: #c8c8c8; font-size: .95rem; }
.ad-sec { font: 700 3rem/1 var(--gothic); min-height: 3rem; margin: 20px 0; color: #ffd76a; }
.ad-msg { margin: 0; min-height: 1.5em; color: #ffb3a8; }
.ad-close { min-width: 160px; min-height: 48px; border-radius: 99px; border: 1px solid #888; background: #2b2b2b; color: #fff; font-size: 1rem; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }
  .ink line.new, .ink line.ans { stroke-dashoffset: 0 !important; }
  .hand { display: none; }
}
@media (min-width: 700px) { body { background: var(--paper-2); } #app { background: var(--paper); box-shadow: 0 0 24px var(--shadow); } }

/* 横向き:縦にしてもらう(Android アプリでは縦に固定する) */
#rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  #rotate { display: flex; position: fixed; inset: 0; z-index: 2000; align-items: center; justify-content: center; flex-direction: column; gap: 8px;
    background: var(--paper); color: var(--ink); font: 700 1.3rem/1.5 var(--mincho); text-align: center; padding: 16px; }
  #rotate span { font-size: 2.4rem; }
  #app, #toast { display: none; }
}

/* 盤の下:いま◯つ と 最長 ◯(答えは出さない) */
.play-foot .count { display: flex; flex-direction: column; line-height: 1.2; }
.play-foot .count .lmax { font: 600 .8rem/1.3 var(--gothic); color: var(--gold-text); }
/* 練習の結果:熟語帳 +N は「新しい熟語」の行の中に(数の箱に重ならない) */
.nwlabel .plus { display: inline-block; margin-left: 8px; padding: 0 10px; border-radius: 99px; background: var(--gold-text); color: var(--paper); font-weight: 700; font-size: .8rem; animation: plusin .5s ease-out; }
@keyframes plusin { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
