/* /play/: player join flow and character sheet. Phone-first: one column with a bottom tab bar; two columns on
   tablets, three on desktops (tabs become columns). Shared look in /lib/base.css. */

.play {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: grid;
  gap: 16px;
}

.play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.play-header button {
  flex: none;
  white-space: nowrap;
}

.play-screen {
  display: grid;
  gap: 12px;
}

.play-error {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--danger) 18%, transparent);
  border: 1px solid var(--danger);
  font-weight: 600;
}

.play-roster,
.play-characters {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.play-roster button,
.play-characters button {
  width: 100%;
  min-height: 64px;
  justify-content: flex-start;
  font-size: 1.1rem;
}

.play-avatar {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #0b1220;
  font-weight: 700;
}

.play-who {
  display: flex;
  align-items: center;
  gap: 12px;
}

.play-form {
  display: grid;
  gap: 10px;
}

.play-field {
  display: grid;
  gap: 10px;
}

.play-form input[type="password"] {
  font-size: 1.4rem;
  letter-spacing: 0.3em;
  text-align: center;
}

.play-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.play-pad button {
  min-height: 56px;
  font-size: 1.3rem;
}

.play-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.play-actions button {
  flex: 1;
}

.play-characters .play-readonly {
  margin-left: auto;
  font-size: 0.85rem;
  font-weight: 500;
}

/* ---- character sheet ---- */

.sheet {
  min-height: 100vh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.sheet-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  gap: 8px;
  padding: 10px var(--gutter);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.sheet-id {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#sheet-back {
  padding: 0;
  font-size: 1.6rem;
}

.sheet-avatar {
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
}

/* V10: Foundry images cover the initial (which shows again if the image fails). */
.play-avatar,
.entry-thumb {
  position: relative;
  overflow: hidden;
}

.face-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  background: var(--surface);
}

.entry-thumb {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 700;
}

.sheet-title {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.sheet-title h1 {
  margin: 0;
  font-size: 1.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* One row on every width: AC, Inspiration, rest and wallet (V2: no condition chips). */
.sheet-stats {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.sheet-stat {
  white-space: nowrap;
}

.sheet-icon {
  flex: none;
  min-height: 34px;
  min-width: 34px;
  width: 34px;
  padding: 0;
  justify-content: center;
  border-radius: 999px;
}

.sheet-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.sheet-icon[aria-expanded="true"] {
  border-color: var(--accent);
}

.sheet-stat {
  font-size: 0.9rem;
}

.sheet-chip {
  min-height: 28px;
  min-width: 0;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

#sheet-inspiration[aria-pressed="true"] {
  background: var(--warn);
  border-color: var(--warn);
  color: #0b1220;
}

/* The header HP text and bar are one button that opens the HP pop-over. */
.sheet-hp-open {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 0;
  min-width: 0;
  padding: 2px 0;
  border: none;
  border-radius: 8px;
  background: none;
  color: inherit;
  font-weight: inherit;
  text-align: left;
}

.sheet-hp-open:active:not(:disabled) {
  transform: none;
}

/* The HP text and bar fill their header column, one wide tap target (the base button centres its content). */
.sheet-hp-open {
  grid-template-columns: minmax(0, 1fr);
  justify-content: stretch;
}

.sheet-hp-open:hover .hp-bar,
.sheet-hp-open:focus-visible .hp-bar {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sheet-hp-text {
  font-size: 0.95rem;
}

.hp-bar {
  display: block;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.hp-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ok);
  transition: width 0.25s ease;
}

.hp-bar[data-level="mid"] .hp-fill {
  background: var(--warn);
}

.hp-bar[data-level="low"] .hp-fill {
  background: var(--danger);
}

.hp-bar.has-temp {
  box-shadow: 0 0 0 2px var(--accent);
}

.sheet-rollbar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.roll-mode {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  flex: none;
}

.roll-mode label {
  position: relative;
}

.roll-mode input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
}

.roll-mode span {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.roll-mode input:checked + span {
  background: var(--accent);
  color: #0b1220;
}

.roll-mode input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

input.roll-bonus {
  min-height: 40px;
  min-width: 0;
  flex: 1;
}

.sheet-banner {
  margin: 12px var(--gutter) 0;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 15%, transparent);
  font-weight: 600;
}

.sheet-banner[data-reason="not_owner"] {
  border-color: var(--border);
  background: var(--surface);
  font-weight: 500;
}

.sheet-banner[data-reason="unreachable"] {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 15%, transparent);
}

.sheet-loading {
  padding: 24px var(--gutter);
}

/* Phone: a bottom tab bar; only the active panel shows. */
.sheet-tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.sheet-tabs button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
}

.sheet-tabs button[aria-selected="true"] {
  color: var(--accent);
  background: var(--surface-2);
}

.sheet-panels {
  padding: 12px var(--gutter) 24px;
}

[data-panel] {
  display: none;
}

[data-panel].is-active {
  display: grid;
}

.sheet-main {
  gap: 12px;
  align-items: start;
}

/* j6a: Combat and Defenses first (stacked on phones, half and half from tablet up), then the action groups. */
.main-top {
  display: grid;
  gap: 12px;
  align-items: start;
}

.main-actions-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

.main-actions {
  display: grid;
  gap: 16px;
  align-items: start;
}

.action-group {
  display: grid;
  gap: 8px;
}

.action-group-title {
  margin: 0;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  color: var(--text);
}

.action-section-title {
  margin: 4px 0 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* 7i7: title and details on the left open the description; buttons on the right, wrapping below only when the
   title would get narrower than 6.5rem. */
.entry.action-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 8px 10px;
}

button.entry-open.action-open {
  flex: 1 1 6.5rem;
  min-height: 40px;
  font-size: 0.9rem;
}

button.entry-open.action-open .entry-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}

