/* Table Companion styles.
   The building blocks (.win, .bar, .btn, .well, .lbl, .num, .row, .pip, …)
   are copied from the design canvas (Main.dc.html). */

/* touch-action: no double-tap zoom on phones (pinch zoom still works),
   and no tap delay while the browser waits for a second tap. */
html { background: #E8E8E8; touch-action: manipulation; }
body {
  margin: 0;
  background: #E8E8E8;
  color: #222222;
  font-family: 'IBM Plex Sans', sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---- Canvas building blocks -------------------------------------------- */

/* Card border: --bc if a card sets it (grey cards, picker cards), else the character colour. */
.win { flex-shrink: 0; min-height: min-content; background: #F7F7F7; border: 2px solid var(--bc, var(--accent, #F7F7F7)); border-radius: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.18), 0 3px 8px rgba(0,0,0,.14); }
.bar { color: #F5F5F5; font: 600 11px/1 'IBM Plex Mono', monospace; letter-spacing: .08em; text-transform: uppercase; padding: 8px 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; border-radius: 8px 8px 0 0; }
/* Cards that start with a title bar get the bar colour as background along
   their top edge (hidden behind the bar). Without it, the bar's rounded
   corner and the border's inner curve leave a hairline of light card
   background between them. Nothing moves, so it holds at any zoom level.
   `local`: in scrolling popups the strip scrolls away with the bar. */
.win:has(> .bar:first-child) {
  background: linear-gradient(var(--bc, var(--accent, #F7F7F7)) 0 12px, #F7F7F7 12px) local;
}
.barbtn { width: 100%; border: 0; cursor: pointer; min-height: 40px; box-sizing: border-box; }
.btn { font: 600 15px 'IBM Plex Sans', sans-serif; color: #222222; background: #EDEDED; border: 1px solid #363636; border-radius: 9px; box-shadow: 0 1px 2px rgba(0,0,0,.32), 0 2px 5px rgba(0,0,0,.14); cursor: pointer; min-height: 44px; transition: transform .06s; }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 2px rgba(0,0,0,.3); }
/* Not in the canvas: buttons at an edge in arrange mode. */
.btn:disabled, .btn:disabled:active { opacity: .35; cursor: default; transform: none; box-shadow: 0 1px 2px rgba(0,0,0,.32), 0 2px 5px rgba(0,0,0,.14); }
.well { background: #FFFFFF; border: 1px solid #858585; border-radius: 7px; box-shadow: inset 0 1px 3px rgba(0,0,0,.22); box-sizing: border-box; outline: none; }
.well:focus { border-color: #2B3F6B; box-shadow: inset 0 1px 3px rgba(0,0,0,.22), 0 0 0 2px #9FB0D6; }
.num { font-family: 'IBM Plex Mono', monospace; }
.lbl { font: 600 11px 'IBM Plex Mono', monospace; letter-spacing: .06em; text-transform: uppercase; color: #5A5A5A; }
.row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid #D0D0D0; }
.tag { font: 600 11px 'IBM Plex Mono', monospace; background: #E8E8E8; border: 1px solid #858585; border-radius: 5px; padding: 3px 6px; color: #222222; }
.pip { width: 22px; height: 22px; border-radius: 50%; border: 0; cursor: pointer; padding: 0; }
.plain { background: none; border: 0; padding: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.inp { width: 100%; height: 44px; padding: 0 10px; font: 15px 'IBM Plex Sans', sans-serif; color: #222222; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* "Group by type": each group (Actions, Bonus actions…, spell levels) in its
   own inner panel on a slightly darker tray (canvas: .grps / .grp). */
.grps { display: flex; flex-direction: column; gap: 8px; padding: 8px; background: #EDEDED; }
.grps:last-child { border-radius: 0 0 8px 8px; }   /* follows the card's inner corner */
.grp { background: #F7F7F7; border-radius: 8px; overflow: hidden; }
.grplbl { font: 600 11px/1 'IBM Plex Mono', monospace; letter-spacing: .06em; text-transform: uppercase; color: #474747; padding: 9px 10px 3px; }
.grp .row { border-top: 0; padding-left: 10px; padding-right: 10px; position: relative; }
/* Inset dividers that stop short of the panel edges; none under the label. */
.grp .row::before { content: ''; position: absolute; top: 0; left: 12px; right: 12px; height: 1px; background: #DCDCDC; }
.grp .grplbl + .row::before { display: none; }

/* Small group heading strip inside a card (copy picker). */
.subbar { font: 600 10px 'IBM Plex Mono', monospace; letter-spacing: .06em; text-transform: uppercase; color: #5A5A5A; background: #EDEDED; border-top: 1px solid #D0D0D0; padding: 6px 12px; }

.star { width: 44px; height: 44px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }

/* Icon-only square buttons (switch character, pencil, arrows). */
.iconbtn { width: 44px; padding: 0; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* Small × close button inside a title bar. */
.closebtn { background: #EDEDED; border: 1px solid #363636; border-radius: 5px; width: 22px; height: 22px; padding: 0; cursor: pointer; color: #222222; font-weight: 600; }

/* ---- Page layout ------------------------------------------------------- */

/* One scrolling column of cards: the phone sheet, the picker, and the editors
   (on tablet/desktop those sit inside .dialog). */
.scr {
  box-sizing: border-box;
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 12px 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 14px;
}

/* ---- Tablet / desktop (SPEC §8 Layouts) -------------------------------- */

/* Slim bar across the top in the character colour: name, last rolls, buttons. */
.topbar {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 14px; padding: 8px 16px;
  background: var(--accent); color: #F5F5F5; border-bottom: 1px solid #363636;
}

/* The sheet's columns (2 on tablet, 3 on desktop); --cols is set inline. */
.cols {
  box-sizing: border-box;
  max-width: 1500px; margin: 0 auto; padding: 16px 16px 40px;
  display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 14px; align-items: start;
}
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.wide-banner { max-width: 1500px; margin: 0 auto; padding: 16px 16px 0; box-sizing: border-box; }

/* Editors as a centred dialog over the dimmed sheet. */
.backdrop { position: fixed; inset: 0; z-index: 4; background: rgba(20, 20, 20, .45); }
.dialog {
  position: fixed; top: 24px; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 5;
  width: min(560px, calc(100% - 48px)); overflow-y: auto;
  background: #E8E8E8; border: 1px solid #E8E8E8; border-radius: 12px;
  box-shadow: 0 10px 28px rgba(20, 20, 20, .38);
}

/* ---- Popups (phone bottom sheets) ------------------------------------- */

.ovl {
  position: fixed; inset: 0; z-index: 4;
  background: rgba(20, 20, 20, .45);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px; box-sizing: border-box;
}
.ovl > .win { width: 100%; max-width: 536px; max-height: 100%; overflow-y: auto; }

/* Rows inside popups: tap to roll. */
.poprow { display: flex; align-items: center; gap: 10px; min-height: 48px; width: 100%; border-bottom: 1px solid #DCDCDC; }
.poprow .why { display: block; font-size: 11px; font-weight: 400; color: #5A5A5A; margin-top: 1px; }

/* Proficiency dots (no outlines): filled = character colour, expertise = ring. */
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: #D0D0D0; }
.dot.on { background: var(--accent); }
.dot.exp { background: var(--accent); box-shadow: 0 0 0 2px #F5F5F5, 0 0 0 3.5px var(--accent); }

/* ---- Roll result (drops in from the top) ------------------------------ */

.toast {
  position: fixed; left: 12px; right: 12px; top: 14px; z-index: 6;
  max-width: 536px; margin: 0 auto;
  box-shadow: 0 1px 3px rgba(0,0,0,.2), 0 6px 16px rgba(20,20,20,.32);
}
@media (prefers-reduced-motion: no-preference) { .toast { animation: drop .18s ease-out; } }
@keyframes drop { from { transform: translateY(-24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- "Not saved" notice ------------------------------------------------ */

.savenote {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 7;
  background: #474747; color: #F5F5F5; border-radius: 8px; padding: 8px 12px;
  font: 600 12px 'IBM Plex Mono', monospace;
}

/* ---- DM view (SPEC §8 DM view; canvas DM.dc.html) ---------------------- */

/* Dark top bar: ‹ Characters, title + count, Live chip. Sticks to the top. */
.dmtop {
  position: sticky; top: 0; z-index: 3;
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding: 8px 16px;
  background: #474747; color: #F5F5F5; border-bottom: 1px solid #363636;
}
.dmtop.phone { gap: 10px; padding: 8px 12px; align-items: flex-start; }
.dmtitle { flex: 1 1 160px; min-width: 0; }
.dmtop.phone .dmtitle { flex: 1 1 0; padding-top: 2px; }
.dmright { display: flex; align-items: center; gap: 10px; flex-shrink: 0; margin-left: auto; }
.dmchip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 8px; border: 1px solid rgba(245,245,245,.5); font: 600 11px 'IBM Plex Mono', monospace; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }

/* Overview: columns of character cards (--cols set inline: 1 / 2 / 3). */
.dmscroll { box-sizing: border-box; max-width: 1500px; margin: 0 auto; padding: 16px 16px 40px; }
.dmtop.phone + .dmscroll { padding: 14px 12px 40px; }
.ovgrid { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 14px; align-items: start; }
.dmcol { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* The whole upper part of a card is one button (opens the read-only sheet). */
.ovhit { display: block; width: 100%; padding: 0; margin: 0; background: none; border: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; border-radius: 8px 8px 0 0; }
.ovhit > .bar { display: flex; }
.ovcard:has(.ovhit:hover) { outline: 2px solid #858585; outline-offset: 1px; }
.ovline { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; row-gap: 2px; min-height: 22px; }

/* DM note on the card: dashed white box with a dark "DM" tag. */
.dmnote { display: flex; gap: 8px; align-items: flex-start; background: #FFFFFF; border: 1px dashed #858585; border-radius: 7px; padding: 6px 8px; }
.dmtag { font-size: 10px; color: #F5F5F5; background: #474747; border-radius: 4px; padding: 2px 5px; flex-shrink: 0; margin-top: 1px; }

/* ---- Arrange mode (SPEC §8 Card order & arranging; canvas .arrwrap) ----- */

/* Each card as a dimmed, non-clickable preview (`inert` on .arrprev), clipped
   to ~160px with a fade at the bottom; the buttons sit below it and overlap
   the faded edge a little. The DM overview uses 200px (.arrwrap.tall). */
.arrwrap { display: flex; flex-direction: column; gap: 6px; --arrmax: 160px; }
.arrwrap.tall { --arrmax: 200px; }
.arrprev > .win {
  min-height: 0; max-height: var(--arrmax); overflow: hidden; opacity: .45;
  -webkit-mask-image: linear-gradient(#000 calc(100% - 36px), transparent 100%);
  mask-image: linear-gradient(#000 calc(100% - 36px), transparent 100%);
}
.arrwrap.hid .arrprev > .win { opacity: .2; }
.arrctl { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; position: relative; z-index: 1; margin-top: -14px; }
.arrbtns { display: flex; align-items: center; justify-content: center; gap: 6px; }
/* "Hidden" tag: centred just above the buttons, over the faded card edge.
   Absolutely placed so the buttons stay where they are whether a card is
   hidden or not. */
.arrctl .arrhid { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); white-space: nowrap; }

/* ---- DM view: editable note, read-only sheet (canvas DM.dc.html) ------- */

.noteedit { cursor: text; }
.noteedit:focus-within { border-style: solid; border-color: #2B3F6B; box-shadow: 0 0 0 2px #9FB0D6; }
.noteedit textarea { flex: 1; min-width: 0; border: 0; background: transparent; padding: 2px 0; margin: 0; font: 13px/1.4 'IBM Plex Sans', sans-serif; color: #222222; resize: vertical; outline: none; min-height: 36px; }
.noteedit textarea::placeholder { color: #5A5A5A; }

/* Read-only sheet columns: 3 desktop / 2 tablet / 1 phone (--cols inline). */
.dmcols { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 14px; align-items: start; }

/* Saves and skills as a flat two-column list (no roll buttons). */
.flat2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 14px; }
.flatrow { display: flex; align-items: center; gap: 8px; min-height: 30px; border-bottom: 1px solid #DCDCDC; font-size: 13px; }

/* DM pin on each entry: dashed outline when off, dark when pinned. */
.pinbtn { width: 36px; height: 36px; flex-shrink: 0; border-radius: 8px; border: 1px dashed #858585; background: transparent; color: #858585; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.pinbtn.on { background: #474747; border: 1px solid #363636; color: #F5F5F5; }

/* ---- Login (login.js) ---------------------------------------------------- */

/* Covers the whole page (above dialogs, popups and toasts) until the key is accepted. */
.login { position: fixed; inset: 0; z-index: 20; background: #E8E8E8; overflow-y: auto; }
