/* ============================================================================
 * ARPG-style Character Select / Create screen (web/src/ui/charselect.js)
 * Sprites: assets/ui/fe_*.webp (hd/global/ui/frontend, 0.5x of 4K); positions from
 * characterselectpanelhd.json (x0.5). Everything scales by screen height via --cs-scale.
 * ============================================================================ */

#charselect {
  position: fixed;
  inset: 0;
  z-index: 95;
  pointer-events: none;
  color: #d8c8a2;
  font: 14px/1.35 var(--font-ui);
  --cs-scale: 1;
  --cs-panel-w: 0px;
  user-select: none;
}
#charselect[hidden] { display: none; }
#charselect button,
#charselect input,
#charselect .cs-panel,
#charselect .cs-confirm { pointer-events: auto; }

body.charselect-open > :not(#charselect):not(#game):not(script):not(style) {
  display: none !important;
}
body.charselect-open #game { cursor: default; }
/* Boot-time Realm login: only the login modal of the (otherwise hidden) HUD. */
body.boot-auth #hud > :not(#realm-modal) { display: none !important; }

/* ---- ARPG front-end buttons (4 frames: normal, pressed, disabled, hover) ---- */
.fe-btn {
  position: relative;
  border: 0;
  padding: 0;
  background-color: transparent;
  background-repeat: no-repeat;
  cursor: pointer;
  color: #e9d6a0;
  font: 19px/1 var(--font-title);
  letter-spacing: 1px;
  text-shadow: 0 2px 3px #000;
}
.fe-btn > span { position: relative; top: 1px; }
.fe-btn.med {
  width: 235px;
  height: 59px;
  background-image: url('../../assets/ui/fe_btn_med.webp');
  background-size: 940px 59px;
}
.fe-btn.large {
  width: 304px;
  height: 72px;
  background-image: url('../../assets/ui/fe_btn_large.webp');
  background-size: 1216px 72px;
  font-size: 24px;
}
.fe-btn.med:hover { background-position: -705px 0; color: #fff2c6; }
.fe-btn.large:hover { background-position: -912px 0; color: #fff2c6; }
.fe-btn.med:active { background-position: -235px 0; }
.fe-btn.large:active { background-position: -304px 0; }
.fe-btn.med:disabled { background-position: -470px 0; color: #77705f; cursor: default; }
.fe-btn.large:disabled { background-position: -608px 0; color: #77705f; cursor: default; }

.fe-del {
  width: 46px;
  height: 44px;
  border: 0;
  padding: 0;
  background: url('../../assets/ui/fe_delete.webp') 0 0 / 184px 44px no-repeat;
  cursor: pointer;
}
.fe-del:hover { background-position: -92px 0; }
.fe-del:active { background-position: -46px 0; }
.fe-del:disabled { background-position: -138px 0; cursor: default; }

/* ---- Select view: right stone panel ---- */
.cs-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 402px;
  height: 1080px;
  background: url('../../assets/ui/fe_rightpanel.webp') 0 0 / 402px 1080px no-repeat;
  zoom: var(--cs-scale);
}
.cs-panel-head {
  position: absolute;
  left: 37px;
  top: 40px;
  width: 327px;
  text-align: center;
  font: 20px/1 var(--font-title);
  color: #c7a96a;
  letter-spacing: 2px;
}
.cs-list {
  position: absolute;
  left: 37px;
  top: 74px;
  width: 327px;
  height: 818px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: #6d5733 transparent;
}
.cs-tile {
  position: relative;
  flex: 0 0 92px;
  width: 306px;
  height: 92px;
  border: 0;
  padding: 0;
  text-align: left;
  background: url('../../assets/ui/fe_chartile.webp') 0 0 / 918px 92px no-repeat;
  cursor: pointer;
  color: inherit;
}
.cs-tile:hover { background-position: -306px 0; }
.cs-tile.on { background-position: -612px 0; }
.cs-selector {
  position: absolute;
  inset: 0;
  background: url('../../assets/ui/fe_selector.webp') 0 0 / 306px 92px no-repeat;
  pointer-events: none;
}
.cs-tile-title,
.cs-tile-name,
.cs-tile-lvl {
  position: absolute;
  left: 13px;
  right: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 2px 2px #000;
}
.cs-tile-title { top: 9px; font-size: 13px; color: #a99677; }
.cs-tile-name { top: 31px; font: 23px/1.1 var(--font-title); color: #f3e2b3; letter-spacing: 0.5px; }
.cs-tile-lvl { top: 61px; font-size: 14px; color: #c6b48e; }
.cs-empty { padding: 30px 10px; text-align: center; color: #8f8166; }
.cs-new { position: absolute; left: 83px; top: 908px; }
.cs-del { position: absolute; left: 118px; top: 990px; }

.cs-hero-label {
  position: absolute;
  left: 0;
  top: 0;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 2px 4px #000, 0 0 10px #000;
}
.cs-hl-name { font: calc(30px * var(--cs-scale)) / 1.1 var(--font-title); color: #f6e3ae; letter-spacing: 1px; }
.cs-hl-sub { font-size: calc(17px * var(--cs-scale)); color: #c9b78f; }

.cs-play-row {
  position: absolute;
  bottom: 44px;
  left: calc((100vw - var(--cs-panel-w)) / 2 / var(--cs-scale));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  zoom: var(--cs-scale);
}
.cs-play-row .cs-play {
  position: static;
  transform: none;
  zoom: 1;
}
.cs-play {
  position: absolute;
  bottom: 44px;
  left: calc((100vw - var(--cs-panel-w)) / 2 / var(--cs-scale));
  transform: translateX(-50%);
  zoom: var(--cs-scale);
}
.cs-bottom-left {
  position: absolute;
  left: 28px;
  bottom: 40px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  zoom: var(--cs-scale);
}
.cs-mode-line { font-size: 15px; color: #b9a882; text-shadow: 0 1px 3px #000; }
.cs-mode {
  display: inline-block;
  padding: 1px 7px;
  margin-right: 5px;
  border: 1px solid #6a5636;
  font: 13px/1.3 var(--font-title);
  color: #cbb17a;
}
.cs-mode.on { border-color: #5ca653; color: #b7f5a8; }
.cs-bl-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.cs-bl-btns:empty { display: none; }

.cs-confirm-wrap {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 3, 2, 0.85);
  z-index: 50;
  pointer-events: auto;
}
.cs-confirm {
  width: min(540px, calc(100vw - 32px));
  font-size: 13px;
}
.cs-confirm-title { color: #dfca92; }
.cs-confirm-desc { font-size: 13px; color: #c8bfa8; line-height: 1.45; }
.cs-confirm-btns { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }

/* ---- Create view ---- */
.cs-create-head {
  position: absolute;
  top: 34px;
  left: calc(50vw / var(--cs-scale));
  transform: translateX(-50%);
  width: 900px;
  text-align: center;
  text-shadow: 0 2px 4px #000, 0 0 12px #000;
  zoom: var(--cs-scale);
}
.cs-create-title { font: 30px/1.1 var(--font-title); color: #e8c46f; letter-spacing: 1.5px; }
.cs-class-title { margin-top: 26px; font: 44px/1.1 var(--font-title); color: #f2d27e; letter-spacing: 2px; }
.cs-class-desc { margin-top: 8px; font-size: 19px; color: #d6c7a4; }

.cs-hots { position: absolute; inset: 0; pointer-events: none; }
.cs-class-hot {
  position: absolute;
  left: 0;
  top: 0;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}
.cs-class-tag {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  white-space: nowrap;
  font: calc(17px * max(var(--cs-scale), 0.7)) / 1.2 var(--font-title);
  color: #9d8c6b;
  text-shadow: 0 2px 3px #000;
  opacity: 0;
  transition: opacity 0.15s;
}
.cs-class-hot:hover .cs-class-tag { opacity: 1; color: #e9d7a8; }
.cs-class-hot.on .cs-class-tag { opacity: 1; color: #ffd36e; }
.cs-class-hot.loading .cs-class-tag { opacity: 0.6; }

.cs-name-box {
  position: absolute;
  left: calc(50vw / var(--cs-scale));
  bottom: 40px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  zoom: var(--cs-scale);
}
.cs-name-label { font: 20px/1.2 var(--font-title); color: #e6c56f; margin-bottom: 4px; text-shadow: 0 2px 3px #000; }
.cs-name-row { position: relative; }
.cs-dice {
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translate(8px, -50%);
  width: 46px;
  height: 46px;
  border: 1px solid #6e5836;
  background: linear-gradient(180deg, #2b2116, #120d08);
  color: #e6c875;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}
.cs-dice:hover { border-color: #d6b464; color: #fff1c4; }
.cs-name-entry {
  width: 441px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: url('../../assets/ui/fe_nameentry.webp') 0 0 / 441px 72px no-repeat;
}
.cs-name-entry input {
  width: 340px;
  border: 0;
  outline: 0;
  background: transparent;
  color: #f5e6bd;
  text-align: center;
  font: 26px/1 var(--font-title);
  letter-spacing: 1px;
}
.cs-name-entry input::placeholder { color: #6e6450; font-size: 18px; }
.cs-name-hint { margin-top: 6px; font-size: 13px; color: #8d7f63; text-shadow: 0 1px 2px #000; }
.cs-name-hint.bad { color: #f08a72; }

#charselect[data-view="create"] .cs-back {
  position: absolute;
  left: 40px;
  bottom: 46px;
  zoom: var(--cs-scale);
}
#charselect[data-view="create"] .cs-play {
  left: auto;
  right: 40px;
  bottom: 40px;
  transform: none;
}

@media (max-height: 520px) {
  .cs-class-title { margin-top: 10px; font-size: 36px; }
  .cs-class-desc { font-size: 17px; }
}

/* Difficulty picker: only shown for heroes that have beaten Normal (diffUnlocked > 0) */
.cs-diff { position: absolute; left: calc((100vw - var(--cs-panel-w)) / 2 / var(--cs-scale)); bottom: 118px; transform: translateX(-50%); zoom: var(--cs-scale); display: flex; gap: 6px; z-index: 3; }
.cs-diff-btn { font: inherit; font-size: 15px; padding: 4px 14px; color: #b9a882; background: rgba(0,0,0,.65); border: 1px solid #5b4a2a; cursor: pointer; text-shadow: 0 1px 3px #000; }
.cs-diff-btn.on { color: #ebd086; border-color: #c7a24b; background: rgba(60,40,10,.8); }
.cs-diff-btn:disabled { opacity: .35; cursor: default; }
