*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { touch-action: manipulation; }
button { user-select: none; }
img { -webkit-touch-callout: none; user-select: none; }

@media (max-width: 767px) {
  input[type="text"], input[type="search"], textarea { font-size: 16px !important; min-width: 0; }
  button:not(.filter-ink-btn) { min-height: 36px; }
}

:root {
  /* ---- Surfaces ---- */
  /* --border is darker than --border2: used as an elevated/inset surface;
     --border2 is the lighter tone used for actual 1px borders. */
  --bg:       #1a1a2e;
  --surface:  #16213e;
  --border:   #0f3460;
  --border2:  #1a4a7a;

  /* ---- Brand / accent ---- */
  --accent:   #e94560;
  --accent2:  #c73650;  /* hover state of --accent; also opponent phase */
  --blue:     #4090ff;

  /* ---- Text ---- */
  --text:     #e0e0e0;
  --text-mid: #a0a0c0;
  --text-dim: #7a8fa8;

  /* ---- Shape / motion ---- */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --transition: 0.15s ease;
  /* Common interactive state transition (buttons / links / bordered boxes) */
  --trans-interactive: background var(--transition), color var(--transition), border-color var(--transition);

  /* ---- Overlay backdrops ---- */
  --overlay-bg:      rgb(0 0 0 / 0.6);
  --overlay-bg-soft: rgb(0 0 0 / 0.5);
  --overlay-bg-deep: rgb(0 0 0 / 0.85);

  /* ---- Modal / floating shadows ---- */
  --shadow-modal: 0 12px 40px rgb(0 0 0 / 0.5);
  --shadow-card:  0 4px 12px rgb(0 0 0 / 0.5);

  /* ---- Inkwell indicator ---- */
  --inkable: #40c080;

  /* ---- Ink colors ---- */
  --ink-amber:    #ffc040;
  --ink-amethyst: #c080ff;
  --ink-emerald:  #40d090;
  --ink-ruby:     #ff6070;
  --ink-sapphire: var(--blue);
  --ink-steel:    #90a0b0;

  /* ---- Rarity colors ---- */
  --rarity-common:     #aaa;
  --rarity-uncommon:   #60c0ff;
  --rarity-rare:       #ffd060;
  --rarity-super-rare: #ff9040;
  --rarity-legendary:  #d080ff;
  --rarity-enchanted:  #80ffcc;
  --rarity-epic:       #ffb830;
  --rarity-iconic:     #40d8d0;
  --rarity-promo:      #ff80c0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  /* Shared viewport margin so every page (index/deck/deck-edit/solo/lore)
     clears notch/home indicator/mobile browser chrome. box-sizing keeps
     `height: 100vh` pages exact. */
  padding: max(12px, env(safe-area-inset-top))
           max(12px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom))
           max(12px, env(safe-area-inset-left));
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* Round elements: let outline follow the circle. */
.filter-ink-btn:focus-visible,
.card-modal-btn:focus-visible,
.solo-lore-btn:focus-visible { outline-offset: 3px; }

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1rem; color: var(--accent); }
header h1 a { color: inherit; text-decoration: none; }
header .spacer { flex: 1; }

/* ---- Breadcrumb ---- */
.breadcrumb-sep {
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 0.8rem;
  user-select: none;
}
.breadcrumb-current {
  color: var(--text-mid);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breadcrumb-link {
  flex-shrink: 0;
  padding: 0;
  background: none;
  border: none;
  color: var(--text-mid);
  font-size: 0.9rem;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--transition);
}
.breadcrumb-link:hover { color: var(--text); }

/* ---- Buttons ---- */
.btn {
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
  transition: var(--trans-interactive);
}
.btn-primary       { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-mid);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--text); }
.btn-outline-danger {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}
.btn-outline-danger:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ---- Shared modal primitives ----
   Concrete overlays (.confirm-overlay / .import-overlay / .lore-overlay /
   .solo-overlay) keep their own z-index, backdrop color, padding, and
   backdrop-filter. The positioning + toggle behavior is unified here. */
.confirm-overlay,
.import-overlay,
.lore-overlay,
.solo-overlay {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
}
.confirm-overlay.active,
.import-overlay.active,
.lore-overlay.active,
.solo-overlay.active { display: flex; }

/* Dialog surface. Each concrete dialog still controls its own padding,
   width, layout, animation timing, and shadow. */
.confirm-dialog,
.import-dialog,
.lore-dialog,
.solo-dialog {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
}

@keyframes dialog-in {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}
