* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px 80px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 2px;
}
header h1 { font-size: 18px; margin: 0; font-weight: 700; }
.badge {
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-top: 12px;
}
.card h2 { font-size: 14px; margin: 0 0 10px; color: var(--muted); font-weight: 600; }

.buddy { display: flex; gap: 12px; align-items: flex-start; }
.buddy-face {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--primary-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; flex-shrink: 0;
}
.buddy-bubble {
  background: var(--primary-soft);
  border-radius: 4px 14px 14px 14px;
  padding: 10px 14px;
  font-size: 14px;
  min-height: 44px;
}

.amount { font-size: 30px; font-weight: 700; margin: 2px 0; letter-spacing: 0.5px; }
.delta { font-size: 13px; color: var(--muted); }
.delta.up { color: var(--primary); }
.delta.down { color: var(--danger); }

.level-row {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted); margin: 14px 0 4px;
}
.bar {
  height: 8px; border-radius: 4px; background: var(--line);
  overflow: hidden; flex: 1;
}
.bar-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.6s ease; }

.btn {
  display: inline-block;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  margin-top: 12px;
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.stat-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.stat-name { font-size: 13px; width: 70px; flex-shrink: 0; white-space: nowrap; color: var(--muted); }
.stat-lv { font-size: 12px; width: 40px; text-align: right; font-weight: 600; }

.quest {
  display: flex; flex-direction: column; gap: 2px;
  width: 100%;
  text-align: left;
  background: none; border: none;
  border-top: 1px solid var(--line);
  padding: 12px 2px;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}
.quest:first-child { border-top: none; }
.q-name { font-size: 14px; font-weight: 600; }
.q-meta { font-size: 12px; color: var(--muted); }
.quest.done .q-name { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.empty { color: var(--muted); font-size: 14px; }

.boss {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%;
  border: none; font-family: inherit;
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 8px;
  font-size: 14px;
}
.boss.ready { background: var(--danger-soft); color: var(--danger); cursor: pointer; font-weight: 600; }
.boss.locked { background: var(--bg); color: var(--muted); }
.boss.defeated { background: var(--primary-soft); color: var(--primary); }
.b-state { font-size: 12px; }

dialog {
  border: none;
  border-radius: var(--radius);
  padding: 20px;
  max-width: 340px;
  width: calc(100vw - 48px);
  background: var(--card);
  color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h3 { margin: 0 0 8px; font-size: 16px; }
dialog p { font-size: 14px; margin: 6px 0; }
dialog .note { color: var(--muted); font-size: 12px; }
dialog input {
  width: 100%;
  font-size: 16px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  margin: 4px 0 10px;
}
dialog label { font-size: 12px; color: var(--muted); }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; }

footer {
  margin-top: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}
footer .links { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
footer .links .btn {
  margin-top: 0;
  padding: 8px 12px;
  font-size: 12px;
  white-space: nowrap;
}

#toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translate(-50%, 80px);
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  max-width: 90vw;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

.sprite { display: block; image-rendering: pixelated; }

.buddy-face { cursor: pointer; }
.buddy-face.hop { animation: hop 0.4s steps(2); }
@keyframes hop { 50% { transform: translateY(-6px); } }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.card-head h2 { margin: 0; }
.info-btn {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  background: none;
  color: var(--muted);
  font-size: 9px;
  font-style: italic;
  font-family: Georgia, serif;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}

.amount-row { display: flex; align-items: center; gap: 10px; }
.amount-row .amount { flex: 1; min-width: 0; }
.btn.mini {
  margin: 0;
  padding: 6px 14px;
  font-size: 12px;
  flex-shrink: 0;
}

.streak {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
.streak .info-btn { margin-left: auto; }

.party-stage {
  position: relative;
  display: flex;
  align-items: flex-end;
  min-height: 86px;
  padding-top: 30px;
}
.hen-slot {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.hen-slot.hop { animation: hop 0.4s steps(2); }
.party-bubble {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: var(--primary-soft);
  border-radius: 4px 14px 14px 14px;
  padding: 8px 12px;
  font-size: 13px;
  z-index: 2;
}
.party-line {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-left: auto;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}
.party-line:active { transform: scale(0.97); }
.pm { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pm-name { font-size: 10px; color: var(--muted); }

.dq-dlg {
  border: 2px solid #22262a;
  margin-left: 16px;
  margin-right: auto;
}
.dq-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.dq-head h3 { margin: 0; font-size: 15px; }
.dq-list { border: 2px solid var(--ink); border-radius: 8px; padding: 6px 4px; }
.dq-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 15px;
  color: inherit;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
}
.dq-cursor { color: var(--primary); font-size: 11px; }
.dq-item.locked { color: var(--muted); }
.dq-item.locked .dq-cursor { visibility: hidden; }
.dq-note { font-size: 10px; margin-left: auto; color: var(--muted); }
.dq-item:not(.locked):hover { background: var(--primary-soft); border-radius: 6px; }

.panel-dlg {
  max-width: 360px;
  max-height: 82vh;
  overflow-y: auto;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 8px;
  margin-bottom: 10px;
}
.panel-head h3 { margin: 0; font-size: 16px; }

.stat-bonus { color: var(--gold); font-size: 10px; margin-left: 2px; }

.skill-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.sk-name { width: 68px; flex-shrink: 0; font-weight: 600; }
.sk-lv { color: var(--gold); font-weight: 700; flex-shrink: 0; }
.sk-src { color: var(--muted); font-size: 11px; flex: 1; min-width: 0; text-align: right; }

.todo-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  border-top: 1px solid var(--line);
  padding: 12px 2px;
  font-family: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.todo-row:first-child { border-top: none; }
.t-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; }
.t-tag { flex-shrink: 0; font-size: 11px; color: var(--muted); }
.t-tag.hot { color: var(--danger); font-weight: 700; }

.achv-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.achv-date { color: var(--muted); font-size: 11px; flex-shrink: 0; }
.achv-memo { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.achv-amt { color: var(--danger); font-weight: 700; flex-shrink: 0; }
.achv-del {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
}
.achv-form { display: flex; gap: 6px; margin-top: 10px; align-items: center; }
.achv-form input { margin: 0; }
.achv-form #achv-amount { width: 110px; flex-shrink: 0; }
.achv-form .btn { margin: 0; flex-shrink: 0; }

.ob-row { display: flex; gap: 6px; }
.ob-row select {
  font-size: 14px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  margin: 4px 0 10px;
}
#ob-add { margin: 0 0 10px; padding: 6px 14px; font-size: 12px; }

.boss { gap: 10px; }
.boss .b-name { flex: 1; text-align: left; }

.scene-dlg { max-width: 380px; }
.stage {
  position: relative;
  height: 140px;
  border: 2px solid #22262a;
  border-radius: 10px;
  background: linear-gradient(#a8d8ea 0 70%, #7cb35e 70% 100%);
  overflow: hidden;
}
.stage-slot { position: absolute; bottom: 22px; }
.stage-slot.left { left: 12%; }
.stage-slot.right { right: 12%; }

.msgbox {
  position: relative;
  border: 2px solid #22262a;
  border-radius: 8px;
  background: var(--card);
  padding: 10px 26px 10px 12px;
  margin-top: 8px;
  min-height: 68px;
}
.msg-name { margin: 0; font-size: 11px; font-weight: 700; color: var(--primary); }
.msg-text { margin: 2px 0 0; font-size: 14px; }
.msg-next {
  position: absolute;
  right: 6px;
  bottom: 4px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  animation: blinkv 1s steps(2) infinite;
}
@keyframes blinkv { 50% { opacity: 0; } }

.scene-reward { font-size: 12px; color: var(--gold); font-weight: 600; margin: 10px 0 2px; }
.step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 14px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.step input { width: 18px; height: 18px; flex-shrink: 0; margin-top: 2px; accent-color: var(--primary); }

.streak {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
.note-sm { font-size: 13px; color: var(--muted); margin: 0; }

.stage-slot.center { left: 50%; transform: translateX(-50%); }
.poof { animation: poof 0.45s steps(3) forwards; }
@keyframes poof {
  to { transform: scale(1.8); opacity: 0; }
}

.col-h { font-size: 12px; color: var(--muted); margin: 12px 0 6px; font-weight: 600; }
.col-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.col-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 4px;
  font-family: inherit;
  color: inherit;
  position: relative;
}
.col-slot.ownable { cursor: pointer; }
.col-slot.unknown { opacity: 0.55; }
.col-face { min-height: 34px; display: flex; align-items: center; font-size: 20px; color: var(--muted); }
.col-name { font-size: 11px; text-align: center; line-height: 1.3; }
.col-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
}

.battle-dlg {
  max-width: 380px;
  width: calc(100vw - 32px);
  border: 2px solid var(--ink);
}
.bt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.bt-head h3 { margin: 0; font-size: 16px; }
.bt-gauge { font-size: 12px; color: var(--danger); letter-spacing: 1px; flex-shrink: 0; }
.bt-stage {
  height: 156px;
  background: linear-gradient(#2b2f45 0 72%, #4a3a52 72% 100%);
}
.bt-enemy-slot { left: 50%; transform: translateX(-50%); bottom: 26px; }
.bt-hero-slot { right: 8px; bottom: 14px; }
#bt-stage-wrap { cursor: pointer; }
.shake { animation: shake 0.4s steps(2) 2; }
@keyframes shake { 50% { transform: translateX(-50%) translateY(-4px); } }
.msg-name.is-boss { color: var(--danger); }

#opening {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 20px;
  transition: opacity 1.2s ease;
}
#opening[hidden] { display: none; }
#opening.fadeout { opacity: 0; }
body.op-lock { overflow: hidden; }
.op-stage { height: 150px; display: flex; align-items: flex-end; }
#op-hen { display: block; transform-origin: bottom center; }
#op-hen.approach { animation: approach 2.2s steps(7) both; }
@keyframes approach {
  from { transform: scale(0.1); opacity: 0.3; }
  to { transform: scale(1); opacity: 1; }
}
.op-msg {
  width: min(88vw, 340px);
  min-height: 92px;
  border: 2px solid #fff;
  border-radius: 6px;
  background: #000;
  color: #fff;
  padding: 12px 16px 18px;
  font-size: 15px;
  line-height: 1.9;
  position: relative;
}
.op-msg p { margin: 0; }
.op-cursor {
  position: absolute;
  right: 10px;
  bottom: 5px;
  font-size: 13px;
  color: #fff;
  animation: blinkv 1s steps(2) infinite;
}
.op-input {
  width: min(88vw, 340px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 108px;
}
.op-field-row { display: flex; gap: 8px; align-items: stretch; }
.op-field-row .tl-field { flex: 0 1 62%; }
.op-btn.op-decide { flex: 0 0 26%; text-align: center; padding: 10px 4px; }
.op-input input {
  background: #000;
  color: #fff;
  border: 2px solid #fff;
  border-radius: 6px;
  font-size: 16px;
  padding: 10px 12px;
  font-family: inherit;
  min-width: 0;
}
.op-input input::placeholder { color: #4a4a4a; }

.op-start {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #000;
  color: #fff;
  border: 2px solid #fff;
  border-radius: 6px;
  padding: 14px 44px;
  font-size: 18px;
  letter-spacing: 6px;
  font-family: inherit;
  cursor: pointer;
  opacity: 0;
  transition: opacity 1.6s ease;
}
.op-start.shown { opacity: 1; }
.op-start:active { background: #333; }
#opening.pre-start .op-stage,
#opening.pre-start .op-msg,
#opening.pre-start .op-input { visibility: hidden; }
.op-btn {
  background: #000;
  color: #fff;
  border: 2px solid #fff;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.op-btn:active { background: #333; }

#levelup {
  position: fixed;
  inset: 0;
  background: rgba(15, 25, 22, 0.88);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #fff;
  cursor: pointer;
  overflow: hidden;
}
#levelup[hidden] { display: none; }
.levelup-txt {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 4px;
  color: #f5c542;
  margin: 0;
  animation: hop 0.6s steps(2) infinite;
}
.levelup-lv { font-size: 20px; font-weight: 700; margin: 0; }
.levelup-title { font-size: 14px; color: #9fe1cb; margin: 0; }
.levelup-hint { font-size: 11px; color: rgba(255,255,255,0.5); margin-top: 18px; }
#levelup-confetti { position: absolute; inset: 0; pointer-events: none; }
#levelup-confetti span {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 8px;
  animation: fall 1.6s steps(8) infinite;
}
@keyframes fall {
  to { transform: translateY(105vh); }
}
