:root {
  --bg-0: #0f1520;
  --bg-1: #151d2b;
  --panel-bg: rgba(24, 33, 47, 0.93);
  --panel-border: #324661;
  --surface: rgba(11, 16, 25, 0.84);
  --surface-border: #3a516f;
  --surface-border-strong: #92a8c4;
  --surface-selected: rgba(20, 30, 44, 0.92);
  --text-strong: #f2f7ff;
  --text-muted: #b3c1d8;
  --warning: #ffc46d;
  --error: #ffa1ad;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text-strong);
  background: repeating-linear-gradient(
    135deg,
    var(--bg-0) 0,
    var(--bg-0) 16px,
    var(--bg-1) 16px,
    var(--bg-1) 32px
  );
}

.page-shell {
  width: min(1200px, 94vw);
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.hero {
  margin-bottom: 1.2rem;
}

.hero-kicker {
  margin: 0;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.82rem;
}

.hero h1 {
  margin: 0.35rem 0 0.6rem;
  font-size: clamp(1.7rem, 3.4vw, 2.5rem);
}

.hero-subtitle {
  margin: 0;
  color: var(--text-muted);
  max-width: 74ch;
}

.layout {
  display: grid;
  grid-template-columns: minmax(240px, 0.56fr) minmax(500px, 1.24fr) minmax(360px, 1fr);
  gap: 1rem;
  align-items: start;
}

.panel {
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  border-radius: 12px;
  padding: 1rem;
}

.panel h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.field-group {
  margin-bottom: 1rem;
}

.setup-panel,
.result-panel-shell {
  min-width: 0;
}

.books-panel {
  min-width: 0;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field-label {
  margin: 0 0 0.42rem;
  color: var(--text-muted);
  font-weight: 600;
}

.counter {
  margin: 0 0 0.42rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.custom-select {
  position: relative;
}

.custom-select-trigger,
.search-input,
.btn {
  width: 100%;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-strong);
  padding: 0.58rem 0.68rem;
  font-size: 0.95rem;
}

.custom-select-trigger {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  cursor: pointer;
}

.custom-select-trigger:focus-visible,
.search-input:focus-visible,
.btn:focus-visible,
.level-btn:focus-visible,
.custom-option-btn:focus-visible {
  outline: 2px solid var(--surface-border-strong);
  outline-offset: 1px;
}

.custom-select-caret {
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg);
  margin-top: -4px;
}

.custom-select-panel {
  margin-top: 0.35rem;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  background: rgba(11, 16, 25, 0.98);
  padding: 0.45rem;
  position: absolute;
  z-index: 25;
  width: 100%;
}

.search-input {
  margin-bottom: 0.45rem;
}

.custom-option-list {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 260px;
  overflow: auto;
  overscroll-behavior: contain;
}

.custom-option-item + .custom-option-item {
  margin-top: 0.28rem;
}

.custom-option-btn {
  width: 100%;
  border: 1px solid var(--surface-border);
  border-radius: 7px;
  background: transparent;
  color: var(--text-strong);
  padding: 0.5rem 0.58rem;
  cursor: pointer;
  text-align: left;
  font-weight: 500;
}

.custom-option-btn.is-selected {
  border-color: var(--surface-border-strong);
  background: var(--surface-selected);
}

.custom-option-empty {
  color: var(--text-muted);
  padding: 0.4rem 0.2rem 0.2rem;
}

.mode-group {
  display: grid;
  gap: 0.5rem;
}

.mode-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.56rem 0.66rem;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
}

.mode-option input {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--surface-border-strong);
  border-radius: 999px;
  margin: 0;
  position: relative;
  background: transparent;
}

.mode-option input::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text-strong);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
}

.mode-option input:checked::after {
  transform: translate(-50%, -50%) scale(1);
}

.enchant-list {
  max-height: 320px;
  overflow: auto;
  padding-right: 0.3rem;
  overscroll-behavior: contain;
}

.enchant-row {
  padding: 0.62rem;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  margin-bottom: 0.52rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.62rem;
  align-items: start;
}

.enchant-row.is-selected {
  border-color: var(--surface-border-strong);
  background: var(--surface-selected);
}

