:root {
  --bg: #0B1120;
  --paper: #131B2E;
  --ink: #E5EAF4;
  --ink-soft: #94A1BA;
  --accent: #5BBFDF;
  --accent-dark: #3987C9;
  --accent-soft: #1C3A52;
  --kinah: #E2B340;
  --danger: #EE7B6E;
  --line: #25314B;
  --grade-common: #94A1BA;
  --grade-rare: #5CA6E0;
  --grade-legend: #B179E8;
  --grade-unique: #E2B340;
  --grade-special: #EE7B6E;
  --radius: 12px;
  --font-display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
}

a { color: var(--accent); }

/* --- Navigation --- */
.topnav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.topnav-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  text-decoration: none;
  color: var(--accent);
  letter-spacing: 0.03em;
}
.topnav-links { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; }
.topnav-links a { text-decoration: none; font-weight: 600; color: var(--ink); }
.topnav-links a:hover { color: var(--accent); }
.topnav-logout { display: flex; align-items: center; gap: 0.75rem; margin: 0; }
.topnav-username { font-weight: 600; color: var(--ink-soft); }
.topnav-logout button {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 700;
}
.topnav-logout button:hover { background: var(--accent-dark); color: #fff; }

/* --- Login --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--paper);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card h1 { font-family: var(--font-display); font-size: 1.5rem; margin-top: 0; color: var(--accent); }
.login-card form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.5rem; text-align: left; }
.login-card label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 600; }
.login-card input { padding: 0.65rem 0.75rem; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-size: 1rem; font-family: var(--font-body); }
.login-card button { margin-top: 0.5rem; }

/* --- Buttons --- */
.btn[hidden], .btn-icon[hidden] { display: none; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1.4rem;
  border-radius: 999px;
  font-weight: 700;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  font-family: var(--font-body);
}
.btn-primary { background: var(--accent); color: #0B1120; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-secondary { background: var(--paper); color: var(--accent); border: 1px solid var(--line); }
.btn-secondary:hover { background: var(--accent-soft); }
.btn-small { padding: 0.45rem 0.9rem; font-size: 0.9rem; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: none;
  background: var(--paper);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--accent);
}
.btn-icon:hover { background: var(--accent-soft); }
.btn-icon-danger { color: var(--danger); }

.flash-error { background: #3a1f1c; color: var(--danger); padding: 0.75rem 1rem; border-radius: 10px; font-weight: 600; }
.empty-hint { color: var(--ink-soft); font-size: 1.05rem; }
.small { font-size: 0.85rem; color: var(--ink-soft); }

/* --- Admin screens --- */
.admin-wrap { max-width: min(1200px, 90vw); margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.admin-wrap-narrow { max-width: 420px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.admin-wrap h1 { font-family: var(--font-display); color: var(--accent); display: flex; align-items: center; gap: 0.6rem; }
.admin-wrap h2 { font-family: var(--font-display); color: var(--accent); font-size: 1.4rem; margin: 0 0 0.5rem; }
.editor-toolbar { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.editor-toolbar form { margin: 0; }

.user-rows { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 1rem;
}
.page-row-actions { display: flex; gap: 0.5rem; }
.page-row-actions form { margin: 0; }
.page-row-text { color: var(--ink-soft); margin: 0.25rem 0 0; }

.role-badge {
  display: inline-block;
  margin-left: 0.75rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
}

.big-form { display: flex; flex-direction: column; gap: 1.25rem; margin-top: 1.5rem; }
.field { display: flex; flex-direction: column; gap: 0.5rem; font-weight: 600; }
.field input, .field select {
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 1rem;
  font-family: var(--font-body);
}
.checkbox-line { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; }
.form-actions { display: flex; gap: 1rem; justify-content: flex-end; }

.inline-form { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin: 1rem 0; }
.inline-form input[type="text"] {
  flex: 1 1 240px;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
}
.inline-form select { padding: 0.65rem 0.85rem; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); }

/* --- Search results --- */
.search-results { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1rem; }
.search-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 1rem;
}
.search-result form { display: flex; align-items: center; gap: 0.75rem; margin: 0; flex-wrap: wrap; }

/* --- Character cards --- */
.char-grid { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.char-card {
  position: relative;
  display: block;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.15s;
}
.char-card:hover { border-color: var(--accent); }
.char-card h3 { font-family: var(--font-display); margin: 0.3rem 0 0.2rem; font-size: 1.5rem; color: var(--ink); }
.char-card-meta { color: var(--ink-soft); margin: 0; font-size: 0.9rem; }
.char-card-cp { font-family: var(--font-mono); color: var(--accent); font-size: 1.3rem; margin: 0.5rem 0 0; }
.char-card-cp span { font-family: var(--font-body); font-size: 0.75rem; color: var(--ink-soft); }
.char-card-at { color: var(--ink-soft); font-size: 0.8rem; margin: 0.4rem 0 0; }
.mine-badge {
  display: inline-block;
  background: var(--kinah);
  color: #2a1f05;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-bottom: 0.3rem;
}

/* --- Character detail --- */
.char-header { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.char-portrait {
  width: 88px; height: 88px; object-fit: cover; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--bg); flex-shrink: 0;
}
.char-header-info { display: flex; flex-direction: column; gap: 0.2rem; }
.char-title-pill { margin: 0; font-weight: 700; font-style: italic; }

.grade-common { color: var(--grade-common); }
.grade-rare { color: var(--grade-rare); }
.grade-legend { color: var(--grade-legend); }
.grade-unique { color: var(--grade-unique); }
.grade-special { color: var(--grade-special); }

.eq-item { display: inline-flex; align-items: center; gap: 0.5rem; white-space: normal; }
.eq-icon { width: 30px; height: 30px; object-fit: contain; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; flex-shrink: 0; }

.petwing-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 0.85rem; }
.petwing-item {
  display: flex; align-items: center; gap: 0.75rem; background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.6rem 1rem;
}
.petwing-icon { width: 42px; height: 42px; object-fit: contain; background: var(--bg); border-radius: 8px; flex-shrink: 0; }
.petwing-name { margin: 0; font-weight: 600; }
.petwing-meta { margin: 0.1rem 0 0; font-size: 0.85rem; color: var(--ink-soft); }

.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin: 1rem 0 2rem; }
.stat-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; }
.stat-card h3 { font-family: var(--font-display); font-size: 0.95rem; color: var(--ink-soft); margin: 0; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.stat-card-v { font-family: var(--font-mono); font-size: 1.8rem; color: var(--accent); margin: 0.3rem 0 0; }
.stat-card-d { font-family: var(--font-mono); font-size: 0.85rem; color: var(--ink-soft); margin: 0.2rem 0 0; }

section { margin-bottom: 2rem; }

.chart-svg { width: 100%; max-width: 640px; height: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; }

.bar-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 70px; align-items: center; gap: 0.75rem; }
.bar-label { font-size: 0.9rem; color: var(--ink-soft); }
.bar-row.priority .bar-label { color: var(--accent); font-weight: 700; }
.bar-track { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--ink-soft); border-radius: 999px; }
.bar-row.priority .bar-fill { background: var(--accent); }
.bar-value { font-family: var(--font-mono); font-size: 0.9rem; text-align: right; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table th { font-family: var(--font-display); color: var(--ink-soft); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.8rem; }

.skill-list { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.3rem 1rem; }
.skill-list li { display: flex; justify-content: space-between; gap: 0.5rem; border-bottom: 1px solid var(--line); padding: 0.3rem 0; font-size: 0.9rem; }
.skill-list em { color: var(--ink-soft); font-style: normal; font-size: 0.8rem; }
.skill-list span { font-family: var(--font-mono); color: var(--ink-soft); }

details { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; }
details summary { cursor: pointer; font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; color: var(--accent); }
details[open] summary { margin-bottom: 0.75rem; }

/* --- Craft --- */
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: var(--bg); }

