:root {
  --bg: #0f1424;
  --bg-2: #161d35;
  --card: #1c2542;
  --card-2: #232e52;
  --line: #2c3866;
  --text: #e8ecff;
  --muted: #8b97c4;
  --accent: #6ea8ff;
  --accent-2: #b07bff;
  --good: #46d39a;
  --danger: #ff6b81;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #1d2747 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 26px;
  background: linear-gradient(90deg, rgba(110,168,255,0.10), rgba(176,123,255,0.10));
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(8px);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { color: var(--muted); font-size: 13px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.reset-info { color: var(--muted); font-size: 12px; margin-right: 6px; }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent); }
.btn-primary { background: linear-gradient(90deg, var(--accent), var(--accent-2)); border: none; color: #0b1020; font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(110,168,255,0.25); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.topbar-left { display: flex; align-items: center; gap: 16px; }

main { max-width: none; margin: 0; padding: 22px 22px 60px; }

.legend { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 18px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.chip {
  background: var(--card-2);
  border: 1px solid var(--line);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text);
}

.party-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin: -4px 0 18px; /* full available width; chips wrap only when they don't fit */
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.party-label { color: var(--muted); font-size: 13px; }
/* one row per player */
.party-chips { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.party-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.party-group-label { min-width: 90px; }
.party-group-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.party-empty { color: var(--muted); font-size: 13px; font-style: italic; }

/* ---------- Party Planner ---------- */
.squad-mini-wrap {
  display: inline-flex; flex-direction: column; align-items: center; gap: 2px;
  width: 40px; flex: 0 0 auto;
}
.squad-mini {
  width: 34px; height: 34px;
  border-radius: 8px; border: 1px solid var(--line);
  background: var(--card-2) center/cover no-repeat;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--accent);
}
.squad-mini-name {
  font-size: 9px; color: var(--muted); line-height: 1.1;
  max-width: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center;
}
.squad-mini-wrap.removable { cursor: pointer; }
.squad-mini-wrap.removable:hover .squad-mini { outline: 2px solid var(--danger); }
.squad-build-list { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; }

#squadName {
  width: 100%;
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  padding: 6px 9px; border-radius: 8px; font-size: 14px; font-weight: 600;
}
#squadName:focus { outline: none; border-color: var(--accent); }

/* board + planner aside layout */
.board-wrap { display: flex; gap: 18px; align-items: flex-start; }
.board-wrap > .board { flex: 1 1 auto; min-width: 0; }
.squad-aside {
  flex: 0 0 220px;
  display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 86px;
}
@media (max-width: 720px) { .board-wrap { flex-wrap: wrap; } .squad-aside { flex-basis: 100%; position: static; } }

/* builder shown as a player-like column */
.squad-col {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--accent); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.squad-col-head { font-size: 15px; font-weight: 600; }
.squad-col-hint { font-size: 11px; color: var(--muted); }
.squad-col-actions { display: flex; gap: 8px; }

