*{box-sizing:border-box}
:root{
  --bg:#242222;
  --panel:#171817;
  --panel2:#1f201e;
  --border:#090909;
  --text:#eeeeee;
  --muted:#a9a9a9;
  --blue:#4166a8;
  --green:#3f7a50;
}
html,body{margin:0;min-height:100%;background:var(--bg);color:var(--text);font-family:Arial,Helvetica,sans-serif}
body{padding:28px 0 50px}
button{border:0;border-radius:6px;background:var(--blue);color:#fff;padding:10px 14px;font-size:14px;cursor:pointer}
button:hover{filter:brightness(1.1)}
button:disabled{opacity:.45;cursor:not-allowed}
button.primary{background:var(--green)}
button.danger{background:#873c3c}
.app-shell{width:min(1500px,94vw);margin:auto}
.topbar{display:flex;align-items:center;justify-content:space-between;gap:20px;margin-bottom:18px}
.topbar h1{margin:0;font-size:28px}.topbar p{margin:5px 0 0;color:var(--muted)}
.toolbar{display:flex;gap:7px;flex-wrap:wrap;justify-content:flex-end}
.rank-sheet{background:var(--panel);border:1px solid var(--border)}
.sheet-title{display:none;text-align:center;padding:30px 20px 22px;background:#171817}
.sheet-title h1{margin:0;font-size:38px;letter-spacing:2px}.sheet-title p{margin:8px 0 0;color:#aaa;font-size:17px}
.tier-row{display:grid;grid-template-columns:120px 1fr;min-height:122px;border-bottom:1px solid var(--border)}
.tier-row:last-child{border-bottom:0}
.tier-label{display:flex;align-items:center;justify-content:center;color:#222;font-size:22px;font-weight:500;user-select:none}
.tier-zone{min-height:122px;padding:8px;display:flex;flex-wrap:wrap;align-content:flex-start;align-items:flex-start;gap:5px;background:#171817;position:relative}
.tier-zone.drag-over,.image-pool.drag-over{outline:2px dashed #fff;outline-offset:-3px}
.character-card{width:84px;height:104px;position:relative;flex:0 0 auto;cursor:grab;background:#292929;border:1px solid #0a0a0a;overflow:hidden;user-select:none}
.character-card:active{cursor:grabbing}
.character-card img{width:100%;height:100%;display:block;object-fit:cover}
.card-badge{position:absolute;z-index:3;top:4px;left:4px;padding:2px 6px;border-radius:3px;background:#000c;color:#fff;font-size:11px;line-height:16px}
.character-card.dragging{opacity:.35}
.insertion-marker{width:4px;height:104px;background:#fff;flex:0 0 4px;border-radius:2px;pointer-events:none;box-shadow:0 0 8px #fff}
.pool-section{margin-top:28px}.pool-heading{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px}
.pool-heading h2{margin:0;font-size:20px}.pool-heading p{margin:5px 0 0;color:var(--muted)}
.pool-count{background:#333;border:1px solid #444;padding:5px 9px;border-radius:5px;color:#ccc;font-size:12px}
.image-pool{
  height:220px;
  min-height:220px;
  padding:8px;
  display:flex;
  flex-wrap:wrap;
  align-content:flex-start;
  align-items:flex-start;
  gap:5px;
  background:var(--panel);
  border:1px solid #111;
  overflow-y:auto;
  overflow-x:hidden;
}
.image-pool .character-card{width:75px;height:94px}
.image-pool .card-badge{font-size:10px;line-height:14px;padding:1px 5px}
.image-pool::-webkit-scrollbar{width:10px}
.image-pool::-webkit-scrollbar-track{background:#101110}
.image-pool::-webkit-scrollbar-thumb{background:#555;border-radius:6px}
.image-pool::-webkit-scrollbar-thumb:hover{background:#707070}
.modal{width:min(650px,92vw);background:#202120;color:#fff;border:1px solid #444;border-radius:10px;padding:20px}
dialog{border:0;background:transparent;padding:0}
dialog::backdrop{background:#000b}
.modal-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:16px}
.modal-header h2{margin:0}.close-btn{background:transparent;font-size:25px;padding:2px 8px}
.edit-row{display:grid;grid-template-columns:1fr 82px 42px;gap:8px;margin:8px 0}
.edit-row input{width:100%;height:38px;background:#111;color:#fff;border:1px solid #555;border-radius:5px;padding:8px}
.edit-row input[type=color]{padding:2px}.remove-tier{background:#713535;padding:5px}
.modal-actions{display:flex;justify-content:space-between;gap:10px;margin-top:18px}
.modal-note{color:#aaa;margin:0 0 15px}.export-options{display:grid;gap:8px}
.export-option{display:flex;align-items:center;justify-content:space-between;text-align:left;background:#2b2c2a;border:1px solid #444}
.export-option span{color:#aaa;font-size:12px}.export-option.active{border-color:#6d93d8}
.quality-row{display:flex;align-items:center;justify-content:space-between;margin-top:16px;padding:12px;background:#181918;border-radius:6px}
.quality-row select{background:#111;color:#fff;border:1px solid #555;border-radius:5px;padding:7px}
.toast{position:fixed;left:50%;bottom:25px;transform:translateX(-50%) translateY(20px);background:#111e;color:#fff;border:1px solid #444;border-radius:7px;padding:11px 16px;opacity:0;pointer-events:none;transition:.2s;z-index:100}
.toast.show{opacity:1;transform:translateX(-50%) translateY(0)}
.export-only{display:none}

body.presentation .topbar,
body.presentation .pool-section{display:none}
body.presentation{padding:0;background:#171817}
body.presentation .app-shell{width:100%;max-width:none}
body.presentation .rank-sheet{border:0;min-height:100vh}
body.presentation .sheet-title{display:block}
body.presentation .tier-row{grid-template-columns:130px 1fr;min-height:calc((100vh - 130px)/5)}
body.presentation .tier-zone{min-height:0}
body.presentation .character-card{width:92px;height:114px}

@media(max-width:800px){
  .topbar{flex-direction:column;align-items:flex-start}
  .toolbar{justify-content:flex-start}
  .tier-row{grid-template-columns:78px 1fr}
  .character-card{width:66px;height:82px}
  .image-pool .character-card{width:66px;height:82px}
  .insertion-marker{height:82px}
}

@media print{
  body{background:#fff;padding:0}
  body *{visibility:hidden}
  body.presentation #rankSheet,
  body.presentation #rankSheet *{visibility:visible}
  body.presentation #rankSheet{position:absolute;left:0;top:0;width:100%;border:0}
  body.presentation .sheet-title{display:block}
  body.presentation .tier-row{break-inside:avoid}
}

/* Performance: isolate the large scrollable image pools from the rest of the page. */
.image-pool{contain:layout paint}
.character-card{contain:layout paint}
.character-card img{content-visibility:auto}
