:root {
  color-scheme: dark;
  --bg: #0c0f16;
  --surface: #151b2c;
  --surface-strong: #1f2844;
  --text: #e5ecff;
  --muted: #9badc9;
  --accent: #8dbdff;
  --border: rgba(255,255,255,.08);
  --shadow: 0 14px 45px rgba(0,0,0,.35);
  --min-selection-item-size: 1cm;
  --max-selection-item-size: 1.25cm;
  --mobile-bottom-offset: 0;
  font-family: Inter, system-ui, sans-serif;
}

.page { max-width: 1400px; margin: auto; }

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top, #15223d 0%, #090b14 55%); color: var(--text); }
header { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 1em; }
h1 { font-size: clamp(2.4rem, 2.2vw, 3.4rem); margin:0; letter-spacing: -0.04em; }
p.lead { margin: 0; color: var(--muted); max-width: 760px; line-height: 1.7; }

#content { margin-top: 2em; display: flex; flex-wrap: wrap; gap: 2em; justify-content: center; align-items: stretch; padding-bottom: 8px; }
#pipBtn { position: relative; top:0px; right: 0px; }
.section { margin-bottom: 0; display: flex; flex-direction: column; }
.global-selection-box { margin: 0em 1em 0em 1em; max-height: calc(50% - (var(--mobile-bottom-offset) / 2.0)); overflow-y: auto; position: sticky; top: 0; z-index: 50; width: 100%; padding: 16px; background: var(--bg); border: 1px dashed rgba(255,255,255,.14); border-radius: 16px; flex: 0 0 auto; min-width: 250px; max-width: calc(100% - 2em); }
.global-selection-box.overlay-active { border-color: #ff0000ff; }
.global-selection-box .overlay-description { display: none; }
.global-selection-box.overlay-active .overlay-description { display: block; color: var(--text); font-size: 0.75rem; margin-top: 8px; }
.global-selection-box div.overlay-indicator { display: none; }
.global-selection-box.overlay-active div.overlay-indicator { bottom: 6px; right: 10px; position: absolute; display: inline-block; color: #ff0000ff; font-size: 1.5em; font-style: bold; animation-name: overlay-indicator-pulse; animation-duration: 1.5s; animation-iteration-count: infinite; }
@keyframes overlay-indicator-pulse {
  0% { transform: translate(0, 0); }
  50% { transform: translate(-10px, -10px);}
  100% { transform: translate(0, 0);}
}
.global-selection-box.modal-open { position: fixed; top: 0; width: -webkit-fill-available; }
.global-selection-box h2 { margin: 0 0 12px; font-size: 1rem; color: var(--accent); }
.global-selection-box .selection-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--min-selection-item-size), var(--max-selection-item-size))); gap: 5px; align-items: start; }
.global-selection-box .selection-items.hidden { display: none; }
.selection-box .selection-items { display: grid; grid-template-columns: repeat(5, minmax(var(--min-selection-item-size), var(--max-selection-item-size))); gap: 5px; align-items: start; }
.global-selection-box .selection-empty { margin: 0; color: var(--muted); font-size: .9rem; text-align: center; padding: 20px 0; }
.section h2 { margin: 0 0 18px; font-size: 1.2rem; letter-spacing: .02em; color: var(--accent); }
.section-header { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: 14px; }
.section-header h2 { margin: 0; font-size: 1rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.section-body { display: block; }
.grid { display: grid; margin-bottom: 1em; gap: 10px; grid-template-columns: repeat(5, minmax(var(--min-selection-item-size), var(--max-selection-item-size))); justify-content: center; }
.item-card { position: relative; border: none; border-radius: 0; padding: 0; background: transparent; transition: transform .18s ease; cursor: pointer; }
.item-card:hover { transform: translateY(-3px); }
.item-card img { width: 100%; height: 100%; display: block; border-radius: 0; background: transparent; object-fit: contain; }
.item-card-badge { position: absolute; left: 0px; top: 0px; width: 18px; height: 18px; padding: 2px; border-radius: 6px; background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.16); display: grid; place-items: center; }
.item-card-badge img { width: 100%; height: 100%; object-fit: contain; display: block; }

