:root {
  --bg: #1d1a17; --panel: #2a2520; --panel2: #352e27; --line: #4a4036; --ink: #f4ead9; --sub: #c2b59e;
  --gold: #f2c14e; --red: #e8643c; --green: #6cc070; --blue: #4f9ce8;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
html { font-size: 17px; }
html.fz1 { font-size: 19.5px; }
html.fz2 { font-size: 22px; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #0f0d0b; color: var(--ink); overscroll-behavior: none; }
body { font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
.hidden { display: none !important; }

#app { position: relative; max-width: 480px; height: 100%; margin: 0 auto; background: var(--bg); overflow: hidden; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* タイトル */
#title { align-items: center; justify-content: center; background: radial-gradient(circle at 50% 30%, #3b4a2f, #1d1a17 70%); }
.title-box { text-align: center; padding: 24px; }
.kicker { color: var(--sub); margin: 0 0 6px; font-size: 0.9rem; }
h1 { font-size: 2.4rem; margin: 0 0 14px; letter-spacing: 0.08em; color: var(--gold); text-shadow: 0 3px 0 #6b4a1a; }
.lead { line-height: 1.7; margin: 0 0 22px; }
.font-row { margin: 0 0 22px; color: var(--sub); font-size: 0.95rem; }
.font-row button { margin-left: 6px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
.font-row button.on { background: var(--gold); color: #2a1d08; border-color: var(--gold); }
button.big { display: block; width: 100%; padding: 15px; border: 0; border-radius: 14px; background: linear-gradient(#f6cf6a, #d99a2b); color: #2a1d08; font-weight: 800; font-size: 1.15rem; box-shadow: 0 4px 0 #8a5a14; }
button.big:active { transform: translateY(2px); box-shadow: 0 2px 0 #8a5a14; }
button.mid { padding: 13px 10px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel2); font-weight: 700; position: relative; }
button.link { background: none; border: 0; color: var(--sub); text-decoration: underline; margin-top: 16px; }
.badge { position: absolute; top: -8px; right: -6px; background: var(--red); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 0.8rem; }

/* 上の帯 */
#topbar { display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--safe-t)) 8px 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
.arrow { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); }
.arrow:disabled { opacity: 0.25; }
.area-name { flex: 1; text-align: center; font-weight: 800; font-size: 1.1rem; }
.area-name small { display: block; font-weight: 400; font-size: 0.8rem; color: var(--sub); }

.tab { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 12px 16px; }
#tab-field { display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
#tab-field > * { flex: none; }
#tab-field #finds { flex: 1 1 0; min-height: 0; overflow: hidden; }
html.fz2 #field { height: 34vh; min-height: 210px; }

/* 戦いの場 */
#field { position: relative; height: 40vh; min-height: 250px; max-height: 360px; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); display: flex; flex-direction: column; justify-content: space-between; padding: 10px 6px 16px; }
.row { display: flex; justify-content: center; gap: 4px; }
.unit { position: relative; width: 19%; max-width: 78px; text-align: center; transition: transform 0.12s, opacity 0.3s; }
.unit .pic { width: 100%; aspect-ratio: 1; display: block; object-fit: contain; filter: drop-shadow(0 3px 3px rgba(0,0,0,.5)); }
.unit.big { width: 34%; max-width: 140px; }
.unit .hp { height: 6px; width: 80%; margin-left: auto; margin-right: auto; background: rgba(0,0,0,0.5); border-radius: 3px; overflow: hidden; margin-top: 2px; }
.unit .hp i { display: block; height: 100%; background: var(--green); transition: width 0.2s; }
.unit.down { opacity: 0.2; }
.unit.act { transform: translateY(-6px) scale(1.06); }
.unit.hurt { animation: shake 0.2s; }
.unit .zz { position: absolute; top: -4px; right: 0; font-size: 0.8rem; }
#allies .unit.act { transform: translateY(-10px) scale(1.06); }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
#fx { position: absolute; inset: 0; pointer-events: none; }
.dmg { position: absolute; font-weight: 900; font-size: 1.1rem; color: #fff; text-shadow: 0 2px 0 #000, 0 0 4px #000; animation: rise 0.8s forwards; }
.dmg.good { color: var(--gold); font-size: 1.3rem; }
.dmg.heal { color: #8ef08e; }
@keyframes rise { to { transform: translateY(-28px); opacity: 0; } }
.banner { position: absolute; left: 0; right: 0; top: 42%; text-align: center; font-weight: 900; font-size: 1.3rem; color: var(--gold); text-shadow: 0 2px 0 #000; background: rgba(0,0,0,0.55); padding: 8px; animation: pop 1.4s forwards; }
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 15% { transform: scale(1.05); opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
#run-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: rgba(0,0,0,0.4); }
#run-bar i { display: block; height: 100%; width: 0; background: var(--gold); }

.mark-box { display: flex; align-items: center; gap: 10px; text-align: left; padding: 8px 10px; border-radius: 14px; border: 1px dashed var(--gold); background: rgba(242,193,78,0.08); }
.mark-box .pic { width: 48px; height: 48px; flex: none; }
.mark-box .t { flex: 1; font-size: 0.92rem; line-height: 1.45; }
.mark-box .bar { height: 7px; background: rgba(0,0,0,0.4); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.mark-box .bar i { display: block; height: 100%; background: var(--gold); }

#finds { display: flex; flex-direction: column; gap: 4px; }
.find { font-size: 0.92rem; padding: 6px 10px; background: var(--panel); border-radius: 10px; display: flex; gap: 8px; align-items: center; animation: slidein 0.3s; }
.find .new { background: var(--red); color: #fff; font-size: 0.75rem; padding: 1px 6px; border-radius: 6px; font-weight: 800; }
@keyframes slidein { from { transform: translateX(-20px); opacity: 0; } }
.actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: auto; }
button.boss { background: linear-gradient(#ef8a5a, #c4462a); color: #fff; box-shadow: 0 4px 0 #6f2412; }

/* 下のタブ */
#tabs { display: flex; border-top: 1px solid var(--line); background: var(--panel); padding-bottom: var(--safe-b); }
#tabs button { flex: 1; padding: 13px 0; border: 0; background: none; color: var(--sub); font-weight: 700; }
#tabs button.on { color: var(--gold); box-shadow: inset 0 3px 0 var(--gold); }

/* 部隊・図鑑 */
h2 { font-size: 1.05rem; margin: 14px 2px 8px; color: var(--gold); }
h2:first-child { margin-top: 2px; }
.note { color: var(--sub); font-size: 0.9rem; line-height: 1.6; margin: 4px 2px 10px; }
.party-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.slot { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; text-align: center; font-size: 0.8rem; min-height: 90px; }
.slot .pic { width: 100%; aspect-ratio: 1; }
.slot.empty { display: flex; align-items: center; justify-content: center; color: var(--sub); }
.combo-on { background: rgba(242,193,78,0.12); border: 1px solid var(--gold); border-radius: 12px; padding: 8px 10px; margin: 6px 0; font-size: 0.92rem; line-height: 1.5; }
.mon-list { display: flex; flex-direction: column; gap: 6px; }
.mon { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px; text-align: left; width: 100%; }
.mon .pic { width: 54px; height: 54px; flex: none; }
.mon .t { flex: 1; line-height: 1.4; font-size: 0.92rem; }
.mon .t b { font-size: 1rem; }
.mon .in { font-size: 0.8rem; padding: 6px 8px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.mon .in.on { background: var(--gold); color: #2a1d08; }
.chip { display: inline-block; font-size: 0.75rem; padding: 0 6px; border-radius: 6px; color: #fff; margin-right: 4px; }
.star { color: var(--gold); letter-spacing: -1px; }
.row-btns { display: flex; gap: 8px; margin: 8px 0; }
.row-btns button { flex: 1; }
.book { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.book .cell { background: var(--panel); border-radius: 12px; padding: 6px; text-align: center; font-size: 0.85rem; border: 1px solid var(--line); }
.book .cell .pic { width: 100%; aspect-ratio: 1; }
.book .cell.unknown .pic { filter: brightness(0) opacity(0.5); }
.combo { background: var(--panel); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; font-size: 0.92rem; line-height: 1.55; border: 1px solid var(--line); }
.combo.found { border-color: var(--gold); }
.combo .h { font-weight: 800; color: var(--gold); }

/* 下から出る板 */
.sheet { position: absolute; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-end; z-index: 20; }
.sheet-body { width: 100%; max-height: 88%; overflow-y: auto; background: var(--bg); border-radius: 18px 18px 0 0; padding: 16px 14px calc(16px + var(--safe-b)); border-top: 2px solid var(--gold); }
.sheet-body.full { max-height: 100%; height: 100%; border-radius: 0; }
.sheet h3 { margin: 0 0 10px; color: var(--gold); font-size: 1.15rem; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 0.95rem; margin: 8px 0; }
.eq { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; width: 100%; text-align: left; font-size: 0.92rem; }
.eq .slotname { color: var(--sub); width: 3.5em; flex: none; }
.eq.new::after { content: "New"; background: var(--red); color: #fff; font-size: 0.7rem; padding: 0 5px; border-radius: 5px; margin-left: auto; }
.close { margin-top: 12px; }

/* 報告と主との一戦 */
.rep-head { text-align: center; margin-bottom: 10px; }
.rep-head .big-n { font-size: 2rem; font-weight: 900; color: var(--gold); }
.rep-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rep-grid .cell { text-align: center; font-size: 0.8rem; position: relative; }
.rep-grid .cell .pic { width: 100%; aspect-ratio: 1; }
.rep-grid .new { position: absolute; top: 0; left: 0; background: var(--red); color: #fff; font-size: 0.7rem; padding: 0 5px; border-radius: 5px; font-weight: 800; }
.result { text-align: center; font-size: 2rem; font-weight: 900; margin: 6px 0; }
.result.g3 { color: var(--gold); font-size: 2.6rem; text-shadow: 0 0 18px rgba(242,193,78,0.8); }
.result.g2 { color: var(--gold); }
.result.g1 { color: #f0dfa8; font-size: 1.8rem; }
.result.lose { color: var(--sub); }
.reason { background: var(--panel); border-radius: 12px; padding: 10px 12px; line-height: 1.65; font-size: 0.95rem; }
.reason .hint { color: var(--gold); margin-top: 6px; }
#boss-field { height: 46vh; min-height: 280px; }

#toast { position: absolute; left: 12px; right: 12px; bottom: calc(76px + var(--safe-b)); z-index: 30; background: rgba(20,16,10,0.95); border: 2px solid var(--gold); border-radius: 14px; padding: 12px; text-align: center; font-weight: 800; line-height: 1.5; animation: pop 3s forwards; }
textarea { width: 100%; height: 90px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; font-size: 0.8rem; -webkit-user-select: text; user-select: text; }

#rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  #rotate { display: flex; position: fixed; inset: 0; z-index: 99; background: var(--bg); align-items: center; justify-content: center; font-size: 1.2rem; }
}

.hint { position: absolute; top: calc(10px + var(--safe-t)); left: 10px; right: 10px; z-index: 5; background: rgba(20,16,10,0.95); border: 1px solid var(--gold); border-radius: 12px; padding: 12px 40px 12px 12px; font-size: 0.95rem; line-height: 1.6; }
.hint button { position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; border: 0; background: none; font-size: 1.2rem; }
