@media (prefers-color-scheme: light) {
    :root {
        --bg: #f2f0ea;
        --paper: #fffdf9;
        --ink: #2d2418;
        --muted: #6f6556;
        --line: #d9d1c5;
        --accent: #8a5a2b;
        --accent-strong: #6d431a;
    }
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1e1e1e;
        --paper: #2d2d2d;
        --ink: #ffffff;
        --muted: #a0a0a0;
        --line: #444444;
        --accent: #8a5a2b;
        --accent-strong: #6d431a;
    }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.app {
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px;
  width: 100%;
}

.header h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2.5vw, 2rem);
}

.header p {
  margin: 8px 0 0;
  color: var(--muted);
}

.layout {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 8px 24px rgba(41, 30, 14, 0.08);
}

.table-head,
.stat-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  align-items: center;
}

.table-head {
  font-weight: 700;
  padding: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}

.stats-grid {
  display: grid;
  gap: 6px;
}

.stat-row {
  padding: 4px 6px;
  border-radius: 8px;
}

.stat-row:nth-child(odd) {
  background: var(--paper);
}

.stat-row label {
  font-weight: 600;
}

input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
}

input[type="number"]:focus {
  outline: 2px solid #d8b792;
  border-color: var(--accent);
}

.actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  color: #fff;
  background: var(--accent);
  font: inherit;
  font-weight: 700;
  transition: transform 0.1s ease, background 0.2s ease;
}

button:hover {
  background: var(--accent-strong);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: var(--muted);
}

button.secondary:hover {
  background: var(--line);
}

.help-card h2,
.output-card h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.help-content {
  max-height: 80%;
  overflow: auto;
  line-height: 1.45;
}

.help-content p {
  margin: 10px 0 4px;
  font-weight: 700;
}

.help-content ul {
  margin: 4px 0 0 18px;
  padding: 0;
}

.output-card {
  margin-top: 12px;
}

#output {
  min-height: 220px;
  margin: 0;
  white-space: pre-wrap;
  font-family: Consolas, "Courier New", monospace;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.loading-popup {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.24);
  z-index: 999;
}

.loading-popup.is-visible {
  display: flex;
}

.loading-popup__box {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}

@media (max-width: 840px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .help-content {
    max-height: none;
  }
}
.max-level {
   display: flex;
   align-items: center;
   gap: 8px;
   margin-bottom: 12px;
   padding: 6px;
}

#maxLevel {
   width: 50%;
   margin-left: 20%;
}

.footer {
  margin-top: 32px;
  padding: 16px 12px;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.footer p {
  margin: 4px 0;
}