:root {
  --bg: #0f172a;
  --panel: #111827;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #334155;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 18px;
  --good: #86efac;
  --neutral: #cbd5e1;
  --bad: #fca5a5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  background-image: linear-gradient(160deg, rgba(2,6,23,0.85), rgba(15,23,42,0.85) 45%, rgba(17,24,39,0.85)), url('images/mars-background.jpg');
  background-attachment: fixed;
  background-size: 110% auto;
  background-repeat: no-repeat;
  background-position: center center;
  overflow-x: hidden;
  will-change: background-position;
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

.hero, .panel, .trait-card, .history-item {
  background: rgba(17, 24, 39, .94);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero { padding: 28px; margin-bottom: 20px; }

.hero-header {
  display: flex;
  align-items: center;
  gap: 28px;
  justify-content: space-between;
}

.hero-content {
  flex: 1;
}

.hero-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pawn-wrapper {
  position: relative;
  display: inline-block;
  width: min(200px, 24vw);
  isolation: isolate;
  user-select: none;
}

.logo-image,
.pawn-image {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 0 20px rgba(56,189,248,.3));
  transition: transform 0.3s ease, filter 0.3s ease;
}

.pawn-wrapper:hover .logo-image,
.pawn-wrapper:hover .pawn-image {
  transform: scale(1.03);
  filter: drop-shadow(0 0 30px rgba(56,189,248,.45));
}

.pawn-eye {
  position: absolute;
  width: 4.8%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: #05070c;
  pointer-events: none;
  z-index: 2;
  transform: translate3d(0, 0, 0);
  box-shadow: 0 0 0 1px rgba(0,0,0,.15);
}

/* Tuned for your PNG */
.eye-left {
  left: 44.15%;
  top: 33.6%;
}

.eye-right {
  left: 56.9%;
  top: 33.6%;
}

h1 { margin: 0 0 8px; font-size: clamp(2rem, 4vw, 3rem); }
h2, h3 { margin-top: 0; }
.subtitle, .lead, .small-note { color: var(--muted); line-height: 1.6; }
.mt-20 { margin-top: 20px; }

.panel { padding: 20px; }

.grid {
  display: grid;
  grid-template-columns: 2.1fr 1fr;
  gap: 20px;
}

.panel-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 14px;
}

.setting-box {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(15, 23, 42, .45);
}

.setting-box label {
  display: block;
  font-size: .9rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.setting-box input,
.reference-controls input,
.reference-controls select {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #020617;
  color: white;
}

.preset-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

.preset-label {
  color: var(--muted);
  font-weight: 700;
  margin-right: 4px;
}

.music-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(15, 23, 42, .45);
}

.control-label {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.volume-control {
  display: flex;
  gap: 8px;
  align-items: center;
}

.volume-control label {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.volume-control input[type="range"] {
  width: 120px;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, rgba(56,189,248,.3), rgba(56,189,248,.6));
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
}

.volume-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(56,189,248,.8);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(56,189,248,.4);
}

.volume-control input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(56,189,248,.8);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 8px rgba(56,189,248,.4);
}

#volumeLabel {
  color: var(--text);
  font-weight: 600;
  min-width: 35px;
  text-align: right;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 700;
  cursor: pointer;
  color: white;
  transition: transform .16s ease, opacity .16s ease, box-shadow .2s ease;
}

button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }

