:root {
  --ink: #1b1d3a;
  --hot: #ff4d4d;
  --gold: #ffcc33;
  --paper: #fff8e8;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%; margin: 0; overflow: hidden; background: #15173a;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  color: var(--ink);
  -webkit-user-select: none; user-select: none;
  touch-action: none;
}
button { font: inherit; }

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* パネル */
#title, #result, #sharebox {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(10, 12, 30, .55);
}
#hallbox[hidden], #minnainfo[hidden], #legendbox[hidden], #certbox[hidden], #title[hidden], #result[hidden], #sharebox[hidden], #slotbox[hidden], #handoff[hidden], #draw[hidden], #friendbox[hidden], button[hidden] { display: none; }
.panel {
  width: min(92vw, 400px); max-height: calc(100% - 20px); overflow-y: auto;
  background: var(--paper); border: 4px solid var(--ink); border-radius: 18px; box-shadow: var(--shadow);
  padding: 18px 16px; text-align: center;
}
.logo {
  font-weight: 900; font-size: min(44px, 11vw); line-height: 1.05; color: var(--hot);
  text-shadow: 3px 3px 0 var(--ink); letter-spacing: 1px;
}
.lead { margin-top: 8px; font-weight: 700; font-size: 14px; }
#rival {
  margin-top: 10px; padding: 8px; border-radius: 10px; background: #ffe7a8; border: 2px solid var(--ink);
  font-weight: 800; font-size: 15px;
}
#tbest { margin-top: 8px; font-size: 14px; font-weight: 700; opacity: .8; }
.howto { list-style: none; padding: 0; margin: 12px 0 14px; text-align: left; font-size: 13px; line-height: 1.7; }
.howto li { padding-left: 4px; }
.howto b { color: var(--hot); }
.howto b.k { display: inline-block; min-width: 92px; }

