:root {
  --bg: #111318;
  --panel: #191d25;
  --panel-soft: #202632;
  --line: #303846;
  --line-strong: #465366;
  --text: #f3ead8;
  --muted: #b9aa90;
  --gold: #d8aa4c;
  --gold-soft: #f5cf75;
  --green: #77d68b;
  --red: #c96b5c;
  --blue: #78a8e8;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background:
    radial-gradient(circle at 18% 0%, rgba(216, 170, 76, 0.12), transparent 32%),
    linear-gradient(135deg, #111318 0%, #17120e 52%, #10141b 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

h1,
h2,
p,
figure {
  margin: 0;
}

.app-shell {
  width: min(1780px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  color: #20150b;
  font-weight: 900;
  background: linear-gradient(180deg, #ffe09a, #c48a2e);
  border: 1px solid #ffe7a8;
  border-radius: 8px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.34);
}

h1 {
  font-size: clamp(28px, 3vw, 44px);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p,
.section-head span,
label span,
.catalog-name small,
.reward-item-name small {
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(380px, 0.75fr);
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid rgba(216, 170, 76, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 232, 166, 0.04), rgba(0, 0, 0, 0)),
    rgba(25, 29, 37, 0.92);
  box-shadow:
    0 20px 42px rgba(0, 0, 0, 0.34),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.editor-panel,
.stats-panel,
.preview-panel,
.output-panel {
  padding: 16px;
}

.side-stack {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 42px;
  margin-bottom: 12px;
}

.section-head > div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.type-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(112px, 1fr));
  gap: 6px;
  margin: 0;
  padding: 5px;
  border: 1px solid rgba(216, 170, 76, 0.28);
  border-radius: 8px;
  background: rgba(12, 14, 19, 0.68);
}

.type-switch label {
  position: relative;
  display: grid;
  min-height: 36px;
  place-items: center;
  color: var(--muted);
}

.type-switch input {
  position: absolute;
  opacity: 0;
}

.type-switch span {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
}

.type-switch input:checked + span {
  color: #fff5ca;
  background: linear-gradient(180deg, #8a422f, #5a251d);
  box-shadow: inset 0 0 0 1px rgba(255, 221, 135, 0.48);
}

.entry-toolbar,
.meta-grid,
.custom-grid {
  display: grid;
  gap: 10px;
}

.entry-toolbar {
  grid-template-columns: minmax(260px, 1fr) auto auto auto;
  align-items: end;
  margin-bottom: 14px;
}

.meta-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.custom-grid {
  grid-template-columns: minmax(110px, 0.65fr) minmax(180px, 1fr) minmax(220px, 1.2fr) auto auto;
  align-items: end;
}

label {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.wide-field {
  grid-column: span 2;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 10, 14, 0.72);
  outline: none;
}

input,
select {
  height: 40px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(216, 170, 76, 0.14);
}

.primary-button,
.ghost-button {
  min-height: 40px;
  padding: 0 14px;
  color: #fff3ca;
  font-weight: 900;
  border-radius: 8px;
  border: 1px solid rgba(255, 221, 135, 0.38);
  background: linear-gradient(180deg, #8a422f, #55241d);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
}

.ghost-button {
  color: var(--text);
  background: rgba(21, 25, 32, 0.9);
}

.ghost-button.active {
  color: #20150b;
  background: linear-gradient(180deg, #ffe09a, #c48a2e);
}

.danger {
  border-color: rgba(201, 107, 92, 0.48);
  color: #ffd1c9;
}

.import-box,
.custom-item {
  margin-bottom: 16px;
  border: 1px solid rgba(216, 170, 76, 0.18);
  border-radius: 8px;
  background: rgba(8, 10, 14, 0.34);
}

.import-box summary,
.custom-item summary {
  padding: 12px 14px;
  color: #ffe2a3;
  font-weight: 900;
  cursor: pointer;
}

.import-grid {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
}

#importText {
  min-height: 150px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.import-actions,
.output-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.catalog-head {
  margin-top: 4px;
}

.catalog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: min(100%, 820px);
}

.search-input {
  width: min(320px, 100%);
}

.item-catalog {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  padding: 4px 3px 10px;
  margin-bottom: 14px;
}

.catalog-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 7px;
  align-items: center;
  min-height: 54px;
  padding: 7px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 18, 24, 0.74);
}

.catalog-item:hover {
  border-color: var(--gold);
  background: rgba(35, 30, 22, 0.9);
}

.catalog-item.favorite {
  border-color: rgba(245, 207, 117, 0.54);
}

.catalog-add {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  min-width: 0;
  min-height: 40px;
  padding: 0;
  color: inherit;
  text-align: left;
  border: 0;
  background: transparent;
}

.favorite-toggle {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: rgba(255, 239, 191, 0.58);
  font-size: 18px;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 10, 14, 0.62);
}

.favorite-toggle[aria-pressed="true"] {
  color: var(--gold-soft);
  border-color: rgba(245, 207, 117, 0.62);
  background: rgba(85, 55, 20, 0.55);
}

.favorite-toggle:hover,
.favorite-toggle:focus-visible {
  border-color: var(--gold-soft);
}

.import-favorites {
  position: relative;
  display: inline-grid;
  place-items: center;
  overflow: hidden;
}

.import-favorites input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.catalog-icon,
.reward-icon {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.36);
}

