* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

:root {
  --ink: #f0e8d8;
  --dim: #a99f8c;
  --card: #1c1723ee;
  --edge: #3a3244;
  --ember: #d8722b;
  --gold: #d9a441;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Nunito', system-ui, sans-serif;
  background: #131a2b;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }

.screen {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 100% at 50% 0%, #1d2438 0%, #10141f 70%);
  overflow-y: auto; padding: 20px; padding-top: max(20px, env(safe-area-inset-top));
}

.title-card { text-align: center; max-width: 720px; width: 100%; }
.title-logo { width: 92px; height: 92px; filter: drop-shadow(0 6px 18px #d8722b44); }
.wordmark {
  font-family: 'Cinzel', serif; font-weight: 800; letter-spacing: 0.09em;
  font-size: clamp(2rem, 7vw, 3.4rem); line-height: 1.1; margin: 8px 0 2px;
  background: linear-gradient(180deg, #f4e3c0, #d8722b);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--dim); margin-bottom: 18px; font-size: 0.95rem; }

#fac-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-bottom: 18px; text-align: left; }
.fac-card {
  background: var(--card); border: 2px solid var(--edge); border-radius: 14px;
  padding: 12px 14px; cursor: pointer; color: var(--ink); font: inherit;
  display: flex; flex-direction: column; gap: 4px; transition: border-color .15s, transform .15s;
}
.fac-card:hover { transform: translateY(-2px); }
.fac-card.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 8px 24px #0006; }
.fc-swatch { width: 34px; height: 12px; border-radius: 6px; }
.fc-name { font-weight: 800; font-size: 1.02rem; }
.fc-blurb { color: var(--dim); font-size: 0.82rem; line-height: 1.3; }
.fc-stat { color: var(--gold); font-size: 0.78rem; font-weight: 700; }

.btn {
  font: inherit; font-weight: 800; color: var(--ink); cursor: pointer;
  background: linear-gradient(180deg, #8a4a22, #6e3a1a); border: 1px solid #b06030;
  padding: 10px 20px; border-radius: 12px; min-height: 40px;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }
.btn.big { font-size: 1.06rem; padding: 13px 30px; border-radius: 14px; }
.btn.small { padding: 7px 13px; min-height: 36px; border-radius: 10px; font-size: 0.9rem; }
.btn.ghost { background: #ffffff14; border-color: #ffffff2e; }
.title-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  flex-wrap: wrap;
}
.tb-left, .tb-right { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.chip {
  background: var(--card); border: 1px solid var(--edge); border-radius: 999px;
  padding: 7px 13px; font-size: 0.88rem; font-weight: 700; white-space: nowrap;
}
.chip.dim, .dim { color: var(--dim); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 999px; font-size: 1.1rem;
  background: var(--card); border: 1px solid var(--edge); color: var(--ink); cursor: pointer;
}
.icon-btn.off { opacity: 0.4; }

#panel {
  position: fixed; left: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 21;
  width: min(340px, calc(100vw - 24px));
  background: var(--card); border: 1px solid var(--edge); border-radius: 16px;
  padding: 13px 15px; display: flex; flex-direction: column; gap: 7px;
  backdrop-filter: blur(6px);
}
.p-head { display: flex; justify-content: space-between; align-items: center; font-family: 'Cinzel', serif; font-weight: 800; font-size: 1.05rem; }
#panel-sub { font-size: 0.82rem; }
#panel-comp { font-size: 0.82rem; line-height: 1.35; }
#panel-recruit { font-size: 0.88rem; line-height: 1.35; }
#panel-mp { font-size: 0.82rem; }
.bar { height: 10px; border-radius: 6px; background: #ffffff18; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; }
.bar-label { font-size: 0.8rem; color: var(--dim); }

#order-row { display: inline-flex; gap: 4px; align-items: center; margin-left: 4px; }
.ord-chip {
  width: 26px; height: 26px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.62rem; font-weight: 800; color: #10141f; opacity: 0.45; border: 2px solid transparent;
}
.ord-chip.now { opacity: 1; border-color: #f4ead2; transform: scale(1.12); }
.ord-chip.done { opacity: 0.25; }
.ord-chip.you { box-shadow: 0 0 0 2px var(--gold); }

#atk-confirm {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(14px, env(safe-area-inset-bottom)); z-index: 25;
  background: var(--card); border: 1px solid #e5573f66; border-radius: 14px;
  padding: 10px 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  max-width: calc(100vw - 24px); font-size: 0.9rem;
}
.atk-actions { display: flex; gap: 8px; }
.btn.gold { background: linear-gradient(180deg, #a8842a, #8a6a1a); border-color: #d9a441; }

#prebattle {
  position: fixed; right: 12px; top: 64px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 26;
  display: flex; align-items: flex-start; pointer-events: none;
}
.pb-card {
  background: var(--card); border: 1px solid var(--edge); border-radius: 18px;
  width: min(330px, calc(100vw - 24px)); padding: 16px; pointer-events: auto;
  display: flex; flex-direction: column; gap: 10px; max-height: 100%; overflow-y: auto;
}
.pb-card h3 { font-family: 'Cinzel', serif; letter-spacing: 0.03em; }
#pb-goals { display: flex; flex-direction: column; gap: 6px; }
.pb-goal {
  font: inherit; text-align: left; color: var(--ink); cursor: pointer;
  background: #ffffff10; border: 1px solid var(--edge); border-radius: 10px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.pb-goal span { font-size: 0.78rem; color: var(--dim); }
.pb-goal.on { border-color: var(--gold); background: #d9a44122; }
.pb-sliders { display: flex; flex-direction: column; gap: 8px; }
.pb-sliders label { font-size: 0.84rem; color: var(--dim); display: flex; flex-direction: column; gap: 2px; }
.pb-sliders input { width: 100%; accent-color: var(--ember); }
.pb-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.84rem; }
.pb-row .btn.on { border-color: var(--gold); color: var(--gold); }

.bt-side { min-width: 86px; text-align: center; }
.spd {
  width: 44px; height: 38px; border-radius: 10px; font: inherit; font-weight: 800;
  background: var(--card); border: 1px solid var(--edge); color: var(--dim); cursor: pointer;
}
.spd.on { color: var(--ink); border-color: var(--gold); }
.bt-hint {
  position: fixed; bottom: max(10px, env(safe-area-inset-bottom)); left: 0; right: 0;
  text-align: center; font-size: 0.78rem; z-index: 20; pointer-events: none;
}

.report-card {
  background: var(--card); border: 1px solid var(--edge); border-radius: 20px;
  max-width: 460px; width: calc(100vw - 36px); padding: 24px; text-align: center;
}
.report-card h2 { font-family: 'Cinzel', serif; font-size: 1.7rem; margin-bottom: 14px; letter-spacing: 0.04em; }
#report-body { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; text-align: left; }
.rr { display: flex; justify-content: space-between; gap: 12px; font-size: 0.93rem; line-height: 1.35; }
.rr.dim { font-size: 0.84rem; }

#toast {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--card); border: 1px solid var(--edge); border-radius: 999px;
  padding: 9px 18px; font-size: 0.9rem; font-weight: 700; white-space: nowrap;
  max-width: calc(100vw - 30px); overflow: hidden; text-overflow: ellipsis;
}
#ver {
  position: fixed; right: 8px; bottom: max(6px, env(safe-area-inset-bottom)); z-index: 15;
  font-size: 0.68rem; color: #ffffff42; pointer-events: none;
}

@media (max-width: 520px) {
  .topbar { padding: 8px; }
  .chip { padding: 6px 10px; font-size: 0.8rem; }
  #fac-grid { grid-template-columns: 1fr 1fr; }
  .fc-blurb { display: none; }
}
