/* Modals: a native <dialog> styled as a small phosphor terminal window (docs/ui-spec.md § Visuals:
   Modals). Esc cancels natively; the ::backdrop dims the sky.

   The dialog never outgrows the screen: it is at most the visible height (`dvh` follows a phone's address bar; `vh`
   where it is unknown) less a 16 px margin each side, like its width. Its title and its buttons' row keep their size,
   and the body between them (`.modal-body`) scrolls when it is too tall, so the title stays in view and the buttons
   stay reachable. `.modal-form`, the form some dialogs wrap their body and buttons in, is part of that column. The body
   is a scroll container, so the browser scrolls a control that takes keyboard focus into view. A scroll container cuts off
   what is drawn outside it, a focus outline (up to 5 px, a button's) included: the 16 px of padding at its sides holds
   it, and `scroll-padding` keeps a control that focus scrolls in, flush with the edge, off it at the top and the bottom. */
.modal {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--phosphor-rule);
  border-radius: 10px;
  background: radial-gradient(ellipse at 50% 30%, var(--glass-glow), var(--glass) 70%);
  box-shadow: 0 0 0 4px var(--bezel), 0 0 0 5px var(--bezel-edge), 0 18px 40px rgba(10, 30, 50, 0.5);
  color: var(--phosphor);
  font: var(--terminal-size) / var(--terminal-leading) var(--font-mono);
  text-shadow: 0 0 5px var(--phosphor-glow);
}

.modal[open] {
  display: flex;
  flex-direction: column;
}

.modal::backdrop {
  background: rgba(20, 60, 90, 0.5);
}

.modal-title {
  flex: none;
  margin: 0;
  padding: 7px 14px;
  border-bottom: 1px solid var(--phosphor-rule);
  background: rgba(156, 255, 156, 0.1);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 16px 16px 8px;
  overflow-y: auto;
  scroll-padding: 6px;
}

.modal-body p {
  margin: 0 0 12px;
}

.modal-field {
  display: block;
  margin: 0 0 12px;
}

.modal-field label,
.modal-field .modal-label {
  display: block;
  margin-bottom: 4px;
  color: var(--phosphor-dim);
  font-size: 12px;
}

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

.modal-input {
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--phosphor-rule);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--phosphor-echo);
  font: inherit;
  color-scheme: dark;
}

/* The Real Name dialog's one input spans the dialog (trays/real-name.js). */
.real-name-input {
  width: 100%;
}

.modal-input:focus-visible {
  outline: 2px solid var(--phosphor);
  outline-offset: 1px;
}

/* The notes under a control: its help, a date field's live line, its error. The paragraph rule `.modal-body p` above sets
   their margin (0 0 12px; it is more specific than these two classes). */
.modal-help {
  color: var(--phosphor-dim);
  font-size: 12px;
  font-style: italic;
  text-shadow: none;
}

.modal-error {
  color: #ff8a80;
  font-size: 12px;
}

/* The first note under a control sits 4 px below it (owner ruling OR-1, 2026-10-06; it touched the control before), so a
   focused control's outline — 2 px at a 1 px offset, 2 px at 2 px on the checkbox — no longer overlaps the text. The
   control is a text or number input, the row of a date / time (or hour / minute) pair, the checkbox's label, or the file
   picker's row; the rule starts at `.modal-body` to be more specific than `.modal-body p`. Notes after a note keep
   the paragraph spacing. */
.modal-body :is(.modal-input, .modal-row, .modal-check, .modal-file-row) + :is(.modal-help, .modal-error) {
  margin-top: 4px;
}

.modal-actions {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding: 8px 16px 16px;
}

.modal-button {
  padding: 6px 16px;
  border: 1px solid var(--phosphor-rule);
  border-radius: 4px;
  background: transparent;
  color: var(--phosphor);
  font: inherit;
  cursor: pointer;
}

.modal-button:hover {
  background: rgba(156, 255, 156, 0.14);
}

.modal-button--primary {
  border-color: var(--phosphor);
  background: rgba(156, 255, 156, 0.16);
  font-weight: 700;
}

.modal-button--danger {
  border-color: var(--led-red);
  color: #ffb3ad;
}

.modal-button--danger:hover {
  background: rgba(255, 59, 48, 0.18);
}

.modal-form {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  margin: 0;
}

/* The game-datetime field: the date is wider than hour and minute. */
.modal-row .modal-field {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
}

