:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --soft: #eff6ff;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
  --radius: 18px;
  --header-height: 4.1rem;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 1rem);
}

body {
  margin: 0;
  padding-top: var(--header-height);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

code {
  background: #eef2ff;
  padding: 0.08rem 0.35rem;
  border-radius: 0.4rem;
  color: #3730a3;
}

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  min-height: var(--header-height);
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 800;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 0.75rem;
  background: var(--primary);
  color: white;
  font-size: 0.9rem;
}

.site-nav {
  display: flex;
  gap: 0.35rem;
}

.site-nav a {
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 650;
}

.site-nav a:hover {
  background: var(--soft);
  color: var(--primary-dark);
}

.page {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.hero,
.page-title {
  background: linear-gradient(135deg, #ffffff 0%, #eff6ff 100%);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: clamp(1.5rem, 4vw, 3.2rem);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--primary);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

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

h1 {
  margin-bottom: 0.75rem;
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: 1.1;
}

.hero-text,
.page-title p {
  color: var(--muted);
  max-width: 760px;
}

.hero-actions {
  margin-top: 1.5rem;
}

.primary-btn,
button {
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1.1rem;
  background: var(--primary);
  color: white;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.primary-btn:hover,
button:hover {
  background: var(--primary-dark);
}

.tool-grid {
  margin-top: 1.2rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.tool-card {
  display: flex;
  gap: 1rem;
  padding: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.tool-card.disabled {
  opacity: 0.62;
}

.tool-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 1rem;
  background: var(--soft);
  color: var(--primary-dark);
  font-weight: 900;
}

.tool-card h2 {
  margin-bottom: 0.2rem;
  font-size: 1.15rem;
}

.tool-card p {
  margin-bottom: 0;
  color: var(--muted);
}

.controls {
  margin-top: 1.2rem;
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(4, minmax(130px, 1fr)) auto;
  gap: 0.75rem;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  padding: 0.6rem 0.75rem;
  background: white;
  color: var(--text);
  font: inherit;
}

.summary-bar {
  margin: 1rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.summary-bar strong {
  font-size: 1.5rem;
}

.summary-bar span {
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  gap: 1rem;
  align-items: start;
}

.modal-list-layout {
  grid-template-columns: minmax(0, 1fr);
}

.ability-list {
  display: grid;
  gap: 0.8rem;
}

.ability-card {
  width: 100%;
  display: grid;
  grid-template-columns: 66px 1fr;
  gap: 0.9rem;
  text-align: left;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.ability-card:hover,
.ability-card.active {
  background: #f8fbff;
  border-color: #bfdbfe;
}

.ability-icon-wrap {
  width: 58px;
  height: 58px;
  border-radius: 1rem;
  background: #f3f4f6;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.ability-icon-wrap.large {
  width: 76px;
  height: 76px;
  border-radius: 1.2rem;
}

.ability-icon {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.no-icon,
.missing-icon::after {
  content: "無圖";
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.ability-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.ability-title-row h2 {
  margin-bottom: 0.1rem;
  font-size: 1.05rem;
  line-height: 1.3;
}

.tag {
  display: inline-flex;
  white-space: nowrap;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--muted);
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 850;
}

.tag-wake {
  background: #fef3c7;
  color: #92400e;
}

.tag-enemy {
  background: #fee2e2;
  color: #991b1b;
}

.tag-maze {
  background: #f3e8ff;
  color: #6b21a8;
}

.tag-team {
  background: #cffafe;
  color: #0e7490;
}

.code {
  margin-bottom: 0.25rem;
  color: var(--primary-dark);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  word-break: break-all;
}

.desc {
  margin-bottom: 0.55rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-line;
}

.mini-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.mini-meta span {
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  padding: 0.2rem 0.5rem;
  font-size: 0.76rem;
  font-weight: 750;
}

.detail-panel {
  position: sticky;
  top: calc(var(--header-height) + 1rem);
  max-height: calc(100vh - var(--header-height) - 2rem);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.detail-head {
  display: flex;
  gap: 1rem;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
}

.detail-head h2 {
  margin-bottom: 0.35rem;
  line-height: 1.25;
}

.detail-section {
  padding-top: 1rem;
}

.detail-section h3 {
  margin-bottom: 0.65rem;
  font-size: 1rem;
}

.preline {
  white-space: pre-line;
}

.effect-card {
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 0.9rem;
  margin-bottom: 0.7rem;
  background: #fbfdff;
}

.effect-card h4 {
  margin-bottom: 0.55rem;
  color: var(--primary-dark);
}

dl {
  margin: 0;
  display: grid;
  gap: 0.45rem;
}

dl div {
  display: grid;
  grid-template-columns: 5.2rem 1fr;
  gap: 0.5rem;
}

dt {
  color: var(--muted);
  font-weight: 800;
}

dd {
  margin: 0;
}

.raw-json {
  max-height: 420px;
  overflow: auto;
  border-radius: 1rem;
  background: #0f172a;
  color: #e5e7eb;
  padding: 1rem;
  font-size: 0.82rem;
  line-height: 1.55;
}

.empty-state {
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.empty-state.small {
  text-align: left;
}

.modal-backdrop {
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(8px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  position: relative;
  width: min(760px, 100%);
  max-height: calc(100vh - var(--header-height) - 2rem);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 1.25rem;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  width: 2.35rem;
  height: 2.35rem;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
}

.modal-close:hover {
  background: #e5e7eb;
}

@media (hover: none) and (pointer: coarse) {
  .site-nav a:hover,
  .primary-btn:hover,
  button:hover,
  .ability-card:hover,
  .modal-close:hover {
    background: inherit;
    color: inherit;
    border-color: inherit;
  }
}

@media (max-width: 960px) {
  .controls,
  .layout {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 620px) {
  :root {
    --header-height: 4.1rem;
  }

  .header-inner {
    align-items: center;
    flex-direction: row;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
  }

  .site-nav {
    width: auto;
    overflow-x: visible;
  }

  .summary-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .ability-card {
    grid-template-columns: 52px 1fr;
  }

  .ability-icon-wrap {
    width: 48px;
    height: 48px;
  }

  .modal-backdrop {
    align-items: end;
    padding: 0.6rem;
  }

  .modal-panel {
    width: 100%;
    max-height: calc(100vh - var(--header-height) - 1.2rem);
    border-radius: 22px 22px 16px 16px;
    padding: 1rem;
  }

  .modal-panel .detail-head {
    align-items: flex-start;
    padding-right: 3rem;
  }

  dl div {
    grid-template-columns: 4.2rem 1fr;
  }
}
