:root {
  --bg: #14161d;
  --panel: #1e2230;
  --panel-2: #262b3d;
  --border: #363d55;
  --text: #e8e9f0;
  --muted: #9aa0b5;
  --accent: #c9a84c;
  --accent-dark: #a8892f;
  --danger: #d05555;
  --green: #4caf7d;
  --blue: #5a8fd0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  text-align: center;
  padding: 2rem 1rem 1rem;
}

#gh-links {
  position: fixed;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.gh-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.gh-btn:hover {
  background: var(--panel);
  border-color: var(--accent);
  transform: translateY(-1px);
}
.gh-btn svg {
  width: 16px;
  height: 16px;
  fill: var(--accent);
}
/* Interface-language picker (flag button + dropdown), left of the GitHub
   buttons. Flag emoji fall back to the country letters on platforms that do
   not draw them (Windows), so the language code is always shown too. */
#ui-lang {
  position: relative;
}
#ui-lang-btn {
  font-family: inherit;
  cursor: pointer;
}
#ui-lang .flag {
  font-size: 1.05rem;
  line-height: 1;
}
#ui-lang-menu {
  /* right-anchored: the nav sits against the right edge of the window, so a
     left-anchored menu would overflow it on narrow screens */
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  min-width: 10.5rem;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
#ui-lang-menu li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  border-radius: 0.4rem;
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
}
#ui-lang-menu li:hover {
  background: var(--panel);
}
#ui-lang-menu li.current {
  color: var(--accent);
  font-weight: 600;
}

@media (max-width: 560px) {
  .gh-btn span { display: none; }
  .gh-btn { padding: 0.45rem; }
  /* the flag is the button's only content: keep it visible */
  #ui-lang-btn .flag { display: inline; }
}

header h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 0.02em;
}

