:root {
  --bg: #313338;
  --bg-deep: #1e1f22;
  --surface: #2b2d31;
  --surface-strong: #232428;
  --surface-hover: #35373c;
  --input: #1e1f22;
  --text: #dbdee1;
  --heading: #f2f3f5;
  --muted: #949ba4;
  --muted-strong: #b5bac1;
  --line: #3f4147;
  --line-soft: #383a40;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --success: #23a559;
  --success-bg: rgba(35, 165, 89, 0.16);
  --danger: #f23f42;
  --danger-hover: #d83c3e;
  --warning: #f0b232;
  --closed: #80848e;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  --item-satanic: #f23f42;
  --item-mythic: #c874ff;
  --item-legendary: #f0b232;
  --item-rare: #6ee7f9;
  --item-set: #23a559;
  --game-green: #00f08a;
  --game-red: #ff252b;
  --game-gold: #d8c36f;
  --game-orange: #ff5a18;
  --game-pink: #ff3f98;
  --game-violet: #8d82ff;
  --game-gray: #9a9a9a;
  --game-white: #f5f5f5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "gg sans", "Noto Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 3px;
  background: #4e5058;
  color: var(--heading);
  cursor: pointer;
  font-weight: 600;
  transition: background-color 120ms ease, color 120ms ease, opacity 120ms ease;
}

button:hover {
  background: #5c5f66;
}

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

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--bg-deep);
  border-radius: 3px;
  padding: 9px 10px;
  background: var(--input);
  color: var(--text);
}

input::placeholder {
  color: #6d737d;
}

input:focus,
button:focus-visible {
  border-color: var(--accent);
  outline: 2px solid rgba(88, 101, 242, 0.32);
  outline-offset: 1px;
}

input.field-error {
  border-color: var(--danger);
  outline: 2px solid rgba(242, 63, 66, 0.24);
}

label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.image-field > span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

::-webkit-scrollbar {
  width: 10px;
}

::-webkit-scrollbar-track {
  background: var(--surface-strong);
}

::-webkit-scrollbar-thumb {
  background: #1a1b1e;
  border: 2px solid var(--surface-strong);
  border-radius: 999px;
}

.app-shell {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0;
}

.topbar h1 {
  margin: 0;
  color: var(--heading);
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.1;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
}