.search-section { margin: 0em 1em 0em 1em; padding: 16px; background: var(--bg); border: 1px dashed rgba(255,255,255,.14); border-radius: 16px; flex: 1 1 33%; min-width: 250px; }
.search-controls { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; padding: 8px 12px; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; background: rgba(255,255,255,.05); color: var(--text); font-size: 1rem; }
.search-input:focus { outline: none; border-color: var(--accent); }
.clear-selection-button { padding: 8px 14px; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; background: rgba(255,255,255,.05); color: var(--text); font-size: 0.9rem; cursor: pointer; }
.clear-selection-button:hover { border-color: var(--accent); background: rgba(255,255,255,.08); }
.tag-filter { display: flex; flex-direction: column; gap: 4px; }
.expansion-filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; margin-top: 16px; }
.expansion-label { color: var(--muted); font-size: 0.9rem; }
.expansion-option { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 0.9rem; cursor: pointer; }
.expansion-option input { width: 16px; height: 16px; accent-color: var(--accent); }
.expansion-option img { width: 16px; height: 16px; object-fit: contain; }
.tag-dropdown { position: relative; width: 220px; }
.tag-dropdown-button { width: 100%; padding: 8px 12px; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; background: rgba(255,255,255,.05); color: var(--text); font-size: 0.9rem; text-align: left; cursor: pointer; }
.tag-dropdown-button:hover { border-color: var(--accent); }
.tag-dropdown-menu { position: absolute; top: calc(100% + 6px); left: 0; width: 100%; border: 1px solid rgba(255,255,255,.18); border-radius: 14px; background: var(--surface); box-shadow: 0 18px 40px rgba(0,0,0,.3); max-height: 240px; overflow-y: auto; z-index: 100; display: none; }
.tag-dropdown-menu.open { display: block; }
.tag-dropdown-item { display: flex; align-items: center; gap: 8px; padding: 9px 12px; color: var(--text); cursor: pointer; white-space: nowrap; }
.tag-dropdown-item:hover { background: rgba(255,255,255,.06); }
.tag-dropdown-item.selected .tag-label { color: var(--accent); }
.tag-dropdown-item .tag-prefix { width: 18px; text-align: center; color: var(--accent); }

