:root {
  --ink: #3b2416;
  --ink-soft: #6a4630;
  --cream: #f7ead0;
  --paper: #fff6e4;
  --gold: #e0b14a;
  --gold-deep: #a56b12;
  --rose: #c45c6a;
  --navy: #2c3a62;
  --hp: #d4534a;
  --mp: #4aa3d4;
  --ok: #3d9a62;
  --shadow: 0 8px 24px rgba(40, 18, 8, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: #1a120e;
  color: var(--ink);
  font-family: "Zen Maru Gothic", "Hiragino Sans", "Yu Gothic", sans-serif;
  overflow: hidden;
}

button { cursor: pointer; font-family: inherit; }
body { overscroll-behavior: none; touch-action: manipulation; }
img { display: block; max-width: 100%; pointer-events: none; user-select: none; }

#app {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 20%, #4a2c1c 0%, #1a120e 70%);
}

#phone {
  position: relative;
  width: min(100vw, 430px);
  height: 100dvh;
  max-height: 100dvh;
  background: #000;
  overflow: hidden;
  box-shadow: 0 0 0 2px #6a4a2a, var(--shadow);
}

@media (min-width: 500px) {
  #phone {
    height: min(100dvh, 920px);
    border-radius: 28px;
  }
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.on { display: flex; }