.main, .sub {
  border: 3px solid var(--ink); border-radius: 14px; padding: 10px 22px; font-weight: 800; font-size: 18px; cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
}
.main { background: var(--hot); color: #fff; }
button.sub { background: #fff; color: var(--ink); margin-top: 0; font-size: 16px; }
.main:active, button.sub:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

.rtitle { font-weight: 900; font-size: 22px; }
.rnum { font-weight: 900; font-size: 64px; line-height: 1.1; color: var(--hot); font-variant-numeric: tabular-nums; text-shadow: 3px 3px 0 var(--ink); }
.rnum .unit { font-size: 28px; margin-left: 4px; }
.rsub { font-weight: 700; font-size: 14px; margin-top: 4px; }
.rbest { font-weight: 800; font-size: 15px; margin-top: 6px; min-height: 1.2em; }
.rbest.new { color: #d08a00; }
.rbtns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

#shareimg { width: 100%; border-radius: 10px; border: 2px solid var(--ink); }
.note { font-size: 12px; margin: 6px 0; }
#sharetext { width: 100%; height: 84px; font-size: 13px; border-radius: 8px; border: 2px solid var(--ink); padding: 6px; resize: none; }

.howto b { color: #1e88e5; }
#friendbox { margin: 10px auto 0; padding: 8px; border-radius: 12px; background: #e8f5e9; border: 2px solid var(--ink); }
.fb-title { font-weight: 900; font-size: 15px; color: #2e7d32; }
#friendprev { width: 110px; height: 110px; display: block; margin: 4px auto 0; }
#tprog { margin-top: 8px; font-weight: 800; font-size: 14px; color: #d08a00; min-height: 1em; }

/* 描く画面 */
#draw {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(#15173a, #2a1f4f); color: #fff;
}
.dhead { font-weight: 800; font-size: 16px; }
.dhead b { color: #ffd600; }
#pad { border-radius: 16px; border: 3px solid #7c83ff; touch-action: none; box-shadow: 0 0 20px rgba(124,131,255,.4); }
#hint { min-height: 1.3em; font-weight: 800; font-size: 14px; line-height: 1.35; color: #ff8a80; text-align: center; }
#draw { overflow-y: auto; justify-content: flex-start; gap: 8px; }
#draw > * { flex-shrink: 0; }   /* 縦が足りなくても 縮めて重ねない */
#draw > :first-child { margin-top: auto; }   /* まんなか寄せ。はみ出しても 上が切れない */
#draw > :last-child { margin-bottom: auto; }
/* Safari（ホーム画面から開いていない）: 下のバーが 画面に重なって浮くので あける */
body.browser #draw { padding-bottom: calc(max(12px, env(safe-area-inset-bottom)) + 64px); }
#draw .rbtns.small { flex-wrap: nowrap; gap: 6px; margin-top: 0; }
#draw .rbtns.small button { font-size: 13px; padding: 7px 10px; white-space: nowrap; }
.stats { width: min(100%, 340px); display: grid; gap: 6px; }
.st { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 8px; font-weight: 800; font-size: 13px; }
.bar { height: 12px; border-radius: 6px; background: rgba(255,255,255,.15); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 6px; background: linear-gradient(90deg, #7c83ff, #ffd600); transition: width .15s; }
#draw .rbtns { margin-top: 4px; }
.rbtns.small { margin-top: 8px; }
.rbtns.small button { font-size: 14px; padding: 8px 16px; }
button.friend { background: #2e7d32; }
button:disabled { opacity: .45; }

/* 結果 */
.rtitle.win { color: #d08a00; font-size: 44px; text-shadow: 3px 3px 0 var(--ink); }
.rtitle.lose { color: #1e88e5; font-size: 40px; }
#rprog { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; font-size: 12px; font-weight: 800; }
#rprog .dot { padding: 3px 7px; border-radius: 10px; border: 2px solid var(--ink); background: #eee; opacity: .6; }
#rprog .dot.ok { background: #ffd54f; opacity: 1; }
#rprog .dot.now { background: #fff; opacity: 1; outline: 2px solid var(--hot); }
#rprog .dot.lost { background: #ffcdd2; opacity: 1; text-decoration: line-through; }

/* パーツのタブ */
.tabs { display: flex; gap: 6px; }
.tab { border: 2px solid #7c83ff; background: transparent; color: #c5c8ff; border-radius: 999px; padding: 6px 16px; font-weight: 800; font-size: 15px; }
.tab.done { color: #fff; }
.tab.done::after { content: ' ✓'; color: #ffd600; }
.tab.on { background: #7c83ff; color: #fff; }
#pad { touch-action: none; }

#stats { width: min(100%, 340px); gap: 4px; }
#stats .st { grid-template-columns: 56px minmax(0, 1fr) 36px; font-size: 12px; }
#stats em { font-style: normal; font-weight: 800; font-size: 12px; text-align: right; color: #ffd600; }
#stats .bar { height: 9px; }

/* 戦いの途中で もどる（押しまちがえないよう 左上の HP バーの下に 小さく） */
#quit { position: fixed; left: 10px; top: calc(env(safe-area-inset-top) + 60px); font-size: 12px; padding: 4px 10px; border-width: 2px; box-shadow: 0 2px 0 var(--ink); opacity: .85; }
#fast { position: fixed; right: 10px; top: calc(env(safe-area-inset-top) + 60px); font-size: 12px; padding: 4px 10px; border-width: 2px; box-shadow: 0 2px 0 var(--ink); opacity: .85; }
#fast.on { background: #ffd54f; }

/* たたかうボタンの行: おもて/うら・たたかう・ともだち を 横 1 行に（描く範囲を せまくしない） */
.fightrow { display: flex; gap: 6px; width: min(100%, 380px); align-items: stretch; }
.fightrow button { margin: 0; }
.fightrow .main { flex: 1 1 auto; padding: 6px 10px; font-size: 18px; line-height: 1.15; }
.fightrow .main small { display: block; font-size: 11px; font-weight: 700; opacity: .9; }
.fightrow .friend { flex: 0 0 auto; font-size: 15px; }
.fightrow .side { flex: 0 0 auto; border: 2px solid #7c83ff; background: transparent; color: #c5c8ff; border-radius: 14px; padding: 4px 10px; font-weight: 800; font-size: 13px; }
.fightrow .side.ura { background: #b71c1c; border-color: #ff5252; color: #fff; }
.main.ura { background: #7f0000; box-shadow: 0 4px 0 var(--ink), 0 0 16px rgba(255,60,60,.6); }
/* 強さのバーは 2 列 × 2 段 */
#stats { grid-template-columns: 1fr 1fr; column-gap: 14px; }
#stats .st { grid-template-columns: 44px minmax(0, 1fr) 26px; gap: 5px; }

.logo { font-size: min(38px, 9.5vw); }   /* かいて！／モンスターバトル を 2 行に */

/* モンスターの ほぞん（3 つ） */
#slotbox { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(10, 12, 30, .6); }
#slotlist { display: grid; gap: 8px; margin-top: 8px; }
.slot { display: grid; grid-template-columns: 22px 76px minmax(0, 1fr); align-items: center; gap: 8px; padding: 6px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; }
.slot b { font-size: 18px; }
.slot canvas { width: 76px; height: 76px; border-radius: 8px; background: #1f2250; }
.slot .sbtns { display: flex; flex-direction: column; gap: 6px; }
.slot .sbtns button { font-size: 14px; padding: 6px 8px; margin: 0; box-shadow: 0 2px 0 var(--ink); }
.slot .empty { font-size: 12px; opacity: .6; }
#slotmsg { min-height: 1.3em; margin-top: 8px; font-weight: 800; font-size: 13px; color: #d08a00; }

/* ふたりで たたかう */
.vsbtn { margin-top: 10px; background: #fff3e0; }
#handoff { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: #15173a; }

/* 結果の説明は こちらで決めた場所（
）で 改行、ボタンの 2 段目は 小さく */
#rsub { white-space: pre-line; line-height: 1.5; }
#result .main small { display: block; font-size: 12px; font-weight: 700; opacity: .9; }

/* 5 体の名前の札を 1 行に */
#rprog { gap: 3px; flex-wrap: nowrap; }
#rprog .dot { padding: 3px 5px; font-size: 11px; white-space: nowrap; }

/* タイトル: ボタンを上に、説明は 3 つの まとまり。ことばの 途中で 折れない（スペースの ところで 改行） */
.panel { word-break: keep-all; overflow-wrap: anywhere; }
.tbtns { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 12px 0 4px; }
.tbtns .vsbtn { margin-top: 0; }
#title .howto { text-align: left; margin: 14px 0 0; padding: 10px 12px; border-radius: 12px; background: rgba(27, 29, 58, .05); font-size: 13px; line-height: 1.6; }
#title .howto h3 { margin: 8px 0 2px; font-size: 14px; color: var(--hot); }
#title .howto h3:first-child { margin-top: 0; }
#title .howto p { margin: 0; }
#title .howto b { color: #1e88e5; }
#title .rules { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; margin: 0; }
#title .rules dt { font-weight: 800; color: #1e88e5; white-space: nowrap; }
#title .rules dd { margin: 0; }

#title .rules { row-gap: 6px; }
#title .rules dt, #title .rules dd { line-height: 1.35; }

/* でんどういり */
#hallbox { margin-top: 12px; padding: 8px; border-radius: 12px; border: 2px solid #d4a017; background: #fff8dc; }
.hall-title { font-weight: 900; font-size: 15px; color: #b8860b; }
#halllist { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 4px; }
#halllist .hall { display: flex; flex-direction: column; align-items: center; font-size: 10px; font-weight: 700; color: #7a5c00; }
#halllist canvas { width: 64px; height: 64px; border-radius: 8px; background: #1f2250; }

/* でんせつ（みんなの さいきょう ぐんだん を たおした） */
#legendbox { margin-top: 12px; padding: 8px; border-radius: 12px; border: 2px solid #26a69a; background: #e0f2f1; }
.legend-title { font-weight: 900; font-size: 15px; color: #00796b; }
#legendlist { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 4px; }
#legendlist .hall { display: flex; flex-direction: column; align-items: center; font-size: 10px; font-weight: 700; color: #00695c; cursor: pointer; }
#legendlist canvas { width: 64px; height: 64px; border-radius: 8px; background: #0f3d3a; }
.certbtn { background: #ffd54f; border-color: #b8860b; }
#certbox { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(4, 22, 26, .85); z-index: 30; }
#certbox .panel { max-height: 100%; overflow: auto; }
#certimg { display: block; width: 100%; max-width: 320px; margin: 8px auto 0; border-radius: 8px; }
.cert-note { font-weight: 800; font-size: 14px; color: #00796b; }

/* みんなの さいきょう ぐんだん へ さそう ボタン（青緑と 金） */
.main.minna { background: #00695c; border-color: #ffd54f; color: #fff; box-shadow: 0 4px 0 var(--ink), 0 0 16px rgba(255, 213, 79, .7); }
.main.minna small { display: block; font-size: 12px; font-weight: 700; opacity: .95; }

/* みんなの さいきょう ぐんだん の しょうかい */
#minnainfo { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(4, 22, 26, .88); z-index: 30; }
#minnainfo .panel { max-height: 100%; overflow: auto; border: 3px solid #ffd54f; }
.minna-title { font-size: 24px; font-weight: 900; color: #00695c; line-height: 1.2; }
#minnalist { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
#minnalist .hall { display: flex; flex-direction: column; align-items: center; font-size: 11px; font-weight: 800; color: #00695c; }
#minnalist canvas { width: 60px; height: 60px; border-radius: 8px; background: #0f3d3a; box-shadow: 0 0 8px rgba(255, 213, 79, .8); }
.minna-text { text-align: left; font-size: 13px; line-height: 1.6; margin-top: 8px; }
.minna-text p { margin: 4px 0; }
.minna-text b { color: #00796b; }
.linkbtn { background: none; border: none; box-shadow: none; color: #00796b; font-size: 12px; font-weight: 800; text-decoration: underline; padding: 2px 6px; margin: -2px 0 2px; }

.minna-flow { margin-top: 8px; font-size: 13px; line-height: 1.45; }
.minna-flow .mf { background: #e0f2f1; border-radius: 10px; padding: 5px 8px; }
.minna-flow .mf b, .mf-proof b, .mf-end b { color: #00796b; font-size: 15px; }
.mf-arrow { color: #26a69a; font-size: 11px; line-height: 1.2; }
.mf-proof { margin-top: 8px; padding: 6px 8px; border: 2px solid #ffd54f; border-radius: 10px; background: #fff8dc; font-size: 13px; font-weight: 700; line-height: 1.45; }
.mf-end { margin-top: 8px; font-size: 13px; font-weight: 700; line-height: 1.45; }