button.entry-open.action-open .muted {
  font-size: 0.8rem;
}

.action-entry .activity-buttons {
  flex: 0 1 auto;
  justify-content: flex-end;
  margin-left: auto;
}

.action-entry .activity-buttons button {
  padding: 0 10px;
}

.main-filters {
  display: grid;
  gap: 6px;
}

.filter-row {
  display: grid;
  gap: 2px;
}

.filter-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

@media (min-width: 600px) {
  .filter-row {
    grid-template-columns: 4.5rem 1fr;
    align-items: center;
    gap: 8px;
  }
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

button.filter-chip {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

button.filter-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #0b1220;
}

/* Feature and item tiles that open the description modal. */
button.entry-open {
  display: grid;
  justify-content: stretch;
  justify-items: start;
  gap: 2px;
  flex: 1 1 12rem;
  min-width: 0;
  min-height: var(--tap);
  padding: 2px 4px;
  margin: -2px -4px;
  border: none;
  border-radius: 8px;
  background: none;
  color: inherit;
  font-weight: inherit;
  text-align: left;
}

button.entry-open:active:not(:disabled) {
  transform: none;
}

button.entry-open:hover .entry-name,
button.entry-open:focus-visible .entry-name {
  text-decoration: underline;
}

button.entry-open-name {
  flex: 0 1 auto;
  margin-right: auto;
}

.describe-body {
  display: grid;
  gap: 8px;
  max-height: calc(100dvh - 140px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.describe-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.45;
}

.describe-levels {
  margin: 0;
  padding-left: 1.2em;
  display: grid;
  gap: 2px;
}

.sheet-card {
  display: grid;
  gap: 10px;
}

.sheet-card h2,
.sheet-card h3 {
  margin: 0;
}

.sheet-card h2 {
  font-size: 1.1rem;
}

.sheet-card h3 {
  font-size: 0.95rem;
  color: var(--muted);
}

.sheet-hint {
  margin: 0;
  font-size: 0.85rem;
}

.sheet input[type="number"],
.sheet input[type="search"] {
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.hp-steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.hp-form {
  display: flex;
  gap: 8px;
}

.hp-form button {
  flex: none;
}

.death-saves {
  display: grid;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.death-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pips {
  display: flex;
  gap: 6px;
}

.pip {
  padding: 0;
  font-size: 1.2rem;
}

.pip-success[aria-pressed="true"] {
  color: var(--ok);
}

.pip-failure[aria-pressed="true"] {
  color: var(--danger);
}

.combat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.hit-dice {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.hit-die {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hit-die-name {
  font-weight: 700;
  min-width: 3em;
}

.hit-die button {
  margin-left: auto;
}

.rest-row {
  display: flex;
  gap: 8px;
}

.rest-row button {
  flex: 1;
}

.short-rest {
  display: grid;
  gap: 8px;
}

.short-rest p {
  margin: 0;
}

.short-rest-dice {
  display: grid;
  gap: 8px;
}

.short-rest-die {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.short-rest-die input[type="number"] {
  width: 6em;
}

.abilities {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ability {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.ability-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.ability-label {
  font-weight: 700;
  letter-spacing: 0.05em;
}

.ability-roll {
  padding: 0 8px;
}

.ability-roll.proficient,
.skill.proficient .skill-prof {
  color: var(--accent);
}

.sheet-dialog.abilities-dialog {
  width: min(560px, calc(100vw - 24px));
}

/* mi0 trial: the skills list under the abilities; the dialog scrolls, the title and close stay in view. */
.abilities-dialog .dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: -14px -16px 0;
  padding: 14px 16px 8px;
  background: var(--surface);
}

.pop-skills {
  display: grid;
  gap: 8px;
}

.sheet-dialog .pop-skills-title {
  margin: 4px 0 0;
}

.abilities-dialog .skills {
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 760px) {
  .sheet-dialog.abilities-dialog {
    width: min(760px, calc(100vw - 48px));
  }
  .abilities-dialog .skills {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 12px;
  }
}

@media (min-width: 600px) {
  .abilities-dialog .abilities {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* j6a: Defenses card. */
.defenses {
  display: grid;
  gap: 10px;
}

.defense-block {
  display: grid;
  gap: 4px;
}

.defense-label {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.defense-items,
.defense-note {
  margin: 0;
}

.defense-note {
  font-size: 0.85rem;
}

.condition-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

button.condition-chip {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--warn);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
}

.describe-level {
  margin: 0;
  font-weight: 700;
}

.describe-levels li.is-current {
  font-weight: 700;
}

/* hqr: adding a condition on the Defenses card, Remove / exhaustion level in its modal. */
.condition-add {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.condition-add[hidden],
.condition-edit[hidden] {
  display: none;
}

.condition-add-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.condition-add select {
  flex: 1 1 140px;
  min-width: 0;
}

.condition-edit {
  display: grid;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.condition-level {
  display: flex;
  align-items: center;
  gap: 8px;
}

.condition-level-value {
  min-width: 1.5em;
  text-align: center;
  font-weight: 700;
}

button.condition-remove {
  justify-self: start;
  border-color: var(--warn);
}

.condition-note {
  margin: 0;
}

.skills {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.skill {
  width: 100%;
  justify-content: flex-start;
  padding: 0 12px;
  font-weight: 500;
}

.skill-name {
  flex: 1;
  text-align: left;
}

.skill-ability {
  font-size: 0.8rem;
}

.skill-total {
  min-width: 2.5em;
  text-align: right;
  font-weight: 700;
}

/* ---- 9b tabs: actions, spells, inventory, notes ---- */

.sheet-tab {
  gap: 12px;
  align-items: start;
}

.notes-fields {
  display: contents;
}

/* ---- V6 spells: full-width spellcasting card, filters, flat list of cards ---- */

#spellcasting,
.spell-browser {
  grid-column: 1 / -1;
}

.spell-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

input#spell-search {
  appearance: none;
  background: var(--bg);
  color: var(--text);
  flex: 1 1 14rem;
  min-width: 0;
  min-height: 40px;
}

.spell-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}

.spell-filter input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.spell-filter select {
  min-height: 40px;
}

.spell-side {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.spell-levels {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.spell-levels-label {
  font-size: 0.8rem;
}

button.level-button {
  min-height: 40px;
  min-width: 44px;
  padding: 0 10px;
}

button.level-button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b1220;
}

.spell-damage {
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
}

.spell-damage.muted {
  font-weight: 500;
  font-size: 0.85rem;
}

button.undo-button {
  border-color: var(--warn);
}

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.entry {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.entry-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.entry-name {
  font-weight: 700;
  margin-right: auto;
}

.entry-tags {
  font-size: 0.8rem;
}

.entry-desc {
  margin: 0;
  font-size: 0.9rem;
}

.entries.contents {
  margin-left: 12px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
}

.activities {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.activity {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.activity-info {
  display: grid;
  margin-right: auto;
  font-size: 0.9rem;
}

.activity-info .muted {
  font-size: 0.8rem;
}

.activity-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.activity-buttons button {
  min-height: 40px;
  padding: 0 14px;
}

.uses {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
}

button.step {
  min-height: 36px;
  min-width: 36px;
  padding: 0;
}

.crit-toggle,
.cast-ritual {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.crit-toggle input,
.cast-ritual input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.slots {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.slots .pips {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pip-slot[aria-pressed="true"] {
  color: var(--accent);
}

.cast-panel {
  display: grid;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.cast-panel p {
  margin: 0;
  font-size: 0.85rem;
}

.cast-field {
  display: grid;
  gap: 4px;
  font-size: 0.85rem;
}

.sheet select {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.sheet select:disabled,
.sheet input:disabled {
  opacity: 0.6;
}

.item-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.item-remove {
  margin-left: auto;
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.85rem;
  color: var(--danger);
}

/* ---- S5: add from compendiums ---- */

.items-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.items-head h2 {
  margin: 0;
}

.item-search-form {
  display: grid;
  gap: 8px;
}

input#item-search {
  appearance: none;
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.item-target {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.item-target > span {
  flex: none;
  white-space: nowrap;
}

.item-target select {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
}

.item-results {
  max-height: min(50dvh, 420px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.item-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.item-result .entry-head {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 2px;
}

.item-result button {
  flex: none;
}

.sheet-dialog.add-item-dialog {
  width: min(560px, calc(100vw - 24px));
}

.item-use {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
}

.item-use .cast-field {
  flex: 1 1 180px;
}

.qty {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.qty-value {
  min-width: 2.5em;
  text-align: center;
  font-weight: 700;
}

.note-label {
  font-weight: 700;
  font-size: 1.05rem;
}

.note-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--warn);
}

.note-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

/* ---- header pop-overs ---- */

.sheet-dialog {
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  /* 5rc: scrolling past a dialog's end must not chain to the sheet behind the modal. */
  overscroll-behavior: contain;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 48px rgb(0 0 0 / 0.6);
}

/* 5rc: the page behind an open sheet dialog doesn't scroll (set by openDialog, cleared on the last close). */
html.sheet-modal-open {
  overflow: hidden;
}

.sheet-dialog::backdrop {
  background: rgb(0 0 0 / 0.55);
}

.dialog-body {
  display: grid;
  gap: 12px;
  padding: 14px 16px 18px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.dialog-close {
  padding: 0;
  font-size: 1.4rem;
  justify-content: center;
}

.sheet-dialog h3 {
  margin: 4px 0 0;
  font-size: 0.95rem;
}

.dialog-now {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
}

.dialog-reason {
  margin: 0;
  font-size: 0.9rem;
}

.long-rest,
.long-rest-confirm {
  display: grid;
  gap: 8px;
}

.long-rest-confirm[hidden] {
  display: none;
}

.long-rest-confirm p {
  margin: 0;
}

.wallet-total {
  margin: 0;
  font-size: 1.05rem;
}

.wallet-coins {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.wallet-coin {
  display: grid;
  grid-template-columns: 2.4em minmax(3.5em, auto) minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
}

.wallet-label {
  font-weight: 700;
}

.wallet-amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.wallet-coin input[type="number"] {
  min-width: 0;
  width: 100%;
}

.wallet-coin button {
  padding: 0 12px;
}

/* 49e: payment requests. The wallet button shows how many are open. */
#wallet-open {
  position: relative;
}

#wallet-open:not([data-badge=""])[data-badge]::after {
  content: attr(data-badge);
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--warn);
  color: #111;
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

.wallet-payments {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.wallet-payments[hidden] {
  display: none;
}

.wallet-requests,
.wallet-results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.wallet-request {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wallet-request-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.wallet-request button {
  flex: none;
  padding: 0 12px;
}

.wallet-results {
  font-size: 0.9rem;
}

.payment-ask {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.payment-lines {
  display: grid;
  gap: 4px;
}

.payment-lines p,
#payment-position {
  margin: 0;
}

.payment-error {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  font-weight: 600;
}

.payment-error[hidden] {
  display: none;
}

/* aig: off but focusable (aria-disabled; the script ignores presses). */
button[data-soft][aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

button[data-soft][aria-disabled="true"]:active {
  transform: none;
}

.payment-short {
  color: var(--danger);
  font-weight: 700;
}

.pay-request-targets {
  margin: 0;
  padding: 8px 10px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.pay-request-target-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px 12px;
}

.pay-request-target {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  overflow-wrap: anywhere;
}

.pay-request-amount {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
  gap: 8px;
}

.pay-request-amount label,
.pay-request-field {
  display: grid;
  gap: 4px;
}

/* Outside .sheet (the overview opens it too): the sheet's field look. */
.pay-request-dialog input[type="number"],
.pay-request-dialog input[type="text"],
.pay-request-dialog select {
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.pay-request-target input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex: none;
}

/* The roll pop-up and toast move into an open pop-over; keep them above its content. */
.sheet-dialog .roll-popup,
.sheet-dialog .toast {
  z-index: 2;
}

.sheet-banner[data-reason="offline"],
.sheet-banner[data-reason="bridge_offline"] {
  border-color: var(--warn);
}

.roll-popup {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 11;
  min-width: 200px;
  max-width: calc(100vw - 32px);
  padding: 14px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--surface);
  box-shadow: 0 8px 32px rgb(0 0 0 / 0.5);
  text-align: center;
  cursor: pointer;
}

.roll-title {
  font-weight: 600;
}

.roll-total {
  font-size: 2.6rem;
  font-weight: 800;
  line-height: 1.1;
}

.roll-formula {
  font-size: 0.85rem;
}

.roll-kind {
  font-weight: 700;
}

.roll-popup[data-kind="critical"] {
  border-color: var(--ok);
}

.roll-popup[data-kind="critical"] .roll-kind {
  color: var(--ok);
}

.roll-popup[data-kind="fumble"] {
  border-color: var(--danger);
}

.roll-popup[data-kind="fumble"] .roll-kind {
  color: var(--danger);
}

.toast[data-kind="info"] {
  background: var(--surface-2);
  border: 1px solid var(--ok);
}

.sheet ~ .toast {
  bottom: calc(84px + env(safe-area-inset-bottom));
}

/* Tablet: the tab bar moves to the top; Main's cards share two columns. */
@media (min-width: 700px) {
  .sheet {
    padding-bottom: 24px;
  }
  .sheet-header {
    grid-template-columns: minmax(0, 1fr) minmax(200px, 280px);
    align-items: center;
    column-gap: 20px;
  }
  .sheet-rollbar {
    grid-column: 1 / -1;
  }
  .sheet-tabs {
    position: static;
    padding: 12px var(--gutter) 0;
    background: transparent;
    border-top: none;
  }
  .sheet-tabs button {
    flex: none;
    padding: 0 24px;
  }
  .main-top {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sheet-tab {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sheet-tab .items-card {
    grid-column: 1 / -1;
  }
  .sheet-tab .note:first-child {
    grid-column: 1 / -1;
  }
  .spell-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
  .abilities {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .roll-popup,
  .sheet ~ .toast {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* Desktop: three columns; the header puts the roll bar beside the HP. */
@media (min-width: 1100px) {
  .sheet-header {
    grid-template-columns: minmax(0, 1fr) 280px auto;
  }
  .sheet-rollbar {
    grid-column: auto;
  }
  .main-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sheet-tab {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .sheet-tab .sheet-wide {
    grid-column: span 2;
  }
  .spell-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 700px) {
  .play {
    max-width: 560px;
    padding-top: clamp(32px, 8vh, 96px);
    gap: 20px;
  }
  .play h1 {
    font-size: 1.75rem;
  }
  .play .card {
    padding: 20px 24px;
  }
  .play-pad button {
    min-height: 64px;
  }
}

/* Keyboard-equipped desktops: the native field is enough, but the pad stays usable with a mouse. */
@media (min-width: 1100px) and (hover: hover) {
  .play-pad {
    max-width: 360px;
    justify-self: center;
    width: 100%;
  }
}

/* ---- ita: move pad ---- */

/* The FAB sits above the phone tab bar (bottom-right, clear of the notch/home bar); the sheet scrolls past it. */
.nav-fab {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(80px + env(safe-area-inset-bottom));
  z-index: 6;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.45);
}

.nav-fab[hidden] {
  display: none;
}

.nav-fab svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-fab[aria-expanded="true"] {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

.sheet:has(.nav-fab:not([hidden])) {
  padding-bottom: calc(148px + env(safe-area-inset-bottom));
}

/* Non-modal: a compact panel over the FAB's corner; the sheet behind stays usable. */
.nav-pad {
  position: fixed;
  inset: auto calc(16px + env(safe-area-inset-right)) calc(146px + env(safe-area-inset-bottom)) auto;
  z-index: 7;
  width: min(272px, calc(100vw - 32px));
  margin: 0;
  padding: 10px 12px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 32px rgb(0 0 0 / 0.55);
}

.nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.nav-head h2 {
  margin: 0;
  font-size: 1rem;
}

.nav-token {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.nav-token[hidden] {
  display: none;
}

.nav-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.nav-grid button {
  min-height: 66px;
  padding: 0;
  font-size: 1.7rem;
  line-height: 1;
}

.nav-grid .nav-rotate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.7rem;
  line-height: 1.15;
  background: var(--surface-2);
}

/* The scene as the player sees it: its top edge (accent) and the edge they sit at (green, always nearest them). */
.nav-map {
  position: relative;
  width: 30px;
  height: 30px;
  border: 2px solid var(--muted);
  border-radius: 4px;
  transition: transform 0.2s ease;
}

.nav-map-top,
.nav-map-seat {
  position: absolute;
  font-size: 0;
  border-radius: 2px;
}

.nav-map-top {
  top: -4px;
  left: -2px;
  right: -2px;
  height: 5px;
  background: var(--accent);
}

.nav-map-seat {
  background: var(--ok);
}

.nav-map[data-seat="bottom"] .nav-map-seat {
  left: 4px;
  right: 4px;
  bottom: -4px;
  height: 5px;
}

.nav-map[data-seat="top"] .nav-map-seat {
  left: 4px;
  right: 4px;
  top: -4px;
  height: 5px;
}

.nav-map[data-seat="left"] .nav-map-seat {
  top: 4px;
  bottom: 4px;
  left: -4px;
  width: 5px;
}

.nav-map[data-seat="right"] .nav-map-seat {
  top: 4px;
  bottom: 4px;
  right: -4px;
  width: 5px;
}

.nav-status {
  min-height: 1.3em;
  margin: 8px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--warn);
  text-align: center;
}

@media (min-width: 700px) {
  .nav-fab {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
  .sheet:has(.nav-fab:not([hidden])) {
    padding-bottom: 96px;
  }
  .nav-pad {
    bottom: calc(92px + env(safe-area-inset-bottom));
  }
}
