:root {
  color-scheme: light;
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --line: #d6dde6;
  --line-strong: #aeb9c7;
  --text: #172033;
  --muted: #657186;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --blue: #2563eb;
  --danger: #b42318;
  --owned: #e7f7ef;
  --missing: #f2f4f7;
  --shadow: 0 18px 42px rgba(19, 32, 51, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.save-status {
  min-width: 92px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.save-status.is-saving {
  color: var(--blue);
}

.save-status.is-error {
  color: var(--danger);
  border-color: #f3b3ad;
  background: #fff1f0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.side-panel,
.content-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.side-panel {
  align-self: start;
  max-height: calc(100vh - 104px);
  overflow: auto;
}

.panel-section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.panel-section h2,
.card-toolbar h2 {
  margin: 0 0 10px;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.text-button,
.collection-button,
.rarity-button,
.holo-button,
.card-tile {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
}

.text-button {
  min-height: 36px;
  padding: 7px 9px;
  border-radius: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-button.is-active,
.collection-button.is-active,
.rarity-button.is-active,
.holo-button.is-active {
  border-color: var(--accent);
  background: #ecfdf8;
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.text-button.is-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.rarity-filter {
  display: grid;
  grid-template-columns: 48px 1fr 1fr;
  gap: 6px;
  align-items: stretch;
}

.rarity-button,
.holo-button {
  min-height: 34px;
  border-radius: 6px;
}

.rarity-button img {
  display: block;
  max-width: 32px;
  max-height: 22px;
  margin: 0 auto;
}

.rarity-all {
  grid-column: 1 / -1;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading strong {
  min-width: 44px;
  padding: 4px 8px;
  border-radius: 6px;
  background: #172033;
  color: #fff;
  text-align: center;
}

.summary-list,
.probability-list {
  display: grid;
  gap: 4px;
}

.summary-row,
.probability-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 4px 0;
  border-bottom: 1px solid #edf0f4;
  font-size: 13px;
}

.summary-row span,
.probability-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-row strong,
.probability-row strong {
  font-variant-numeric: tabular-nums;
}

.probability-row.is-best {
  margin: 2px -6px;
  padding: 6px;
  border-bottom: 0;
  border-radius: 6px;
  background: #fff4cc;
  color: #7a3f00;
  box-shadow: inset 0 0 0 1px #f59e0b;
}


.content-panel {
  min-width: 0;
  padding: 14px;
}

.collection-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.collection-button {
  display: grid;
  place-items: center;
  min-height: 72px;
  padding: 6px;
  border-radius: 6px;
}

.collection-button img {
  display: block;
  width: 100%;
  max-width: 180px;
  height: auto;
}

.card-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 2px 0 12px;
}

.card-toolbar h2 {
  margin-bottom: 2px;
}

#page-info {
  color: var(--muted);
  font-size: 13px;
}

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

.card-tile {
  position: relative;
  display: grid;
  justify-items: center;
  min-height: 198px;
  padding: 0 0 8px;
  border-radius: 8px;
  overflow: hidden;
}

.card-tile.is-owned {
  background: var(--owned);
  border-color: #a7dbc3;
}

.card-tile.is-missing {
  background: var(--missing);
}

.card-image,
.card-back {
  width: 122px;
  height: 168px;
  object-fit: contain;
}

.card-back {
  display: grid;
  grid-template-rows: 36px 1fr 28px 24px;
  justify-items: center;
  align-items: center;
  padding: 8px 8px 4px;
  background-size: cover;
  background-position: center;
  color: #697386;
  text-align: center;
}

.card-back .card-name {
  max-width: 108px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.12;
}

.card-back .card-number {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
}

.card-back .rarity-img {
  max-width: 68px;
  max-height: 22px;
  object-fit: contain;
}

.card-back .pack-img {
  max-width: 72px;
  max-height: 22px;
  object-fit: contain;
}

.card-caption {
  width: 100%;
  padding: 5px 6px 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  min-height: 160px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-backdrop.is-hidden {
  display: none;
}

.login-dialog {
  width: min(360px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-dialog h2 {
  margin: 0 0 12px;
  font-size: 17px;
  letter-spacing: 0;
}

.login-dialog input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font: inherit;
}

.login-error {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-panel {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    padding: 10px;
  }

  .button-grid {
    grid-template-columns: 1fr;
  }

  .collection-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 8px;
  }
}