.squad-plan-head { font-size: 13px; color: var(--muted); font-weight: 600; }
.squad-list { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.squad-card {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; cursor: pointer;
}
.squad-card:hover { border-color: var(--accent); }
.squad-card.editing { border-color: var(--accent); box-shadow: 0 0 8px rgba(110,168,255,0.35); }
.squad-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.squad-name { font-size: 12px; font-weight: 600; color: var(--muted); }
.squad-minis { display: flex; gap: 5px; flex-wrap: wrap; }
.squad-finish { align-self: stretch; }

/* in planning mode: characters already used in a squad go sepia & inert */
body.planning .char-row.squad-assigned { filter: sepia(0.85) opacity(0.5); }
body.planning .char-row.squad-assigned .char-photo-col { pointer-events: none; }
body.planning .char-row.squad-draft .char-photo { border-color: var(--accent); box-shadow: 0 0 8px rgba(110,168,255,0.4); }
.party-chip {
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.party-chip:hover { border-color: var(--accent); }
.party-chip.active {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #0b1020;
  font-weight: 600;
}

/* board = 3 columns */
.board {
  display: flex;
  flex-wrap: wrap;
  justify-content: center; /* keep the block of player columns centered on the page */
  /* Pack as many player columns side by side as fit at their natural width,
     wrapping to a new row only when they don't. Not stretched to fill. */
  gap: 18px;
  align-items: flex-start;
}
.column { flex: 0 1 280px; }
@media (max-width: 360px) { .column { flex-basis: 100%; } }

.column {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.column-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.column-title { font-size: 16px; font-weight: 600; color: var(--text); }
.column-title-input {
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 5px 9px; font-size: 15px; font-weight: 600; width: 100%;
}
.column-del { display: none; }
body.editing .column-del { display: inline-flex; }
.col-move { padding: 4px 8px; line-height: 1; flex: 0 0 auto; }
.col-move:disabled { opacity: 0.3; cursor: default; }

/* character row: photo on the left, dailies row to the right */
.char-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 12px;
  order: 0; /* per-row order set inline by layoutColumns (level/timer; +10000 = sunk) */
  transition: background 0.12s ease, opacity 0.3s ease, filter 0.3s ease;
}
.char-row.draggable { cursor: grab; padding: 4px; margin: -4px; }
.char-row.dragging { opacity: 0.45; }
/* all dailies done -> greyscale + faded */
.char-row.done-all { filter: grayscale(1); opacity: 0.45; }
/* keep header on top and the add button at the very bottom when ordering kicks in */
.column-head { order: -1; }
.column-empty { order: -1; }
.add-char { order: 99999; }

/* in the active party: green frame around the character */
.char-row.in-party {
  padding: 6px;
  margin: -6px;
  border-radius: 12px;
  border: 2px solid var(--good);
  background: rgba(70, 211, 154, 0.08);
  box-shadow: 0 0 10px rgba(70, 211, 154, 0.25);
}
.char-row.in-party .char-photo { border-color: var(--good); }

.row-controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.reorder-btn {
  width: 26px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  border-radius: 7px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.1s ease;
}
.reorder-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.reorder-btn:disabled { opacity: 0.3; cursor: default; }

.drag-handle {
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: grab;
  letter-spacing: -2px;
}

.column.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

#classSelect {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  padding: 9px 11px; border-radius: 9px; font-size: 14px;
}
#classSelect:focus { outline: none; border-color: var(--accent); }

.char-photo-col {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 80px;
}
.char-photo-col.party-pickable { cursor: pointer; }
.char-photo-col.party-pickable:hover .char-photo { border-color: var(--good); }
.char-caption {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  max-width: 80px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.1;
}

.char-photo {
  position: relative;
  width: 80px;
  height: 80px;
  flex: 0 0 auto;
  border-radius: 16px;
  border: 3px solid #0c1326;
  background: #0c1326 center/cover no-repeat;
  box-shadow: inset 0 0 0 1px var(--line);
  display: flex; align-items: center; justify-content: center;
}
.char-photo .placeholder { color: var(--muted); font-size: 11px; text-align: center; }

.class-badge {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px 7px 2px 3px;
}
.class-badge img, .class-badge .icon-fallback {
  width: 18px; height: 18px; border-radius: 4px; object-fit: cover;
  display: flex; align-items: center; justify-content: center;
  background: var(--card-2); font-size: 10px; color: var(--accent);
}
.class-badge .class-level { font-size: 12px; font-weight: 700; color: var(--accent); }

/* buff timer clock next to the level (SVG takes currentColor) */
.buff-clock {
  background: none; border: none; cursor: pointer; padding: 0 1px; margin-left: 2px;
  display: inline-flex; align-items: center; gap: 2px; line-height: 1;
  color: var(--muted); opacity: 0.5; /* "off" look when no timer */
}
.buff-clock.on { opacity: 1; } /* color set inline (green→red gradient) */
.buff-clock .clk { display: block; }
.buff-clock .buff-time { font-size: 10px; font-weight: 700; }
.buff-clock:hover { transform: scale(1.12); }
body.locked .buff-clock { cursor: default; pointer-events: none; }

.char-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }

.dailies-row { display: flex; gap: 4px; }
.daily {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  cursor: pointer; user-select: none;
}
.daily .box {
  width: 28px; height: 28px; border-radius: 8px;
  border: 2px solid var(--line); background: var(--card-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #0b1020; transition: all 0.12s ease;
}
.daily .lbl { font-size: 9px; color: var(--muted); letter-spacing: 0.3px; }
.daily.done .box { background: var(--good); border-color: var(--good); }
.daily.done .lbl { color: var(--good); }
.daily.disabled { opacity: 0.3; cursor: default; }
.daily.disabled .box { background: transparent; }
body.editing .daily { cursor: default; }

/* locked = view only: boxes not interactive */
body.locked .daily:not(.disabled) { cursor: default; }
body.locked .daily:not(.disabled) .box { opacity: 0.85; }
/* eidolon stars are read-only when locked (visible, but not clickable) */
body.locked .eid-star { cursor: default; pointer-events: none; }

.char-edit-btn { display: none; }
body.editing .char-edit-btn { display: inline-flex; }

.add-char {
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  font-size: 13px;
  display: none;
}
body.editing .add-char { display: block; }
.add-char:hover { border-color: var(--accent); color: var(--text); }

.add-column-wrap { margin-top: 16px; text-align: center; }

.column-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 10px 0; }