.connection {
  flex: 0 0 auto;
  min-width: 112px;
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(240, 178, 50, 0.14);
  color: var(--warning);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.connection.online {
  background: var(--success-bg);
  color: var(--success);
}

.controls {
  display: grid;
  grid-template-columns: minmax(180px, 320px) minmax(0, 1fr);
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.create-panel,
.rolls-panel {
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.create-panel {
  padding: 16px;
}

.create-panel h2,
.rolls-panel h2 {
  margin: 0;
  color: var(--heading);
  font-size: 18px;
  line-height: 1.2;
}

.create-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.field-hint {
  margin-top: 6px;
  color: #ff9b9d;
  font-size: 12px;
  font-weight: 700;
}

.field-hint.hidden,
.create-preview.hidden {
  display: none;
}

.create-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.create-item-pill {
  width: auto;
  max-width: 100%;
  min-height: 28px;
  padding: 5px 10px;
  background: rgba(0, 0, 0, 0.36);
  font-size: 13px;
  line-height: 1.2;
}

.image-field {
  display: grid;
  gap: 8px;
}

.image-dropzone {
  display: grid;
  place-items: center;
  min-height: 76px;
  border: 1px dashed #4e5058;
  border-radius: 4px;
  background: var(--input);
  transition: border-color 120ms ease, background-color 120ms ease;
}

.image-dropzone:hover,
.image-dropzone:focus,
.image-dropzone.drag-over {
  border-color: var(--accent);
  background: rgba(88, 101, 242, 0.1);
  outline: 0;
}

.image-dropzone.has-image {
  min-height: 48px;
}

.image-dropzone button,
.image-preview-actions button {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 13px;
}

.image-preview {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  padding: 8px;
  background: var(--surface-strong);
}

.image-preview.hidden {
  display: none;
}

.image-preview img {
  width: 72px;
  height: 72px;
  border-radius: 3px;
  object-fit: cover;
  background: var(--input);
}

.image-preview strong {
  display: block;
  overflow: hidden;
  color: var(--heading);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.create-form button,
.roll-button {
  background: var(--accent);
  color: white;
}

.create-form button:hover,
.roll-button:hover {
  background: var(--accent-hover);
}

.server-scope {
  min-height: 40px;
  border: 1px solid var(--bg-deep);
  border-radius: 3px;
  padding: 9px 10px;
  background: var(--input);
  color: var(--muted-strong);
  font-size: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 10px;
}

.tabs {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(70px, 1fr));
  gap: 2px;
  border-radius: 4px;
  padding: 2px;
  background: var(--bg-deep);
}

.tab {
  min-height: 34px;
  border-radius: 3px;
  background: transparent;
  color: var(--muted-strong);
  font-size: 13px;
}

.tab:hover {
  background: var(--surface-hover);
  color: var(--heading);
}

.tab.active {
  background: var(--accent);
  color: white;
}

.search-row {
  padding: 0 16px 14px;
}

.message-box {
  margin: 0 16px 12px;
  border-left: 4px solid var(--warning);
  border-radius: 4px;
  padding: 10px 12px;
  background: rgba(240, 178, 50, 0.12);
  color: #ffd98a;
}

.hidden {
  display: none;
}

.roll-list {
  display: grid;
  gap: 10px;
  padding: 0 16px 16px;
}

.empty-state {
  border: 1px dashed #4e5058;
  border-radius: 6px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-strong);
}

.roll-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 320px) auto;
  gap: 14px;
  align-items: start;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 14px;
  background: var(--surface-strong);
}

.roll-card:hover {
  background: #292b30;
  border-color: #4e5058;
}

.roll-title-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.key,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}

.key {
  background: rgba(88, 101, 242, 0.18);
  color: #c9cdfb;
}

.status {
  background: var(--success-bg);
  color: #8ff0b3;
}

.status.closed {
  background: rgba(128, 132, 142, 0.16);
  color: var(--closed);
}

.item-pill {
  min-height: 25px;
  max-width: min(360px, 100%);
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 3px 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.28);
  color: #ffe4a3;
  font-size: 12px;
  font-weight: 800;
  text-shadow: 0 1px 0 #000;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-pill:hover {
  background: rgba(0, 0, 0, 0.42);
}

.image-pill {
  min-height: 25px;
  max-width: min(360px, 100%);
  border: 1px solid rgba(88, 101, 242, 0.65);
  border-radius: 4px;
  padding: 3px 8px;
  overflow: hidden;
  background: rgba(88, 101, 242, 0.14);
  color: #c9cdfb;
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-pill:hover {
  background: rgba(88, 101, 242, 0.22);
}

.item-pill.theme-arcane,
.item-tooltip.theme-arcane {
  color: var(--game-pink);
}

.item-pill.rarity-satanic,
.item-tooltip.rarity-satanic {
  color: var(--game-red);
}

.item-pill.rarity-satanic-set,
.item-tooltip.rarity-satanic-set,
.item-pill.rarity-heroic,
.item-tooltip.rarity-heroic {
  color: var(--game-green);
}

.item-pill.rarity-mythic,
.item-tooltip.rarity-mythic {
  color: #dab3ff;
}

.item-pill.rarity-unholy,
.item-tooltip.rarity-unholy {
  color: var(--game-pink);
}

.item-pill.rarity-legendary,
.item-tooltip.rarity-legendary,
.item-pill.rarity-angelic,
.item-tooltip.rarity-angelic {
  color: #f2f06a;
}

.item-pill.rarity-rare,
.item-tooltip.rarity-rare {
  color: #b4f4ff;
}

.roll-card h3 {
  margin: 10px 0 8px;
  overflow-wrap: anywhere;
  color: var(--heading);
  font-size: 17px;
  line-height: 1.25;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.entries {
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--bg-deep);
  border-radius: 4px;
  background: var(--input);
}

.entry-row,
.no-entries {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--text);
  font-size: 14px;
}

