:root {
  color: #1f2937;
  background: #f6f8fb;
  font-family: Inter, "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
}

button {
  min-height: 44px;
  border: 1px solid #d7deea;
  border-radius: 8px;
  color: inherit;
  background: #ffffff;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #2563eb;
  font-size: 0.78rem;
  font-weight: 800;
}

h1,
h2,
h3,
p,
dl {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 6vw, 2.6rem);
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.14rem;
}

h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.panel {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid #dce3ef;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(29, 42, 64, 0.06);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title span,
.muted,
small,
em {
  color: #667085;
}

.disciple-tabs,
.selection-grid,
.floor-list,
.debug-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.disciple-tabs button,
.choice-card,
.floor-card {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.disciple-tabs button.active {
  border-color: #2563eb;
  background: #eff6ff;
}

.choice-card {
  align-content: start;
}

.choice-card.selected {
  border-color: #2563eb;
  background: #eff6ff;
}

.choice-card p,
.choice-card small {
  margin: 0;
  line-height: 1.5;
}

.weapon-label {
  color: #2563eb;
  font-size: 0.86rem;
  font-weight: 800;
}

.combo-confirm {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(280px, 1.1fr);
  gap: 14px;
  align-items: start;
}

.wide {
  width: 100%;
  margin-top: 12px;
}

.disciple-tabs span {
  color: #667085;
  font-size: 0.86rem;
}

.disciple-info {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.stat-grid,
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
  margin-bottom: 0;
}

.stat-grid div,
.summary-grid div,
.floor-result dl div {
  min-width: 0;
  padding: 9px;
  border-radius: 8px;
  background: #f5f7fb;
}

dt {
  color: #667085;
  font-size: 0.74rem;
  font-weight: 800;
}

dd {
  margin: 2px 0 0;
  font-size: 1.02rem;
  font-weight: 800;
}

.owned-skills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #edf1f7;
}

.progress-grid {
  margin-top: 12px;
}

.owned-skills span {
  color: #667085;
  font-size: 0.86rem;
  font-weight: 800;
}

.tower-copy {
  max-width: 42rem;
  color: #475467;
  line-height: 1.6;
}

.floor-card {
  border: 1px solid #dce3ef;
  border-radius: 8px;
  background: #f8fafc;
}

.floor-card p {
  margin-bottom: 0;
  color: #475467;
}

.replay-stage {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(180px, 0.8fr) minmax(190px, 1fr);
  gap: 12px;
  align-items: stretch;
}

.combat-card {
  min-height: 230px;
  padding: 14px;
  border: 1px solid #d8e0ed;
  border-radius: 8px;
  background: #f8fafc;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.replay-stage.disciple .combat-card.apprentice,
.replay-stage.enemy .combat-card.enemy {
  transform: translateY(-2px);
  border-color: #60a5fa;
  background: #eff6ff;
}

.combat-card.charging {
  border-color: #f97316;
  background: #fff7ed;
}

.card-label {
  display: inline-flex;
  margin-bottom: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  color: #2563eb;
  background: #dbeafe;
  font-size: 0.74rem;
  font-weight: 800;
}

.bar {
  position: relative;
  display: grid;
  grid-template-columns: auto auto;
  gap: 6px;
  align-items: center;
  min-height: 30px;
  margin-bottom: 8px;
  padding: 5px 8px;
  overflow: hidden;
  border-radius: 8px;
  background: #e5e7eb;
}

.bar span,
.bar strong {
  position: relative;
  z-index: 1;
  font-size: 0.8rem;
}

.bar strong {
  justify-self: end;
}

.bar i {
  position: absolute;
  inset: 0 auto 0 0;
  display: block;
  transition: width 220ms ease;
}

.bar.hp i {
  background: #bfdbfe;
}

.bar.mp i {
  background: #c7d2fe;
}

.icons,
.enemy-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.icons span,
.enemy-stack span,
.enemy-stack i {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475467;
  font-size: 0.76rem;
  font-style: normal;
  font-weight: 700;
}

.enemy-stack .down {
  opacity: 0.54;
  text-decoration: line-through;
}

.replay-center {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 230px;
  padding: 14px;
  border-radius: 8px;
  background: #f1f5f9;
  text-align: center;
}

.replay-center strong {
  color: #1d4ed8;
  font-size: 1.18rem;
}

.replay-center p {
  margin: 8px 0;
  color: #475467;
  line-height: 1.5;
}

.replay-center em {
  padding: 4px 10px;
  border-radius: 999px;
  color: #075985;
  background: #e0f2fe;
  font-style: normal;
  font-weight: 800;
}

.float {
  display: inline-flex;
  min-width: 56px;
  justify-content: center;
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 1.2rem;
  animation: pop 420ms ease both;
}

.float.damage {
  color: #991b1b;
  background: #fee2e2;
}

.float.heal {
  color: #047857;
  background: #d1fae5;
}

@keyframes pop {
  from {
    transform: translateY(6px) scale(0.96);
    opacity: 0.5;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.replay-controls,
.debug-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.primary,
.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  text-align: center;
  font-weight: 800;
}

.primary {
  border-color: #2563eb;
  color: #ffffff;
  background: #2563eb;
}

.ghost {
  background: #f8fafc;
}

.danger {
  border-color: #fecaca;
  color: #b91c1c;
  background: #fff7f7;
}

.skill-branches {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.skill-branches.single-tree {
  grid-template-columns: 1fr;
}

.skill-branches.single-tree .branch {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.branch {
  display: grid;
  gap: 8px;
  align-content: start;
}

.skill-card {
  position: relative;
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 148px;
  padding: 12px;
}

.skill-card p {
  margin-bottom: 0;
  color: #475467;
  font-size: 0.9rem;
  line-height: 1.45;
}

.skill-card.learnable {
  border-color: #60a5fa;
  background: #f8fbff;
}

.skill-card.learned {
  border-color: #2563eb;
  background: #eff6ff;
}

.badge {
  justify-self: start;
  padding: 3px 8px;
  border-radius: 999px;
  color: #1d4ed8;
  background: #dbeafe;
  font-size: 0.72rem;
  font-weight: 800;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.95fr);
  gap: 14px;
}

.floor-results {
  display: grid;
  gap: 10px;
}

.floor-result {
  padding: 12px;
  border: 1px solid #dce3ef;
  border-radius: 8px;
  background: #f8fafc;
}

.floor-result.failed {
  border-color: #fecaca;
  background: #fff7f7;
}

.floor-result dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin: 8px 0;
}

.floor-result ul,
.notes {
  margin-bottom: 0;
  padding-left: 20px;
  line-height: 1.55;
}

.result {
  display: inline-flex;
  margin-bottom: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 900;
}

.result.win {
  color: #075985;
  background: #e0f2fe;
}

.result.lose {
  color: #991b1b;
  background: #fee2e2;
}

.reward {
  margin: 12px 0;
  padding: 10px;
  border-radius: 8px;
  background: #f5f7fb;
  font-weight: 800;
}

.note-box {
  padding: 10px;
  border-radius: 8px;
  background: #f5f7fb;
  color: #475467;
  line-height: 1.6;
}

.battle-log {
  max-height: 280px;
  margin: 0;
  padding-left: 20px;
  overflow: auto;
  color: #344054;
  line-height: 1.58;
}

.battle-log li {
  margin-bottom: 5px;
}

.log-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #ffffff;
}

.log-type {
  min-width: 74px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475467;
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.log-actor {
  font-weight: 900;
}

.log-actor.ally {
  color: #1d4ed8;
}

.log-actor.enemy {
  color: #b91c1c;
}

.log-skill {
  padding: 1px 6px;
  border-radius: 6px;
  background: #ede9fe;
  color: #5b21b6;
  font-weight: 900;
}

.log-damage {
  font-weight: 900;
}

.ally-damage {
  color: #1d4ed8;
}

.enemy-damage {
  color: #b91c1c;
}

.log-ally-damage {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.log-enemy-damage {
  border-color: #fecaca;
  background: #fff7f7;
}

.log-big-damage {
  border-color: #93c5fd;
  background: #dbeafe;
  font-size: 1.04rem;
  font-weight: 900;
}

.log-evade,
.log-miss {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
  font-weight: 800;
}

.log-trigger {
  border-color: #fde68a;
  background: #fffbeb;
  box-shadow: inset 3px 0 0 #f59e0b;
  font-weight: 900;
}

.log-status {
  border-color: #c7d2fe;
  background: #eef2ff;
}

.log-status .log-type {
  background: #c7d2fe;
  color: #3730a3;
}

.log-heal {
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: #047857;
  font-weight: 800;
}

.log-mastery,
.log-level-up {
  border-color: #fcd34d;
  background: #fffbeb;
  color: #92400e;
  font-weight: 900;
}

.log-level-up {
  font-size: 1.06rem;
  box-shadow: inset 4px 0 0 #f59e0b;
}

.log-system {
  background: #f8fafc;
}

.debug-output {
  min-height: 96px;
  max-height: 340px;
  margin: 12px 0 0;
  padding: 12px;
  overflow: auto;
  border-radius: 8px;
  background: #111827;
  color: #e5e7eb;
  font-size: 0.82rem;
  white-space: pre-wrap;
}

.export-panel {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #edf1f7;
}

.import-box {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  color: #667085;
  font-size: 0.82rem;
  font-weight: 800;
}

.import-box textarea {
  min-height: 88px;
  width: 100%;
  resize: vertical;
  border: 1px solid #d7deea;
  border-radius: 8px;
  padding: 10px;
  font: inherit;
}

.debug-seed {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.debug-seed label {
  display: grid;
  gap: 5px;
  color: #667085;
  font-size: 0.82rem;
  font-weight: 800;
}

.debug-seed input {
  min-height: 40px;
  width: 100%;
  border: 1px solid #d7deea;
  border-radius: 8px;
  padding: 0 10px;
  font: inherit;
}

.debug-seed .checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.debug-seed .checkbox-line input {
  min-height: auto;
  width: auto;
}

.seed-history {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.seed-chip {
  justify-content: flex-start;
  min-height: 40px;
  font-size: 0.82rem;
}

@media (max-width: 880px) {
  .app {
    padding: 10px;
  }

  .topbar,
  .section-title,
  .disciple-info,
  .combo-confirm,
  .two-column,
  .replay-stage,
  .skill-branches {
    display: grid;
    grid-template-columns: 1fr;
  }

  .replay-controls,
  .debug-actions {
    grid-template-columns: 1fr 1fr;
  }

  .primary,
  .ghost {
    width: 100%;
  }
}