/* Edit dialog */
.edit-dialog {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: var(--radius);
  width: min(520px, 92vw);
  padding: 0;
  box-shadow: var(--shadow);
}
.edit-dialog::backdrop { background: rgba(4, 7, 18, 0.6); backdrop-filter: blur(3px); }
.edit-dialog form { padding: 20px 22px; }
.edit-dialog h2 { margin: 0 0 16px; font-size: 18px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.field input {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  padding: 9px 11px; border-radius: 9px; font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.field-small { max-width: 90px; }

.dailies-toggle { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 6px 0 4px; }
.dailies-toggle legend { color: var(--muted); font-size: 12px; padding: 0 6px; }
.daily-toggle-list { display: flex; flex-wrap: wrap; gap: 10px; }
.daily-toggle-list label { display: flex; align-items: center; gap: 6px; font-size: 13px; }

.dialog-actions { display: flex; align-items: center; gap: 10px; margin: 18px 0 0; padding: 0; }
.dialog-actions .spacer { flex: 1; }

/* Eidolons tracker modal */
.eidolon-dialog {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: var(--radius);
  width: min(960px, 94vw);
  height: min(80vh, 760px);
  padding: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.eidolon-dialog::backdrop { background: rgba(4, 7, 18, 0.6); backdrop-filter: blur(3px); }
.eidolon-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.eidolon-head h2 { margin: 0; font-size: 18px; }
.eidolon-head-actions { display: flex; align-items: center; gap: 8px; }

.eidolon-add {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 18px; margin: 0 18px; margin-top: 12px;
  background: var(--card); border: 1px solid var(--accent); border-radius: 10px;
}
#eidolonAddName {
  flex: 1; min-width: 180px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 8px 11px; border-radius: 8px; font-size: 14px;
}
#eidolonAddName:focus { outline: none; border-color: var(--accent); }
.eidolon-add-photo { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.eidolon-add-photo input { max-width: 180px; font-size: 12px; }
.eidolon-add-hint { font-size: 11px; color: var(--muted); }

.eidolon-tabs { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 18px 0; }
.eidolon-tab {
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  padding: 6px 12px; border-radius: 9px; cursor: pointer; font-size: 13px;
}
.eidolon-tab:hover { border-color: var(--accent); }
.eidolon-tab.active { background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-color: transparent; color: #0b1020; font-weight: 600; }
.eidolon-tab .tab-count { opacity: 0.8; font-size: 11px; }

.eidolon-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 18px; }
#eidolonSearch {
  flex: 1; min-width: 200px;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  padding: 9px 12px; border-radius: 9px; font-size: 14px;
}
#eidolonSearch:focus { outline: none; border-color: var(--accent); }
.eidolon-filters { display: flex; gap: 6px; }
.eidolon-count { color: var(--muted); font-size: 13px; min-width: 64px; text-align: right; }

.eidolon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  align-content: start; /* don't stretch rows to fill the modal height */
  align-items: start;   /* cards keep their natural height */
  gap: 10px;
  padding: 4px 18px 18px;
  overflow-y: auto;
  height: calc(100% - 150px);
}
.eidolon-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--card); border: 2px solid var(--line); border-radius: 10px;
  padding: 8px 4px; cursor: pointer; color: var(--text);
  transition: border-color 0.12s ease, background 0.12s ease, opacity 0.12s ease;
}
.eidolon-thumb { position: relative; width: 56px; height: 56px; }
.eidolon-card img { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; display: block; }
.eidolon-card .eidolon-name { font-size: 11px; text-align: center; line-height: 1.15; }
.eidolon-card:hover { border-color: var(--accent); }
.eidolon-card.owned { border-color: var(--good); background: rgba(70, 211, 154, 0.10); }
.eidolon-card.complete { border-color: #ffce4d; background: rgba(255, 206, 77, 0.12); box-shadow: 0 0 8px rgba(255, 206, 77, 0.25); }
.eidolon-card:not(.owned) img { opacity: 0.5; filter: grayscale(0.45); }

/* star rating, top-left over the photo — small / unobtrusive */
.eidolon-stars {
  position: absolute; top: 1px; left: 1px;
  display: flex; gap: 0;
  background: rgba(8, 12, 26, 0.45); border-radius: 5px; padding: 0 1px;
}
.eid-star {
  background: none; border: none; padding: 0 1px; margin: 0; cursor: pointer;
  font-size: 11px; line-height: 1.3; color: rgba(255, 255, 255, 0.4);
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.9);
}
.eid-star.on { color: #ffce4d; }
.eid-star:hover { transform: scale(1.25); }

.eid-del {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--danger); color: #0b1020; border: none; cursor: pointer;
  font-size: 11px; font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.eid-edit {
  position: absolute; bottom: -6px; right: -6px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #0b1020; border: none; cursor: pointer;
  font-size: 10px; font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.eidolon-card.custom .eidolon-name::after { content: " ·custom"; color: var(--muted); font-size: 9px; }

.eidolon-empty { color: var(--muted); padding: 30px; text-align: center; grid-column: 1 / -1; }

.hidden { display: none !important; }

/* ---------- Help FAB (bottom-left "?" button + guide) — mock instance only ---------- */
.help-fab { position: fixed; left: 18px; bottom: 18px; z-index: 50; }
.help-fab-btn {
  list-style: none; cursor: pointer; user-select: none;
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 26px; font-weight: 800; line-height: 1; color: #2a2200;
  background: linear-gradient(180deg, #ffe066, #f5c518);
  border: 1px solid #d9a400;
  box-shadow: 0 6px 18px rgba(245, 197, 24, 0.35), var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.help-fab-btn::-webkit-details-marker { display: none; }   /* hide default triangle */
.help-fab-btn::marker { content: ""; }
.help-fab-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(245, 197, 24, 0.5), var(--shadow); }
.help-fab[open] .help-fab-btn { background: linear-gradient(180deg, #f5c518, #e0b000); }

.help-panel {
  position: absolute; left: 0; bottom: 58px;
  width: min(360px, calc(100vw - 36px));
  max-height: min(72vh, 580px); overflow-y: auto;
  padding: 14px 16px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: help-pop 0.14s ease;
}
@keyframes help-pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.help-panel h2 { margin: 0 0 2px; font-size: 16px; }
.help-panel .help-sub { color: var(--muted); font-size: 12px; line-height: 1.4; margin-bottom: 8px; }
.help-item { padding: 8px 0; border-top: 1px solid var(--line); }
.help-item:first-of-type { border-top: none; }
.help-item > b { font-size: 13px; }
.help-key { color: var(--accent); font-weight: 700; }
.help-item p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.help-item p b { color: var(--text); font-weight: 600; }