/* ===== Title ===== */
#screen-title {
  background: #1a120e url("../assets/bg/bg-title.png") center/cover no-repeat;
  align-items: center;
  justify-content: flex-end;
  padding: calc(24px + var(--safe-bot)) 20px 36px;
}
#screen-title .veil {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(20,10,6,.15) 30%, rgba(20,10,6,.72) 78%, rgba(12,6,4,.9) 100%);
}
.title-inner { position: relative; z-index: 1; width: 100%; text-align: center; }
.title-emblem { width: 210px; margin: 0 auto 8px; filter: drop-shadow(0 8px 16px rgba(0,0,0,.45)); }
.title-logo {
  font-family: "Shippori Mincho", serif;
  font-size: 34px;
  letter-spacing: .08em;
  color: #fff6d8;
  text-shadow: 0 2px 0 #8a5a12, 0 8px 18px rgba(0,0,0,.6);
}
.title-sub { color: #f0d7a4; margin: 6px 0 22px; font-size: 13px; letter-spacing: .18em; }
.title-actions { display: flex; flex-direction: column; gap: 10px; }

/* ===== Shared chrome ===== */
.topbar {
  position: relative;
  z-index: 5;
  padding: calc(8px + var(--safe-top)) 10px 8px;
  background: linear-gradient(180deg, rgba(28,16,10,.82), rgba(28,16,10,.45) 70%, transparent);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.topbar-row { display: flex; align-items: center; gap: 6px; }
.company-chip {
  display: flex; align-items: center; gap: 6px;
  min-width: 0; flex: 1;
  color: #fff4d6;
  font-size: 12px;
  font-weight: 700;
}
.company-chip img { width: 28px; height: 28px; object-fit: contain; }
.res-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.res {
  display: flex; align-items: center; gap: 3px;
  background: rgba(255,246,228,.92);
  border: 1px solid #d9b56a;
  border-radius: 999px;
  padding: 2px 7px 2px 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  box-shadow: 0 2px 0 rgba(90,50,10,.2);
  flex: 1;
  min-width: 0;
}
.res img { width: 22px; height: 22px; object-fit: contain; }
.res b { font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.botnav {
  position: relative;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  padding: 6px 6px calc(8px + var(--safe-bot));
  background:
    linear-gradient(180deg, rgba(42,24,14,.2), rgba(42,24,14,.92)),
    #2a180e;
  border-top: 2px solid #c9a056;
}
.botnav button {
  appearance: none;
  border: 0;
  background: transparent;
  color: #e8d2a8;
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0 2px;
}
.botnav button img { width: 36px; height: 36px; object-fit: contain; filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.botnav button.on { color: #fff4c2; }
.botnav button.on img { transform: translateY(-2px) scale(1.06); }

/* ===== Buttons made from PNG ===== */
.btn {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 52px;
  padding: 10px 18px 14px;
  border: 0;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  color: #fffdf4;
  font: inherit;
  font-weight: 800;
  letter-spacing: .08em;
  text-shadow: 0 2px 0 rgba(60,20,0,.55);
  cursor: pointer;
}
.btn-gold { background-image: url("../assets/ui/ui-btn-gold.png"); }
.btn-pink { background-image: url("../assets/ui/ui-btn-pink.png"); color: #5a2030; text-shadow: 0 1px 0 rgba(255,255,255,.45); }
.btn-blue { background-image: url("../assets/ui/ui-btn-blue.png"); }
.btn:active { transform: scale(.98); filter: brightness(.96); }
.btn:disabled { filter: grayscale(.4) brightness(.8); pointer-events: none; }
.btn.sm { min-height: 42px; font-size: 13px; padding: 6px 14px 10px; }
.btn.tiny { min-height: 36px; font-size: 12px; padding: 4px 10px 8px; letter-spacing: .04em; }

/* ===== Home ===== */
#screen-home .stage,
#stage.tab-home {
  background: #2a1a10 url("../assets/bg/bg-office.png") center/cover no-repeat;
}
.home-char-wrap {
  position: absolute;
  left: 0; right: 0; bottom: 108px; top: 8px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.home-char-wrap img.stand {
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 12px 18px rgba(0,0,0,.4));
  animation: idle 3.2s ease-in-out infinite;
  cursor: pointer;
  pointer-events: auto;
}
@keyframes idle {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.home-nameplate {
  position: absolute;
  left: 12px; top: 8px;
  background: url("../assets/ui/ui-btn-gold.png") center/100% 100% no-repeat;
  padding: 8px 18px 12px;
  min-width: 140px;
  color: #fff;
  font-size: 12px;
  text-shadow: 0 1px 0 #5a2008;
}
.home-nameplate b { display: block; font-size: 15px; }
.home-nameplate span { opacity: .9; }

.dialogue {
  position: absolute;
  left: 10px; right: 10px; bottom: 8px;
  height: 96px;
  background: url("../assets/ui/ui-dialogue.png") center/100% 100% no-repeat;
  padding: 18px 22px 16px 20px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  display: flex;
  align-items: center;
}
.home-side {
  position: absolute;
  right: 8px;
  top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.icon-fab {
  position: relative;
  width: 58px; height: 58px;
  border: 0;
  background: rgba(255,246,228,.92);
  border-radius: 16px;
  box-shadow: 0 4px 0 #c9a056, var(--shadow);
  font: inherit;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink);
  display: grid;
  place-items: center;
  text-align: center;
  line-height: 1.2;
}
.icon-fab.alert::after {
  content: "!";
  position: absolute;
  margin-top: -28px;
  margin-left: 22px;
  background: #d4534a;
  color: #fff;
  width: 16px; height: 16px;
  border-radius: 50%;
  font-size: 11px;
  line-height: 16px;
}

/* ===== Scroll pages ===== */
.page {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px 16px;
}
.page.bg-quest { background: #2a1a10 url("../assets/bg/bg-quest.png") center/cover no-repeat; }
.page.bg-paper {
  background:
    linear-gradient(180deg, rgba(42,24,14,.28), rgba(42,24,14,.55)),
    url("../assets/bg/bg-office.png") center/cover no-repeat;
}
.panel {
  background: url("../assets/ui/ui-panel.png") center/100% 100% no-repeat;
  padding: 28px 22px 26px;
  margin-bottom: 10px;
  color: var(--ink);
}
.panel h2, .hd {
  font-family: "Shippori Mincho", serif;
  font-size: 16px;
  margin-bottom: 8px;
  color: #5a2e12;
  text-align: center;
}
.muted { color: var(--ink-soft); font-size: 12px; line-height: 1.5; }

/* ===== Recruit ===== */
.env-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.env-card {
  position: relative;
  background: rgba(255,246,228,.78);
  border: 2px solid #c9a056;
  border-radius: 14px;
  padding: 8px 8px 10px;
  text-align: center;
  box-shadow: 0 6px 0 rgba(90,50,10,.18);
}
.env-card img.env { width: 100%; height: 92px; object-fit: contain; margin: 0 auto; }
.env-card .who { font-size: 13px; font-weight: 800; margin-top: 4px; }
.stars { letter-spacing: 1px; display: flex; justify-content: center; gap: 1px; }
.stars img { width: 16px; height: 16px; }

.card-hero {
  position: relative;
  width: min(260px, 70%);
  margin: 0 auto 8px;
  aspect-ratio: 2/3;
}
.card-hero .stand {
  position: absolute; inset: 8% 10% 6%;
  width: 80%; height: 90%;
  object-fit: contain;
  object-position: bottom center;
  margin: 0 auto;
  left: 10%;
}
.card-hero .frame {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: fill;
  pointer-events: none;
}

/* ===== Quest ===== */
.tabs {
  display: flex; gap: 6px; margin-bottom: 8px;
}
.tabs button {
  flex: 1;
  border: 0;
  background: rgba(255,246,228,.75);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  padding: 8px 4px;
  border-radius: 10px;
  border: 1px solid #c9a056;
}
.tabs button.on { background: #c44536; color: #fff; border-color: #8a2a20; }
.q-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  background: rgba(255,246,228,.88);
  border: 2px solid #c9a056;
  border-radius: 12px;
  padding: 10px 10px;
  margin-bottom: 8px;
}
.q-card.lock { opacity: .55; }
.q-card h3 { font-size: 14px; }
.q-meta { font-size: 11px; color: var(--ink-soft); display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.q-meta img { width: 16px; height: 16px; }

.party-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 8px 0;
}
.slot {
  background: rgba(255,246,228,.9);
  border: 2px solid #c9a056;
  border-radius: 12px;
  overflow: hidden;
  text-align: center;
  min-height: 132px;
}
.slot .bust {
  width: 100%;
  height: 96px;
  object-fit: cover;
  object-position: 50% 8%;
  background: linear-gradient(#d7e6f0, #f3e6d2);
}
.slot .nm { font-size: 11px; font-weight: 800; padding: 4px 2px 6px; }
.slot.empty { display: grid; place-items: center; color: var(--ink-soft); font-size: 12px; }

/* ===== Staff grid ===== */
.staff-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.staff-card {
  position: relative;
  background: rgba(255,246,228,.9);
  border: 2px solid #c9a056;
  border-radius: 12px;
  overflow: hidden;
  text-align: center;
}
.staff-card .bust {
  width: 100%; height: 110px;
  object-fit: cover;
  object-position: 50% 10%;
  background: linear-gradient(#d7e6f0, #f3e6d2);
}
.staff-card .nm { font-size: 12px; font-weight: 800; padding: 4px 2px 2px; }
.staff-card .sub { font-size: 10px; color: var(--ink-soft); padding-bottom: 6px; }
.badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  color: #fff;
  background: #c44536;
}

/* ===== Facilities ===== */
.fac-list { display: flex; flex-direction: column; gap: 8px; }
.fac {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px;
  background: rgba(255,246,228,.9);
  border: 2px solid #c9a056;
  border-radius: 14px;
  padding: 8px;
  align-items: center;
}
.fac img { width: 76px; height: 76px; object-fit: contain; }
.fac h3 { font-size: 14px; }
.bar {
  height: 8px;
  background: #e8d2b0;
  border-radius: 99px;
  overflow: hidden;
  margin: 4px 0;
}
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #e0b14a, #c44536); }

/* ===== Battle ===== */
#screen-battle { background: #000; }
#screen-battle .stage {
  background: #243018 url("../assets/bg/bg-battle.png") center/cover no-repeat;
}
.battle-hud {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
}
.wave-label {
  align-self: center;
  margin-top: 6px;
  background: rgba(20,10,6,.55);
  color: #fff4d6;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 99px;
}
.foes, .allies {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px;
}
.foes { flex: 1; align-items: flex-end; padding-bottom: 8px; }
.allies { padding-bottom: 8px; }
.unit {
  width: 104px;
  text-align: center;
  position: relative;
}
.unit img.spr {
  width: 100%;
  height: 120px;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 6px 8px rgba(0,0,0,.45));
  pointer-events: none;
}
.unit.ally img.spr { height: 132px; }
.unit.dead { opacity: .35; filter: grayscale(1); }
.unit.hit img.spr { animation: shake .25s; }
.unit.slash img.spr { animation: pop .28s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.12) translateY(-8px); }
  100% { transform: scale(1); }
}
.hpbar {
  height: 8px;
  background: #3a2218;
  border: 1px solid #f0d7a4;
  border-radius: 99px;
  overflow: hidden;
  margin-top: 2px;
}
.hpbar > i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #e06a4a, #d4534a); }
.unit .nm { color: #fff4d6; font-size: 10px; text-shadow: 0 1px 2px #000; }
.float-dmg {
  position: absolute;
  left: 50%; top: 18px;
  transform: translateX(-50%);
  color: #fff;
  font-weight: 900;
  font-size: 18px;
  text-shadow: 0 2px 0 #8a2010;
  animation: rise .7s ease-out forwards;
  pointer-events: none;
}
.float-dmg.heal { color: #b8f0c4; text-shadow: 0 2px 0 #1a5a2a; }
@keyframes rise {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -28px); }
}
.blog {
  margin: 0 10px;
  height: 64px;
  overflow: hidden;
  background: rgba(20,10,6,.55);
  color: #fff4d6;
  font-size: 11px;
  padding: 6px 8px;
  border-radius: 8px;
  line-height: 1.35;
}
.battle-act {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  padding: 8px 10px calc(10px + var(--safe-bot));
}
.pw {
  position: relative;
  grid-column: 1 / -1;
  height: 10px;
  background: #3a2218;
  border: 1px solid #f0d7a4;
  border-radius: 99px;
  overflow: hidden;
}
.pw > i { display: block; height: 100%; background: linear-gradient(90deg, #7ec8e8, #f4d76a); width: 0%; }

/* ===== Modal ===== */
.modal {
  position: absolute; inset: 0;
  background: rgba(12,6,4,.62);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 18px;
}
.modal.on { display: flex; }
.modal .sheet {
  position: relative;
  width: 100%;
  max-height: 86%;
  overflow-y: auto;
  background: url("../assets/ui/ui-panel.png") center/100% 100% no-repeat;
  padding: 36px 24px 28px;
}
.modal-x {
  position: sticky;
  top: 0;
  float: right;
  z-index: 2;
  width: 32px; height: 32px;
  border: 0;
  border-radius: 50%;
  background: #c44536;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  margin: -8px -8px 0 0;
}
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  font-size: 12px;
  margin: 8px 0;
}
.toast {
  position: absolute;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  background: rgba(28,16,10,.92);
  color: #fff4d6;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12px;
  z-index: 30;
  display: none;
  border: 1px solid #c9a056;
  max-width: 86%;
  text-align: center;
}
.toast.on { display: block; animation: fade .25s; }
@keyframes fade { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.eq-row { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; margin: 4px 0; }
.cost { display: flex; flex-wrap: wrap; gap: 6px; font-size: 11px; align-items: center; }
.cost span { display: inline-flex; align-items: center; gap: 2px; }
.cost img { width: 16px; height: 16px; }

.result-list { font-size: 13px; line-height: 1.7; text-align: center; }
.hidden { display: none !important; }
.center { text-align: center; }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }

.leader-tag {
  position: absolute; left: 4px; top: 4px;
  background: #c44536; color: #fff;
  font-size: 9px; padding: 1px 5px; border-radius: 6px;
  z-index: 1;
}
