/* Clash of Clans asset viewer — plain CSS, no external requests.
 * Light/dark via prefers-color-scheme; AA contrast; visible focus. */

:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1c1c1e;
  --muted: #55555c;
  --line: #d9d9d4;
  --accent: #2f6fb2;
  --accent-text: #ffffff;
  --card-bg: #ffffff;
  --badge-bg: #e8e8e4;
  --badge-text: #3c3c42;
  --removed: #8a4a4a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  --overlay: rgba(20, 20, 22, 0.55);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --panel: #1e1e22;
    --text: #e8e8ea;
    --muted: #a2a2ab;
    --line: #34343a;
    --accent: #6ba3e0;
    --accent-text: #10131a;
    --card-bg: #1e1e22;
    --badge-bg: #2a2a30;
    --badge-text: #c9c9d1;
    --removed: #d09a9a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    --overlay: rgba(0, 0, 0, 0.65);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  overflow-x: clip;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- top bar ------------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

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

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  flex: 1;
}

.search {
  flex: 1 1 200px;
  max-width: 340px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.filter select,
.filter input[type="checkbox"] {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  max-width: 180px;
}

.filter input[type="checkbox"] {
  padding: 0;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.clear {
  font: inherit;
  font-size: 13px;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}

.status {
  flex-basis: 100%;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* --- grid ---------------------------------------------------------------------- */

main {
  flex: 1;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px;
}

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

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card:hover {
  border-color: var(--accent);
}

.card img {
  width: 100%;
  height: auto;
  max-width: 100%;
  border-radius: 4px;
  background: var(--badge-bg);
  object-fit: contain;
}

.card-name {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  position: absolute;
  top: 12px;
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-text);
  border: 1px solid var(--line);
}

.badge-m {
  left: 12px;
}

.badge-an {
  left: 62px;
}

.badge-s {
  left: 12px;
  color: var(--removed);
}

.badge-s + .badge-m {
  left: 78px;
}

.badge-s + .badge-an {
  left: 78px;
}

.badge-s + .badge-an + .badge-m {
  left: 128px;
}

.sentinel {
  height: 1px;
}

/* --- footer --------------------------------------------------------------------- */

.footer {
  padding: 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-size: 13px;
  color: var(--muted);
}

.footer p {
  margin: 4px 0;
}

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

.noscript {
  padding: 16px;
  font-size: 16px;
}

/* --- dialog ---------------------------------------------------------------------- */

.dialog {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--overlay);
}

.dialog[hidden] {
  display: none;
}

.dialog-panel {
  position: relative;
  width: 100%;
  max-width: 960px;
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.dialog-title {
  margin: 0 40px 2px 0;
  font-size: 20px;
}

.dialog-sub {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.dialog-body {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.dialog-image {
  flex: 1 1 320px;
  min-width: 240px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.dialog-img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  background: var(--badge-bg);
}

.dialog-side {
  flex: 1 1 300px;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.levels,
.others {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.lvl {
  min-width: 34px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.lvl:hover {
  border-color: var(--accent);
}

.lvl.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.meta {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  font-size: 13px;
}

.meta dt {
  color: var(--muted);
}

.meta dd {
  margin: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.meta dd.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  font: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  display: inline-block;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn[disabled] {
  opacity: 0.55;
  cursor: default;
}

/* --- responsive ------------------------------------------------------------------- */

@media (max-width: 640px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
  }

  main {
    padding: 10px;
  }

  .topbar {
    padding: 8px 10px;
  }

  .dialog-panel {
    padding: 14px;
  }
}

/* --- reduced motion ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