.catalog-icon {
  width: 40px;
  height: 40px;
}

.catalog-icon img,
.reward-icon img {
  max-width: 31px;
  max-height: 31px;
  object-fit: contain;
}

.catalog-name {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.catalog-name strong,
.reward-item-name strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.add-sign {
  color: var(--gold-soft);
  font-size: 22px;
  font-weight: 900;
}

.reward-columns,
.reward-row {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) 92px 110px 96px 116px;
  gap: 10px;
  align-items: center;
}

.reward-columns {
  padding: 0 10px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.reward-list {
  display: grid;
  gap: 8px;
}

.reward-row {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(14, 17, 23, 0.82);
}

.reward-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.reward-icon {
  width: 42px;
  height: 42px;
}

.reward-item-name {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.actual-chance {
  color: var(--green);
  font-weight: 900;
}

.row-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.icon-button {
  display: grid;
  min-width: 0;
  height: 34px;
  place-items: center;
  color: var(--text);
  font-weight: 900;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(23, 28, 36, 0.9);
}

.icon-button:hover {
  border-color: var(--gold);
}

.average-chart {
  display: grid;
  gap: 10px;
  max-height: 380px;
  overflow: auto;
  padding-right: 4px;
}

.average-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.average-icon {
  position: relative;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  overflow: hidden;
  color: rgba(255, 239, 191, 0.62);
  font-size: 8px;
  line-height: 1;
  background: url("images/belt-frame.png") center / 32px 32px no-repeat;
}

.average-icon img {
  position: relative;
  z-index: 1;
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.slot-fallback {
  position: absolute;
  inset: 4px;
  display: grid;
  place-items: center;
  overflow: hidden;
  text-align: center;
  word-break: break-all;
}

.average-main {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.average-label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.average-label strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.average-label span {
  color: #fff0bf;
  font-weight: 700;
}

.bar-track {
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(9, 6, 4, 0.7);
}

.bar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--gold));
}

.drop-preview-window {
  display: grid;
  grid-template-columns: repeat(9, 32px);
  gap: 0;
  width: 306px;
  max-width: 100%;
  margin: 0 auto;
  padding: 8px 9px;
  overflow-x: auto;
  border: 1px solid rgba(255, 221, 135, 0.26);
  border-radius: 6px;
  background:
    linear-gradient(rgba(8, 5, 4, 0.76), rgba(8, 5, 4, 0.9)),
    radial-gradient(circle at 50% 0, rgba(214, 169, 73, 0.16), transparent 70%);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.72),
    inset 0 0 22px rgba(0, 0, 0, 0.54);
}

.preview-slot {
  position: relative;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  justify-self: center;
  overflow: hidden;
  color: rgba(255, 239, 191, 0.62);
  font-size: 8px;
  line-height: 1;
  background: url("images/belt-frame.png") center / 32px 32px no-repeat;
}

.preview-slot img {
  position: relative;
  z-index: 1;
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.preview-slot.empty .slot-fallback {
  display: none;
}

.preview-count {
  position: absolute;
  right: 3px;
  bottom: 2px;
  z-index: 2;
  color: #fff2a6;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  text-shadow:
    1px 1px 0 #000,
    -1px 1px 0 #000,
    1px -1px 0 #000,
    -1px -1px 0 #000;
  pointer-events: none;
}

.sample-control {
  grid-template-columns: auto 90px;
  align-items: center;
}

.sample-control input {
  height: 34px;
  text-align: center;
}

#outputText {
  min-height: 520px;
  margin-top: 10px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  color: #fff4c5;
  font-weight: 900;
  border: 1px solid rgba(255, 221, 135, 0.34);
  border-radius: 8px;
  background: rgba(18, 13, 8, 0.94);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.34);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .side-stack {
    position: static;
  }
}

@media (max-width: 820px) {
  .topbar,
  .section-head,
  .entry-toolbar,
  .import-actions,
  .output-actions {
    align-items: stretch;
  }

  .topbar,
  .section-head {
    flex-direction: column;
  }

  .top-actions,
  .top-actions .primary-button,
  .type-switch,
  .catalog-actions,
  .catalog-actions .ghost-button,
  .search-input {
    width: 100%;
  }

  .entry-toolbar,
  .meta-grid,
  .custom-grid,
  .reward-columns,
  .reward-row {
    grid-template-columns: 1fr;
  }

  .reward-columns {
    display: none;
  }

  .wide-field {
    grid-column: auto;
  }
}