.craft-section { margin-bottom: 2.5rem; }
.field-inline { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 500; }
.field-inline input, .field-inline select { padding: 0.5rem 0.65rem; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); width: 7rem; }

.craft-steps { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.craft-step { display: flex; gap: 0.85rem; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; }
.craft-step.is-done { opacity: 0.55; }
.craft-step-toggle { margin: 0; }
.checkbox-btn {
  width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--accent); font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.craft-step-body h3 { font-family: var(--font-display); color: var(--accent); margin: 0 0 0.4rem; font-size: 1.1rem; }
.craft-step-body ul { margin: 0 0 0.5rem; padding-left: 1.2rem; }
.craft-step-body li { margin-bottom: 0.2rem; }

.craft-table th, .craft-table td { white-space: normal; }
.craft-row-form { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; margin: 0; }
.craft-row-form input, .craft-row-form select {
  padding: 0.4rem 0.5rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: 0.85rem; width: 6.5rem;
}
.craft-row-form input[type="text"] { width: 9rem; }

.verdict { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }
.verdict-pos { background: #163a2a; color: #6fd99a; }
.verdict-warn { background: #3a3318; color: var(--kinah); }
.verdict-neg { background: #3a1f1c; color: var(--danger); }

.craft-ranking { padding-left: 1.4rem; }
.craft-ranking li { margin-bottom: 0.3rem; }
.craft-ranking span { color: var(--ink-soft); margin-left: 0.5rem; font-family: var(--font-mono); font-size: 0.9rem; }

.craft-chain { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; margin-bottom: 1.5rem; }
.craft-chain > h3 { font-family: var(--font-display); color: var(--accent); margin-top: 0; }
.craft-chain tr.is-best { background: var(--accent-soft); }