.subtitle {
  color: var(--muted);
  margin: 0.4rem 0 0;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

/* The last panel's bottom margin would add to the footer's own padding:
   drop it so the gap above the footer matches the one under the header. */
main > :last-child {
  margin-bottom: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem 1.4rem;
  margin-bottom: 1.5rem;
}

.control-row {
  margin-bottom: 1rem;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-row.inline {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.hint {
  font-weight: normal;
  opacity: 0.8;
}

input[type="url"],
select,
textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.8rem;
  font-size: 0.95rem;
  font-family: inherit;
}

input[type="url"] {
  width: 100%;
}

textarea {
  width: 100%;
  resize: vertical;
  margin-top: 0.5rem;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

details {
  margin-bottom: 1rem;
}

summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
}

button.primary {
  background: var(--accent);
  color: #1a1508;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

button.primary:hover {
  background: var(--accent-dark);
}

button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary.big {
  padding: 0.8rem 2.2rem;
  font-size: 1.1rem;
}

.status {
  margin-top: 1rem;
}

.status-text {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.status-text.error {
  color: var(--danger);
}

.progress-track {
  height: 6px;
  background: var(--panel-2);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s;
}

.hidden {
  display: none !important;
}

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

.deck-header h2 {
  margin: 0;
}

.deck-stats {
  color: var(--muted);
  font-size: 0.9rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 1rem;
}

.card-tile {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.card-tile img {
  width: 100%;
  border-radius: 6px;
  display: block;
}

.card-tile.wide {
  grid-column: span 2;
}

.card-tile.wide img {
  width: 89%;
  margin: 0 auto;
}

.img-wrap {
  position: relative;
}

/* Right-side control stack (version badge, HD badge, flip button), below the
   title bar so the mana cost stays visible. A hidden HD badge collapses out. */
.card-badges {
  position: absolute;
  top: 2.3rem;
  right: 0.55rem;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
}

/* keep the stack on the (narrower, landscape) card */
.card-tile.wide .card-badges {
  top: 2.5rem;
  right: calc(5.5% + 0.55rem);
}

.flip-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(20, 22, 29, 0.75);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.55);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.flip-btn:hover {
  background: var(--accent);
  color: #1a1508;
}

.flip-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.card-name {
  font-size: 0.8rem;
  text-align: center;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.qty-btn,
.remove-btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.qty-btn:hover {
  background: var(--border);
}

.remove-btn {
  color: var(--danger);
  border-color: var(--danger);
  margin-left: 0.4rem;
}

.remove-btn:hover {
  background: var(--danger);
  color: white;
}

.qty-display {
  min-width: 2.2rem;
  text-align: center;
  font-weight: 600;
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  min-width: 34px;
  /* same width as the flip button below it in the stack */
  text-align: center;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.75);
  color: #fff;
}

.legend .badge {
  position: static;
  flex: none;
  /* wide enough for the two-letter badges, so every explanation starts on
     the same column */
  min-width: 2.3rem;
}

.badge-click {
  cursor: pointer;
}

.badge-click:hover {
  outline: 2px solid rgba(255, 255, 255, 0.6);
}

.badge-localized {
  background: var(--green);
}

.badge-overlay {
  background: var(--blue);
}

.badge-mt {
  background: #d08030;
}

.badge-english {
  background: #8a8fa3;
}

/* resolution badge (HD/LR) sits under the version badge in the stack */
.badge-res {
  background: #7a5ad0;
}

.add-tile {
  border-style: dashed;
  align-items: center;
  justify-content: center;
  min-height: 240px;
}

.add-plus {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 3.5rem;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.add-plus:hover {
  color: var(--accent);
}

.add-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.add-form input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
}

.add-form button {
  padding: 0.45rem;
  font-size: 0.85rem;
}

.add-row {
  display: flex;
  gap: 0.5rem;
}

.add-form .add-qty {
  width: 4.5rem;
  flex: none;
}

.add-row button {
  flex: 1;
}

.print-select {
  width: 100%;
  font-size: 0.72rem;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.section-label {
  grid-column: 1 / -1;
  color: var(--accent);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
  margin-top: 0.5rem;
}

.generate-row {
  text-align: center;
  margin: 2rem 0;
}

.legend ul {
  margin: 0.5rem 0 0;
  padding-left: 0;
  list-style: none;
}

.legend li {
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

/* Badge column: every badge takes the same width so the explanations line
   up, and a wrapped explanation stays inside its own column. */
.legend ul.badge-list li {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
}

.legend ul.notes {
  padding-left: 1.15rem;
  list-style: disc;
}

.legend h3 {
  margin: 0;
  font-size: 1rem;
}

/* A little air before the second heading. It collapses with the last item's
   own 0.4rem, so the page only grows by the difference. */
.legend ul+h3 {
  margin-top: 0.9rem;
}

#retry-btn {
  margin-top: 0.8rem;
}

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem 2rem;
  max-width: 420px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

dialog h3 {
  margin-top: 0;
  padding-right: 1.5rem;
  /* room for the close cross */
}

/* Dismiss cross, top-right of every dialog (Escape does the same thing) */
.dialog-close-form {
  margin: 0;
}

.dialog-close {
  position: absolute;
  top: 0.5rem;
  right: 0.6rem;
  padding: 0.1rem 0.35rem;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.dialog-close:hover {
  background: var(--panel-2);
  color: var(--text);
}

.dialog-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.2rem;
}

button.primary.secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}

button.primary.secondary:hover {
  background: var(--border);
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 1rem 1rem 1.5rem;
  max-width: 800px;
  margin: 0 auto;
}

footer a {
  color: var(--accent);
}

.legend-note {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.6rem 0 0;
}


#version-wrap {
  flex: 1 1 240px;
  min-width: 220px;
}

#preferred-version {
  width: 100%;
}

#edit-dialog {
  width: min(560px, 92vw);
  max-width: 560px;
}

#edit-fields fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0 0 0.8rem;
  padding: 0.4rem 0.8rem 0.8rem;
}

#edit-fields legend {
  color: var(--accent);
  font-size: 0.85rem;
  padding: 0 0.4rem;
}

#edit-fields label {
  margin-top: 0.5rem;
}

#edit-fields input,
#edit-fields textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
  font-family: inherit;
  margin-top: 0.2rem;
  resize: vertical;
}