.primary { background: linear-gradient(135deg, #16a34a, #22c55e); }
.secondary { background: linear-gradient(135deg, #0284c7, #38bdf8); }
.ghost { background: linear-gradient(135deg, #475569, #64748b); }
.danger { background: linear-gradient(135deg, #dc2626, #ef4444); }
.small-btn { padding: 8px 12px; font-size: .84rem; }

.status-area { margin-top: 14px; min-height: 28px; }
.status-message {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: .92rem;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, .45);
}
.status-message.error { border-color: rgba(239,68,68,.55); color: var(--bad); }
.status-message.ok { border-color: rgba(34,197,94,.55); color: var(--good); }

.traits-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.trait-card {
  padding: 18px;
  background: linear-gradient(180deg, rgba(31,41,55,.9), rgba(17,24,39,.95));
  position: relative;
  overflow: hidden;
  transform: translateY(0) scale(1);
  transition: transform .18s ease, box-shadow .22s ease, filter .22s ease, border-color .22s ease;
  transform-style: preserve-3d;
}

.trait-card:hover {
  transform: translateY(-4px) scale(1.015);
  box-shadow: 0 0 0 1px rgba(148,163,184,.22), 0 12px 26px rgba(0,0,0,.4), 0 0 18px rgba(56,189,248,.08);
  filter: brightness(1.04);
}

.trait-card.locked {
  box-shadow: 0 0 0 1px rgba(56,189,248,.65), 0 0 20px rgba(56,189,248,.16), var(--shadow);
}

.trait-card.lock-pulse {
  animation: lockPulse .42s ease;
}

.trait-card.rerolling {
  animation: rerollGlow 0.8s ease-in-out infinite;
  box-shadow: 0 0 0 2px rgba(56,189,248,.6), 0 0 30px rgba(56,189,248,.2), var(--shadow);
}

.trait-card.rolling {
  animation: csgoRoll var(--roll-duration, 0.48s) ease-out both;
}

@keyframes lockPulse {
  0% { transform: scale(1); box-shadow: 0 0 0 1px rgba(56,189,248,.4), 0 0 0 rgba(56,189,248,0); }
  45% { transform: scale(1.045); box-shadow: 0 0 0 1px rgba(56,189,248,.8), 0 0 26px rgba(56,189,248,.35); }
  100% { transform: scale(1); box-shadow: 0 0 0 1px rgba(56,189,248,.65), 0 0 20px rgba(56,189,248,.16), var(--shadow); }
}

@keyframes rerollFlip {
  0% { transform: rotateY(0deg) scale(1); filter: blur(0px); opacity: 1; }
  45% { transform: rotateY(90deg) scale(.98); filter: blur(2px); opacity: .35; }
  55% { transform: rotateY(90deg) scale(.98); filter: blur(2px); opacity: .35; }
  100% { transform: rotateY(0deg) scale(1); filter: blur(0px); opacity: 1; }
}

@keyframes rerollSpin {
  0% { transform: rotateY(0deg) scale(1); }
  25% { transform: rotateY(90deg) scale(0.98); }
  50% { transform: rotateY(180deg) scale(1); }
  75% { transform: rotateY(270deg) scale(0.98); }
  100% { transform: rotateY(360deg) scale(1); }
}

@keyframes rerollGlow {
  0% { box-shadow: 0 0 0 2px rgba(56,189,248,.6), 0 0 30px rgba(56,189,248,.2), var(--shadow); }
  50% { box-shadow: 0 0 0 3px rgba(56,189,248,.8), 0 0 40px rgba(56,189,248,.4), var(--shadow); }
  100% { box-shadow: 0 0 0 2px rgba(56,189,248,.6), 0 0 30px rgba(56,189,248,.2), var(--shadow); }
}

@keyframes rollReveal {
  0% { transform: translateY(12px) scale(.97); opacity: 0; filter: blur(5px); }
  100% { transform: translateY(0) scale(1); opacity: 1; filter: blur(0); }
}

@keyframes csgoRoll {
  0% { transform: translateY(-20px); opacity: 0.6; }
  100% { transform: translateY(0); opacity: 1; }
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .02em;
  margin-bottom: 10px;
  border: 1px solid transparent;
}

.good { background: rgba(34,197,94,.15); color: var(--good); border-color: rgba(34,197,94,.35); }
.neutral { background: rgba(148,163,184,.15); color: var(--neutral); border-color: rgba(148,163,184,.35); }
.bad { background: rgba(239,68,68,.15); color: var(--bad); border-color: rgba(239,68,68,.35); }

.trait-name {
  font-size: 1.1rem;
  font-weight: 800;
  margin-bottom: 12px;
  min-height: 2.2rem;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.history-list {
  display: grid;
  gap: 12px;
  max-height: 640px;
  overflow: auto;
}

.history-item {
  padding: 14px;
  background: rgba(15,23,42,.55);
  transform: translateY(8px);
  opacity: 0;
  animation: historyIn .28s ease forwards;
}

@keyframes historyIn {
  to { transform: translateY(0); opacity: 1; }
}

.history-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
  cursor: pointer;
}

.history-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-tag {
  font-size: .82rem;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(148,163,184,.1);
  border: 1px solid rgba(148,163,184,.16);
}

.history-details {
  display: none;
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.history-item.open .history-details {
  display: block;
}

.chosen-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.chosen-summary-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: rgba(15,23,42,.5);
}

.chosen-summary-card h3 { margin: 0 0 10px; }

.chosen-line, .ref-line {
  color: var(--muted);
  line-height: 1.6;
  margin-top: 6px;
}

.reference-controls {
  display: flex;
  gap: 10px;
  min-width: min(460px, 100%);
}

.reference-controls input { min-width: 220px; }

.reference-group { margin-bottom: 20px; }

.reference-list {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.reference-item {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: rgba(15,23,42,.45);
  transition: all 0.3s ease;
}

.reference-item-glow {
  border-color: rgba(56,189,248,.8);
  background: rgba(56,189,248,.15);
  box-shadow: 0 0 0 1px rgba(56,189,248,.4), 0 0 20px rgba(56,189,248,.2), inset 0 0 15px rgba(56,189,248,.08);
  animation: referenceGlow 2s ease-in-out infinite;
}

@keyframes referenceGlow {
  0%, 100% {
    box-shadow: 0 0 0 1px rgba(56,189,248,.4), 0 0 20px rgba(56,189,248,.2), inset 0 0 15px rgba(56,189,248,.08);
  }
  50% {
    box-shadow: 0 0 0 2px rgba(56,189,248,.6), 0 0 30px rgba(56,189,248,.35), inset 0 0 20px rgba(56,189,248,.12);
  }
}

.reference-item strong { display: block; margin-bottom: 6px; }

.empty {
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 18px;
  text-align: center;
}

.tooltip {
  position: fixed;
  max-width: 320px;
  z-index: 1000;
  padding: 12px 14px;
  background: rgba(2,6,23,.96);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.tooltip.hidden { display: none; }
.tooltip-title { font-weight: 800; margin-bottom: 6px; }
.tooltip-line { color: var(--muted); line-height: 1.5; margin-top: 4px; }

@media (max-width: 920px) {
  .hero-header {
    flex-direction: column;
    text-align: center;
  }

  .hero-logo {
    justify-content: center;
  }

  .grid,
  .traits-grid,
  .chosen-summary-grid,
  .settings-grid,
  .reference-list,
  .reference-controls {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .pawn-wrapper {
    width: min(180px, 42vw);
  }
}
