:root {
  /* deep indigo-navy base instead of brown - lets the warm accents actually pop */
  --bg: #0e1220;
  --surface: #161b2a;
  --surface-2: #1d2436;
  --border: #2b3249;
  --border-strong: #3e4763;

  --text: #e9e7de;
  --text-muted: #939aad;
  --text-faint: #5f6779;

  /* brass gold - primary accent, complementary to the blue base */
  --brass: #caa14a;
  --brass-strong: #e3bd66;
  --on-brass: #201804;

  /* oxblood red - secondary accent / danger */
  --wine: #ac4238;
  --wine-strong: #cf5344;

  /* moss green - tertiary accent, used for positive actions */
  --sage: #4f9155;
  --sage-strong: #67ac6b;

  /* warm parchment card - deliberate contrast against the blue page */
  --card: #efe8d7;
  --card-border: #d8cba7;
  --ink: #2a2317;
  --ink-muted: #6d6250;

  --radius: 10px;
  --radius-sm: 7px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1000px 600px at 12% -8%, rgba(100,120,200,0.14), transparent 60%),
    radial-gradient(900px 500px at 105% 5%, rgba(202,161,74,0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--brass), var(--wine) 130%);
}

.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.lang-toggle { display: flex; gap: 0.3rem; }

.lang-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.lang-btn:hover { border-color: var(--brass); color: var(--brass-strong); }

.lang-btn.active {
  background: var(--brass);
  color: var(--on-brass);
  border-color: var(--brass);
}

main {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 2rem auto;
  padding: 0 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.panel-header h2 {
  margin: 0;
  padding-left: 0.7rem;
  border-left: 3px solid var(--brass);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

#search {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 0.5rem 0.7rem 0.5rem 2.1rem;
  border-radius: var(--radius-sm);
  min-width: 210px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23939aad' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.65rem center;
  background-size: 14px;
}

#search:focus { outline: none; border-color: var(--brass); }
#search::placeholder { color: var(--text-faint); }

.dice-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 60vh;
  overflow-y: auto;
}

.die-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: border-color 0.15s ease;
}

.die-row:hover { border-color: var(--border-strong); }

.die-row.owned { border-color: rgba(202,161,74,0.45); }

.die-info { flex: 1; min-width: 0; }

.die-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
}

.owned-badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--on-brass);
  background: var(--brass);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

.die-faces {
  font-size: 0.83rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.die-special {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.45rem;
  line-height: 1.45;
}

.count-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.count-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.count-btn:hover { border-color: var(--brass); color: var(--brass-strong); }
.count-btn-plus:hover { border-color: var(--sage); color: var(--sage-strong); }
.count-btn-minus:hover { border-color: var(--wine); color: var(--wine-strong); }

.count-value {
  min-width: 1.4em;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.optimize-panel { text-align: center; }

.exact-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  margin-bottom: 1.1rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
}

.exact-toggle input { cursor: pointer; accent-color: var(--brass); width: 15px; height: 15px; }

.optimize-btn {
  background: var(--brass);
  color: var(--on-brass);
  border: none;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.75rem 2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease;
}

.optimize-btn:hover { background: var(--brass-strong); }
.optimize-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.optimize-status { margin-top: 1.15rem; }

.progress-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--brass);
  transition: width 0.3s ease;
}

.progress-fill.indeterminate {
  width: 30% !important;
  animation: progress-indeterminate 1.1s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% { margin-left: -30%; }
  100% { margin-left: 100%; }
}

#progress-text {
  font-size: 0.83rem;
  color: var(--text-muted);
  margin: 0.5rem 0 0;
}

.stop-btn {
  margin-top: 0.7rem;
  background: transparent;
  color: var(--wine-strong);
  border: 1px solid var(--wine);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 1.1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.stop-btn:hover { background: var(--wine); color: var(--text); }
.stop-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.result {
  margin-top: 1.35rem;
  text-align: left;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.35rem 1.25rem;
}

.result h3 {
  margin: 0 0 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--wine);
}

.result-combo {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.7rem;
}

.result-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.result-count {
  font-weight: 700;
  color: var(--wine);
  min-width: 1.6em;
}

.result-ev {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  padding-top: 0.5rem;
  border-top: 1px solid var(--card-border);
}

.result-mode {
  font-size: 0.83rem;
  color: var(--ink-muted);
  margin-top: 0.35rem;
}

.result-mode.heuristic { color: var(--wine); }

.error-msg {
  color: var(--wine-strong);
  font-weight: 600;
}