.entry-row:last-child {
  border-bottom: 0;
}

.entry-high {
  background: rgba(35, 165, 89, 0.1);
}

.entry-low {
  background: rgba(242, 63, 66, 0.09);
}

.entry-high.entry-low {
  background: rgba(88, 101, 242, 0.1);
}

.entry-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-badges {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 16px;
}

.entry-badge {
  display: block;
  width: 16px;
  height: 16px;
}

.entry-score {
  color: var(--heading);
  font-weight: 800;
}

.no-entries {
  color: var(--muted);
}

.actions {
  display: grid;
  grid-template-columns: 92px;
  gap: 8px;
}

.close-button {
  background: var(--danger);
  color: white;
}

.close-button:hover {
  background: var(--danger-hover);
}

.reopen-button {
  background: #248046;
  color: white;
}

.reopen-button:hover {
  background: #1a6334;
}

.modal-open {
  overflow: hidden;
}

.item-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
}

.item-modal.hidden {
  display: none;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 21;
  display: grid;
  place-items: center;
  padding: 18px;
}

.image-modal.hidden {
  display: none;
}

.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
}

.image-modal-panel {
  position: relative;
  width: min(960px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.image-modal-panel img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 120px);
  object-fit: contain;
  border-radius: 4px;
  background: #050505;
}

.image-modal-name {
  margin-top: 10px;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 700;
}

.hover-preview {
  position: fixed;
  z-index: 30;
  overflow: auto;
  pointer-events: none;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
}

.hover-preview.hidden {
  display: none;
}

.hover-item-preview {
  width: min(620px, calc(100vw - 24px));
  border: 1px solid currentColor;
  padding: 12px 28px 18px;
  background: rgba(0, 0, 0, 0.91);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.64), inset 0 0 38px rgba(0, 0, 0, 0.72);
  color: var(--game-gold);
  font-family: "CookieRunBold", "CookieRunOTF Bold", "CookieRunOTF", "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  text-align: center;
  text-shadow: 0 2px 0 #000, 0 0 2px #000;
}

.hover-item-preview h2 {
  margin: 0;
  color: currentColor;
  font-size: clamp(25px, 3.4vw, 36px);
  font-weight: 900;
  line-height: 1.05;
}

.hover-item-preview .item-rarity {
  font-size: clamp(17px, 2.2vw, 21px);
}

.hover-item-preview .item-stats {
  margin-top: 14px;
  border-top: 1px solid color-mix(in srgb, currentColor 34%, transparent);
  padding-top: 13px;
}

.hover-item-preview .item-stats li {
  font-size: clamp(17px, 2.15vw, 23px);
}

.hover-item-footer {
  margin-top: 16px;
  border-top: 1px solid color-mix(in srgb, currentColor 24%, transparent);
  padding-top: 13px;
  color: var(--game-gray);
  font-size: clamp(17px, 2.1vw, 22px);
  font-weight: 900;
}

.hover-image-preview {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.hover-image-preview img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 110px);
  object-fit: contain;
  border-radius: 4px;
  background: #050505;
}

.hover-image-preview div {
  margin-top: 8px;
  overflow: hidden;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
}

.item-modal-panel {
  position: relative;
  width: min(760px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid currentColor;
  border-radius: 0;
  padding: 18px 34px 24px;
  background: rgba(0, 0, 0, 0.91);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.66), inset 0 0 42px rgba(0, 0, 0, 0.72);
  color: var(--game-gold);
  font-family: "CookieRunBold", "CookieRunOTF Bold", "CookieRunOTF", "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  text-align: center;
  text-shadow: 0 2px 0 #000, 0 0 2px #000;
}