.modal-row .modal-field:first-child {
  flex: 2 1 0;
}

.modal-row .modal-input {
  box-sizing: border-box;
  width: 100%;
}

.modal-input[aria-invalid="true"] {
  border-color: var(--led-red);
}

.modal-button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Form fields (docs/ui-spec.md § Form fields): a text or number input spans the dialog, as the Real Name one
   does; the date and time of a local-datetime field sit in the `.modal-row` above. */
.modal-field > .modal-input {
  box-sizing: border-box;
  width: 100%;
}

/* A paragraph above the fields (`ui.intro`). */
.modal-body p.modal-intro {
  margin: 0 0 14px;
  color: var(--phosphor-echo);
}

/* The page's own line under the fields (kinds/form.js `ctx.formNotes`; Reset World: what becomes of the sandbox settings). */
.modal-body p.modal-outcome {
  margin: 0 0 12px;
  color: var(--phosphor-echo);
  font-size: 13px;
}

/* A console line is typed text: monospace, no ligatures. */
.modal-input--mono {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
  letter-spacing: 0;
}

/* The checkbox field: the box and its label on one line, the whole line the click target. */
.modal-field .modal-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--phosphor);
  font-size: inherit;
  cursor: pointer;
}

.modal-check-box {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--phosphor);
  color-scheme: dark;
}

.modal-check-box:focus-visible {
  outline: 2px solid var(--phosphor);
  outline-offset: 2px;
}

.modal-check-box[aria-invalid="true"] {
  outline: 2px solid var(--led-red);
  outline-offset: 2px;
}

/* The file field: the picker and, once a file is chosen, a Clear button. */
.modal-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-file {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--phosphor-echo);
  font: inherit;
  color-scheme: dark;
}

.modal-file::file-selector-button {
  margin-right: 10px;
  padding: 4px 12px;
  border: 1px solid var(--phosphor-rule);
  border-radius: 4px;
  background: transparent;
  color: var(--phosphor);
  font: inherit;
  cursor: pointer;
}

.modal-file::file-selector-button:hover {
  background: rgba(156, 255, 156, 0.14);
}

.modal-file:focus-visible {
  outline: 2px solid var(--phosphor);
  outline-offset: 1px;
}

.modal-file[aria-invalid="true"] {
  outline: 1px solid var(--led-red);
  outline-offset: 2px;
}

.modal-file-clear {
  flex: none;
  padding: 3px 10px;
}

/* Edit Scheduled Actions (kinds/scheduled-list.js): one button per scheduled item with two lines of text, the
   first one bold; a fired command's row is disabled and says why, with a Delete beside it. The list scrolls
   when there are many (up to 20 sessions and 50 commands). The list is a scroll area, which cuts off whatever is drawn
   outside its padding: the Delete button's focus outline reaches 5 px beyond it (3 px at a 2 px offset; a row's is 3 px),
   so the padding is 6 px, and the margin of -4 px takes the 4 px more back, which leaves the rows where they were. The
   scroll padding keeps the outline of a row that focus scrolls into view from ending at the edge of the area. The cap
   is the old one plus the 8 px by which the vertical padding grew (4 px to 12 px), so a capped list shows what it did. */
.sched-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(min(60vh, 420px) + 8px);
  margin: -4px -4px 8px;
  padding: 6px;
  scroll-padding: 6px;
  overflow-y: auto;
  list-style: none;
}

.sched-item {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.sched-row {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--phosphor-rule);
  border-radius: 4px;
  background: transparent;
  color: var(--phosphor);
  font: inherit;
  text-align: left;
  text-shadow: inherit;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.sched-row:hover {
  background: rgba(156, 255, 156, 0.14);
}

.sched-row:focus-visible {
  outline: 2px solid var(--phosphor);
  outline-offset: 1px;
}

.sched-row[aria-disabled="true"] {
  opacity: 0.75;
  cursor: default;
}

.sched-row[aria-disabled="true"]:hover {
  background: transparent;
}

.sched-line {
  display: block;
}

.sched-line--first {
  font-weight: 700;
}

.sched-note {
  display: block;
  color: var(--phosphor-dim);
  font-size: 12px;
  font-style: italic;
  text-shadow: none;
}

.sched-delete {
  flex: none;
  align-self: center;
}

.modal-body p.sched-empty {
  color: var(--phosphor-dim);
}
