/* The button grid (buttons.js): rows × columns of icon and/or label
   buttons, the alt layer, the Alt latch and ⋯, the icon picker. Loaded after
   index.html's own styles, which keep the bar's frame (#buttons) and the
   menu. Icons are game-icons.net masks tinted with currentColor, so they
   follow the theme's colours. Twin of arcana-app's buttons_page.rs. */

#buttons { align-items: flex-start; flex-wrap: nowrap; }
#buttons .bt-grid {
  display: grid;
  grid-template-columns: repeat(var(--across, 12), max-content);
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  align-content: start;
  justify-content: start;
}
#buttons .bt-tools { display: flex; gap: 4px; flex: none; margin-left: auto; }
#buttons .bt-tools button.bt { flex: none; }
#buttons .gap { min-width: 1px; }
/* Both faces sit in the same cell, so a button is as wide as the wider one
   (nothing moves when the alt layer shows) and the alt icon is loaded
   before it is needed. */
#buttons button.bt {
  display: inline-grid;
  align-items: center;
  justify-items: center;
  min-width: 0;
  max-width: 15em;
  padding: 0 8px;
}
#buttons .face { grid-area: 1 / 1; display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
#buttons .face .lbl { overflow: hidden; text-overflow: ellipsis; }
#buttons .face.alt { visibility: hidden; color: var(--i10); }
#buttons button.bt.icon-only { padding: 0 5px; min-width: 30px; }
#buttons .ic { width: 16px; height: 16px; }

/* Narrower than the grid: the columns share the width, then (still too
   narrow) the places wrap, like the bar always did. A shared column is
   never narrower than a button can be (--bt-least; 44px on touch), or the
   buttons overlapped and cut each other's labels; too narrow for that, the
   grid overflows and fit() wraps it. */
#buttons { --bt-least: 0px; }
#buttons.squeeze .bt-grid { grid-template-columns: repeat(var(--across, 12), minmax(var(--bt-least), 1fr)); }
#buttons.squeeze .bt-grid button.bt { max-width: none; width: 100%; }
#buttons.wrap .bt-grid { grid-template-columns: repeat(auto-fill, minmax(4.5em, 1fr)); }
#buttons.wrap .gap { display: none; }
#buttons.wrap .bt-grid button.bt { max-width: none; }

/* Down a side: the grid's columns run down, the tools sit below. */
#buttons.vertical,
#buttons-win[data-window] #buttons.vertical { flex-direction: column; flex-wrap: nowrap; align-items: stretch; align-content: stretch; }
#buttons.vertical .bt-grid { flex: none; }
#buttons.vertical .bt-grid {
  grid-auto-flow: column;
  grid-template-rows: repeat(var(--down, 12), auto);
  grid-template-columns: repeat(var(--across, 1), minmax(0, 1fr));
}
#buttons.vertical .bt-grid button.bt { max-width: none; width: 100%; }
#buttons.vertical .bt-tools { margin: 4px 0 0; justify-content: flex-end; }

/* The alt layer: the alt key held or the latch on. */
#buttons.alt-on .bt.has-alt .face.main,
#buttons .bt.has-alt.peek .face.main { visibility: hidden; }
#buttons.alt-on .bt.has-alt .face.alt,
#buttons .bt.has-alt.peek .face.alt { visibility: visible; }
#buttons.alt-on .bt.has-alt { border-color: color-mix(in srgb, var(--verdigris) 55%, var(--ink)); }
#buttons.alt-on .bt[data-slot]:not(.has-alt) { opacity: 0.5; }
#buttons button.bt.latch { color: var(--muted); }
#buttons button.bt.latch[aria-pressed="true"] { color: var(--i10); border-color: var(--verdigris); background: var(--rule); }

/* ⋯ on touch screens: taps on buttons open their menu until ⋯ again. */
#buttons button.bt.more { display: none; color: var(--muted); }
#buttons.editing .bt[data-slot] { border-style: dashed; border-color: var(--gilt); }
#buttons.editing button.bt.more { color: var(--gilt); border-color: var(--gilt); }
@media (pointer: coarse) {
  #buttons { --bt-least: 44px; }
  #buttons button.bt { height: 44px; min-width: 44px; padding: 0 10px; }
  #buttons button.bt.icon-only { min-width: 44px; padding: 0 8px; }
  #buttons button.bt.more { display: inline-flex; }
  #buttons .ic { width: 24px; height: 24px; }
}
@media (pointer: coarse) and (max-width: 640px) {
  /* A phone has no F-keys. */
  #buttons .face .key { display: none; }
}
@media (max-width: 640px) {
  #buttons.wrap .bt-grid { grid-template-columns: repeat(auto-fill, minmax(min(4.5em, 44px), 1fr)); }
}