.item-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  min-height: 30px;
  padding: 0;
  background: transparent;
  color: var(--muted-strong);
  font-size: 20px;
  line-height: 1;
}

.item-modal-close:hover {
  background: rgba(255, 255, 255, 0.08);
}

.item-modal-head {
  display: block;
  padding: 0 34px;
}

.item-modal-head h2 {
  margin: 0;
  color: currentColor;
  font-size: clamp(30px, 4.7vw, 42px);
  font-weight: 900;
  line-height: 1.05;
}

.item-rarity {
  display: block;
  margin-top: 3px;
  border: 0;
  padding: 0;
  color: var(--game-gray);
  font-size: clamp(18px, 2.6vw, 24px);
  font-weight: 900;
  text-transform: none;
}

.item-wiki-link {
  position: absolute;
  top: 10px;
  left: 10px;
  min-height: 34px;
  border-radius: 3px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #d8d8d8;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  text-shadow: none;
}

.item-wiki-link:hover {
  background: rgba(255, 255, 255, 0.14);
}

.item-lore {
  margin: 18px auto 0;
  max-width: 620px;
  border-top: 1px solid color-mix(in srgb, currentColor 24%, transparent);
  padding-top: 16px;
  color: currentColor;
  font-size: clamp(18px, 2.35vw, 23px);
  font-weight: 900;
  line-height: 1.35;
}

.item-facts {
  display: block;
  margin-top: 18px;
  border-top: 1px solid color-mix(in srgb, currentColor 24%, transparent);
  padding-top: 15px;
  color: var(--game-gray);
  font-size: clamp(19px, 2.45vw, 24px);
  font-weight: 900;
}

.item-facts-line,
.hover-item-footer {
  text-align: center;
}

.item-fact-label {
  color: var(--game-gray);
}

.item-fact-value {
  color: var(--game-white);
}

.item-tier-value {
  color: #fff36a;
}

.item-stat-block {
  margin-top: 16px;
  border-top: 1px solid color-mix(in srgb, currentColor 34%, transparent);
  padding-top: 14px;
}

.item-stats {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.item-stats li {
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: var(--game-violet);
  font-size: clamp(18px, 2.45vw, 25px);
  font-weight: 900;
  line-height: 1.13;
}

.item-stats .item-stat-base {
  color: var(--game-white);
}

.item-stats .item-stat-base[data-stat-color="default"] {
  color: var(--game-white);
}

.item-stat-divider {
  height: 1px;
  width: 56%;
  margin: 9px auto;
  padding: 0;
  background: color-mix(in srgb, currentColor 30%, transparent);
}

.item-stats .item-stat-effect {
  max-width: 620px;
  margin: 0 auto;
  color: var(--game-orange);
  font-size: 0.84em;
  line-height: 1.15;
}

.item-stats .item-stat-description {
  max-width: 620px;
  margin: 2px auto 1px;
  color: var(--game-gray);
  font-size: 0.84em;
  line-height: 1.18;
}

.item-stats .item-stat-proc {
  color: var(--game-orange);
}

.item-stats li[data-stat-color="red"] {
  color: var(--game-pink);
}

.item-stats li[data-stat-color="green"] {
  color: var(--game-green);
}

.item-stats li[data-stat-color="blue"] {
  color: var(--game-violet);
}

.item-stats li[data-stat-color="yellow"],
.item-stats li[data-stat-color="orange"],
.item-stats li[data-stat-color="allskills"] {
  color: var(--game-gold);
}

.item-stats li[data-stat-color="orange"] {
  color: var(--game-orange);
}

.item-stats li[data-stat-color="arcane"] {
  color: var(--game-pink);
}

.item-stats li[data-stat-color="default"] {
  color: var(--game-violet);
}

.item-stat-empty {
  color: var(--game-gray);
}

.hover-lore {
  margin-top: 14px;
  padding-top: 13px;
  font-size: clamp(17px, 2.1vw, 22px);
}

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

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .connection {
    width: 100%;
  }

  .tabs {
    width: 100%;
  }
}