.selection-box { width: 100%; min-height: 120px; margin-top: auto; padding: 12px; border: 1px dashed rgba(255,255,255,.14); border-radius: 16px; background: rgba(255,255,255,.02); }
.selection-box.collapsed { display: none; }
.selection-empty { display: none; color: var(--muted); font-size: .9rem; text-align: center; padding: 28px 0; }
.selection-items { display: grid; min-height: var(--selection-item-size); grid-template-columns: repeat(5, minmax(var(--selection-item-size), 1fr)); gap: 0; align-items: start; }
.selection-items.hidden { display: none; }
.selection-item { position: relative; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.selection-item img { width: 100%; height: 100%; object-fit: contain; }
.selection-count { z-index: 1;position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; border-radius: 999px; background: var(--accent); color: #081023; font-size: .75rem; font-weight: 700; display: grid; place-items: center; padding: 0 5px; }

.tooltip { position: fixed; z-index: 100; pointer-events: none; max-width: 320px; padding: 16px; border-radius: 18px; background: rgba(14,19,35,.96); border: 1px solid rgba(255,255,255,.09); box-shadow: var(--shadow); color: var(--text); font-size: .95rem; line-height: 1.6; opacity: 0; transform: translateY(8px); transition: opacity .16s ease, transform .16s ease; }
.tooltip.visible { opacity: 1; transform: translateY(0); }
.tooltip h3 { margin: 0 0 10px; font-size: 1rem; }
.tooltip .description { color: #d9e3ff; }
.tooltip .recipe-title { margin: 12px 0 6px; font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.tooltip-recipe { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.tooltip-recipe-group { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 8px; border-radius: 14px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08); }
.tooltip-recipe-icon { width: 32px; height: 32px; border-radius: 10px; overflow: hidden; background: rgba(255,255,255,.06); }
.tooltip-recipe-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tooltip-recipe-operator { font-size: .95rem; color: var(--muted); flex-shrink: 0; }
.bubble { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .82rem; font-weight: 600; margin: 0 2px 2px 0; }
.bubble--offense { background: #ffbb76; color: #1b1120; }
.bubble--defense { background: #8ceaa6; color: #072312; }
.bubble--misc { background: #8dbdff; color: #04192f; }
.bubble--debuff { background: #ff7aad; color: #2a0911; }
.bubble--extra { background: rgba(255,255,255,.08); color: #dfe6ff; }

.dim { filter: brightness(33%); }
#modal { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; display: flex; align-items: end; justify-content: center; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 11; }
#modal.visible { opacity: 1; pointer-events: auto; }
#modal .modal-content { position: relative; max-width: 90vw; max-height: calc(50% - (var(--mobile-bottom-offset) / 2.0)); margin-bottom: var(--mobile-bottom-offset); overflow: auto; background: var(--surface); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); z-index: 101; display: flex; flex-direction: column; }
#modal .modal-header { display: flex; flex-direction: row; gap: 10px; align-items: center; max-height: 3em; max-width: 90%; }
#modal .modal-header img { max-height: 3em; }
#modal .modal-body { overflow-y: auto; min-height: 10%; max-height: 33%; }
#modal .modal-close-button { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border: none; border-radius: 50%; background: rgba(255,255,255,.1); color: var(--text); cursor: pointer; align-items: center; justify-content: center; }
#modal .modal-small-button { display: inline-block; width: 2.5em; height: 2.5em; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; background: rgba(255,255,255,.1); color: var(--text); cursor: pointer; align-items: center; justify-content: center; }
#modal .modal-red-button { min-width: 2.5em; height: 2.5em; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; background: rgba(255,0,0,.5); color: var(--text); cursor: pointer; justify-content: center; }
#modal .modal-button { min-width: 2.5em; height: 2.5em; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; background: rgba(255,255,255,.1); color: var(--text); cursor: pointer; align-items: center; justify-content: center; }
#modal .modal-quantity-input { display: inline-block; width: 30%; padding: 6px 8px; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; background: rgba(255,255,255,.05); color: var(--text); font-size: 1rem; text-align: center; }
#modal .modal-footer {  
  padding-top: 1em;
  display: flex;
  flex-direction: column;

  flex-shrink: 0; /* NEVER shrink */
}
#modal .modal-footer .row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}
#modal .modal-footer .row:last-of-type {
  justify-content: space-between;
}
#modal div .row { margin-bottom: 0.5em; }

.pip-container { position: fixed; bottom: 10px; right: 10px; z-index: 20; border: 1px dashed rgba(255,255,255,.14); background: var(--bg); text-align: right; display: flex; flex-direction: column; max-width: 20vw; max-height: 20vh; }
.pip-container.overlay-active { border-color: #ff0000ff;}
.pip-container button { flex: 0 0 auto; }
.pip-container video { flex: 1 1 auto; min-height: 4em; }
.pip-container div { flex: 0 0 auto; padding: 8px; font-size: 0.75em; background: var(--bg); }
footer { font-size: 0.75em; text-align: center; margin: 3em; color: #ccc;}

@media (max-width: 720px) {
    :root { 
      --min-selection-item-size: 1cm; 
      --max-selection-item-size: 1.25cm;
      --mobile-bottom-offset: 3.5em;
    }
    .page { margin: 0; }
    .selection-box { display: none; }
    .expansion-filters { flex-direction: column; }
    .global-selection-box { margin: 0; max-width: 100%; }
    .search-section { margin: 0; }
}
@media (hover) {
  .desktop-only { display: block; }
  .mobile-only { display: none; }
  .global-selection-box { resize: horizontal; overflow: auto; }
}
@media (not (hover)) {
  .desktop-only { display: none; }
  .mobile-only { display: block; }
}
@media (orientation: portrait) and (max-width: 450px) {
  .pip-container { display: none; }
}
@media (orientation: landscape) and (max-height: 450px) {
  .pip-container { display: none; }
}