/* An icon: the SVG's shape, drawn in the text colour. */
.ic {
  display: inline-block;
  flex: none;
  width: 16px;
  height: 16px;
  background-color: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.ic.none { background: none; }

/* Settings › Buttons */
#bt-grid-size label { display: inline-flex; gap: 6px; align-items: center; }
#bt-grid-size select { flex: none; min-width: 3.5em; }
#bt-list .ic { color: var(--gilt); }
#bt-list li.past { background: repeating-linear-gradient(135deg, transparent 0 6px, color-mix(in srgb, var(--rule) 50%, transparent) 6px 12px); }
#bt-list .alt-what { display: inline-flex; gap: 4px; align-items: center; color: var(--i10); font-size: 12px; white-space: nowrap; }
#bt-list .alt-what .ic { color: var(--i10); width: 14px; height: 14px; }
.bt-icon-now { display: inline-flex; width: 28px; height: 28px; align-items: center; justify-content: center; border: 1px solid var(--rule); color: var(--gilt); }
.bt-icon-now .ic { width: 22px; height: 22px; }
#bt-alt-icon-now { color: var(--i10); }
#bt-show, #bt-alt { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
#bt-alt { border-top: 1px solid var(--rule); padding-top: 8px; margin-top: 4px; }
#bt-alt select { flex: none; }

/* The icon picker */
#bt-picker {
  position: fixed;
  z-index: 13;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 16px));
  height: min(560px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 12px 10px;
  background: var(--ink-high);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-small);
  color: var(--parchment);
  font-family: var(--chrome-font);
  font-size: var(--chrome-size);
}
#bt-picker header { display: flex; align-items: center; justify-content: space-between; }
#bt-picker h3 { margin: 0; font-weight: normal; font-size: 15px; color: var(--gilt); }
#bt-picker .bt-picker-find { display: flex; gap: 8px; }
#bt-picker input[type="search"], #bt-picker select {
  min-height: 32px;
  background: var(--ink);
  color: var(--parchment);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  font: inherit;
  padding: 0 8px;
}
#bt-picker input[type="search"] { flex: 1; min-width: 0; }
#bt-picker input:focus-visible, #bt-picker select:focus-visible { outline: 1px solid var(--gilt); }
.bt-picker-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  grid-auto-rows: 44px;
  gap: 4px;
  align-content: start;
  padding: 2px;
}
.bt-picker-grid:focus-visible { outline: 1px solid var(--rule); }
.bt-picker-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 2px;
  color: var(--parchment);
  cursor: pointer;
}
.bt-picker-icon .ic { width: 30px; height: 30px; }
.bt-picker-icon:hover { color: var(--gilt-bright); border-color: var(--rule); }
.bt-picker-icon[aria-selected="true"] { color: var(--gilt); border-color: var(--gilt); }
.bt-picker-icon.active { outline: 2px solid var(--gilt); outline-offset: -2px; color: var(--gilt-bright); }
.bt-picker-status { margin: 0; min-height: 1em; color: var(--muted); font-size: 12px; }
#bt-picker footer { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#bt-picker footer .grow { flex: 1; }
#bt-picker footer button {
  background: none;
  color: var(--parchment);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  font: inherit;
  padding: 4px 12px;
  cursor: pointer;
}
#bt-picker footer button:hover, #bt-picker footer button:focus-visible { border-color: var(--gilt); color: var(--gilt); outline: none; }
#bt-picker .credit { color: var(--muted); font-size: 12px; }
#bt-picker .credit a { color: var(--muted); }
@media (pointer: coarse) {
  .bt-picker-grid { grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); grid-auto-rows: 52px; }
}

/* Locked in place (layout.js .lay-locked, owner 2026-11-14): only the
   buttons are left, each on its own with a soft shadow; the bar's own
   ground goes and the gaps between them let clicks through to the game. */
#buttons-win.lay-locked > #buttons { background: transparent; border-color: transparent; pointer-events: none; }
#buttons-win.lay-locked #buttons button { pointer-events: auto; box-shadow: 0 4px 14px rgb(0 0 0 / 0.55); }

/* Floating or pinned (buttons.js shape(), owner 2026-11-14): the window's
   shape decides the arrangement. Each row fills left to right and wraps;
   every button is one width (--colw: the longest label, capped), so they
   line up as a grid. Pinned left or right: one column, as wide as the
   window. Never squashed below a comfortable height; more than fit scroll.
   The + is always last. */
#buttons-win[data-window] #buttons.shaped { display: block; padding: 6px 8px 8px; scrollbar-width: thin; scrollbar-color: var(--rule-strong) transparent; }
#buttons.shaped .bt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--colw, 120px), 100%), 1fr));
  grid-auto-flow: row;
  grid-template-rows: none;
  gap: 4px;
}
#buttons.shaped.col .bt-grid { grid-template-columns: minmax(0, 1fr); }
#buttons.shaped .gap { display: none; }
#buttons.shaped .bt-grid button.bt { width: 100%; max-width: none; min-height: 30px; justify-items: start; padding: 0 9px; }
#buttons.shaped .bt-grid button.bt.add { order: 1; justify-items: center; }
#buttons.shaped .bt-grid button.bt.icon-only { justify-items: center; }
#buttons.shaped .face { width: 100%; justify-content: space-between; }
#buttons.shaped .bt.nokey .face .key { display: none; }
#buttons.shaped .bt-tools { justify-content: flex-end; }
#buttons.shaped .bt-tools:has(.latch) { margin-top: 4px; }
/* (measuring each button's own width: one unwrapped row, nothing cut) */
#buttons.shaped.measure .bt-grid { display: flex; flex-wrap: nowrap; }
#buttons.shaped.measure .bt-grid button.bt { width: auto; flex: none; }
#buttons.shaped.measure .face { width: auto; }
#buttons-win.lay-locked #buttons.shaped .bt.add { display: none; }
@media (pointer: coarse) {
  #buttons.shaped .bt-grid button.bt { min-height: 44px; }
  #buttons.shaped .bt-tools { margin-top: 4px; }
}