.enchant-row.is-blocked {
  border-color: #8a7048;
  background: rgba(61, 45, 24, 0.25);
}

.enchant-info {
  display: flex;
  align-items: center;
  min-height: 2rem;
}

.enchant-name {
  font-weight: 600;
}

.level-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: flex-end;
}

.level-btn {
  width: 36px;
  height: 32px;
  border: 1px solid var(--surface-border);
  border-radius: 7px;
  background: transparent;
  color: var(--text-strong);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  padding: 0;
}

.level-btn.is-active {
  border-color: var(--surface-border-strong);
  background: rgba(36, 56, 80, 0.45);
}

.level-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.enchant-conflict {
  margin: 0;
  color: var(--warning);
  font-size: 0.84rem;
  grid-column: 1 / -1;
}

.selected-books {
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  background: var(--surface);
  padding: 0.5rem;
  min-height: 130px;
  overflow: visible;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.38rem;
}

.books-placeholder {
  padding: 0.2rem;
}

.book-chip {
  border: 1px solid var(--surface-border);
  border-radius: 999px;
  background: rgba(20, 30, 44, 0.54);
  padding: 0.27rem 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.25;
  max-width: 100%;
}

.button-row {
  display: flex;
  gap: 0.62rem;
}

.btn {
  flex: 1;
  font-weight: 700;
  cursor: pointer;
  box-shadow: none;
}

.btn:hover {
  border-color: #adc2de;
}

.result-panel {
  min-height: 260px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.56rem;
  margin-bottom: 0.9rem;
}

.summary-card {
  margin: 0;
  border: 1px solid #365071;
  border-radius: 10px;
  padding: 0.62rem;
  background: rgba(12, 20, 32, 0.66);
}

.summary-label {
  margin: 0 0 0.2rem;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.summary-value {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.step-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.step-card {
  border: 1px solid #365071;
  border-radius: 10px;
  margin-bottom: 0.58rem;
  padding: 0.62rem 0.72rem;
  background: rgba(15, 22, 36, 0.72);
}

.step-card.is-expensive {
  border-color: #8f4e57;
  background: rgba(53, 20, 29, 0.45);
}

.step-title,
.step-cost,
.step-pwp,
.step-warning {
  margin: 0;
}

.step-title {
  font-weight: 700;
  margin-bottom: 0.24rem;
}

.step-cost,
.step-pwp {
  color: #dbe7ff;
  font-variant-numeric: tabular-nums;
}

.step-pwp {
  margin-top: 0.14rem;
}

.step-warning {
  color: var(--warning);
  margin-top: 0.24rem;
  font-size: 0.84rem;
}

.placeholder {
  margin: 0;
  color: var(--text-muted);
}

.error-text {
  margin: 0;
  color: var(--error);
  font-weight: 700;
}

.enchant-list,
.custom-option-list,
.selected-books {
  scrollbar-width: thin;
  scrollbar-color: #617794 #111a28;
}

.enchant-list::-webkit-scrollbar,
.custom-option-list::-webkit-scrollbar,
.selected-books::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

.enchant-list::-webkit-scrollbar-track,
.custom-option-list::-webkit-scrollbar-track,
.selected-books::-webkit-scrollbar-track {
  background: #111a28;
  border-radius: 999px;
}

.enchant-list::-webkit-scrollbar-thumb,
.custom-option-list::-webkit-scrollbar-thumb,
.selected-books::-webkit-scrollbar-thumb {
  background: #617794;
  border-radius: 999px;
  border: 2px solid #111a28;
}

.enchant-list::-webkit-scrollbar-thumb:hover,
.custom-option-list::-webkit-scrollbar-thumb:hover,
.selected-books::-webkit-scrollbar-thumb:hover {
  background: #8498b3;
}

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

  .enchant-list {
    max-height: 300px;
  }

  .selected-books {
    min-height: 130px;
    overflow: auto;
    max-height: 220px;
  }
}

@media (max-width: 560px) {
  .page-shell {
    width: min(1200px, 96vw);
    padding-top: 1.15rem;
  }

  .panel {
    padding: 0.84rem;
  }

  .enchant-row {
    grid-template-columns: 1fr;
  }

  .level-buttons {
    justify-content: flex-start;
  }
}
