/* Pixel components: window, title bar, buttons, text field, list rows and messages. */

[hidden] {
  display: none !important;
}

.window,
.btn,
.field {
  border: var(--border) solid var(--ink);
  border-image: url("../sprites/frame.png") 1 / var(--border) stretch;
  background-clip: padding-box;
  image-rendering: pixelated;
}

/* ---- window ------------------------------------------------------------------------- */

.window {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  background-color: var(--paper);
  color: var(--ink);
  font: var(--fs-text) / var(--lh-text) var(--font-text);
  /* A drop shadow follows the stepped corners; box-shadow would fill the notches. */
  filter: drop-shadow(var(--shadow) var(--shadow) 0 var(--ink));
}

dialog.window:not([open]) {
  display: none;
}

dialog.window {
  margin: auto;
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: visible;
}

dialog.window::backdrop {
  background: rgba(26, 28, 44, 0.75);
}

.window-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 8px 16px;
  background: var(--action);
  color: var(--paper);
  font: var(--fs-title) / var(--lh-title) var(--font-title);
  margin: 0;
}

.window-title h2 {
  margin: 0;
  font: inherit;
}

.window-body {
  padding: 16px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.window-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
}

@keyframes pop {
  from {
    transform: translateY(8px);
  }
  to {
    transform: translateY(0);
  }
}

dialog.window[open],
.panel:not([hidden]) {
  animation: pop 160ms steps(2) both;
}

/* ---- buttons ------------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  min-height: 44px;
  background-color: var(--paper);
  color: var(--ink);
  font: var(--fs-text) / var(--lh-text) var(--font-text);
  cursor: url("../sprites/cursor-hand.png") 16 0, pointer;
  filter: drop-shadow(var(--shadow) var(--shadow) 0 var(--ink));
  user-select: none;
  -webkit-user-select: none;
}

.btn:active:not(:disabled) {
  transform: translate(var(--shadow), var(--shadow));
  filter: none;
}

.btn-primary {
  background-color: var(--highlight);
  color: var(--ink);
}

.btn-secondary {
  background-color: var(--action);
  color: var(--paper);
}

.btn-success {
  background-color: var(--success);
  color: var(--ink);
}

.btn-danger {
  background-color: var(--danger);
  color: var(--paper);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  background-color: var(--muted);
  color: var(--ink);
  cursor: not-allowed;
  filter: none;
}

.btn-small {
  min-height: 32px;
  padding: 0 8px;
  font-size: var(--fs-small);
  line-height: var(--lh-small);
}

.btn-close {
  min-height: 32px;
  min-width: 32px;
  padding: 0;
  font-family: var(--font-title);
  font-size: 16px;
  line-height: 24px;
}

.btn:focus-visible,
.field:focus-visible,
.row:focus-visible,
.stat:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 4px;
}

.badge {
  display: inline-block;
  min-width: 28px;
  padding: 0 8px;
  background: var(--highlight);
  color: var(--ink);
  text-align: center;
}

.link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--action);
  text-decoration: underline;
  cursor: url("../sprites/cursor-hand.png") 16 0, pointer;
}

/* ---- text fields -------------------------------------------------------------------- */

.field {
  width: 100%;
  min-height: 44px;
  padding: 4px 8px;
  background-color: var(--paper);
  color: var(--ink);
  font: var(--fs-text) / var(--lh-text) var(--font-text);
  box-shadow: inset 4px 4px 0 var(--muted);
  border-radius: 0;
}

select.field {
  appearance: none;
  -webkit-appearance: none;
}

.label {
  display: block;
  font: var(--fs-small) / var(--lh-small) var(--font-text);
  margin-bottom: 4px;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form .label {
  margin-top: 4px;
}

/* ---- list rows ---------------------------------------------------------------------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  border: 4px solid var(--ink);
  overflow: auto;
  min-height: 0;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 4px 12px;
  border: 0;
  border-bottom: 4px solid var(--muted);
  background: var(--paper);
  color: var(--ink);
  font: var(--fs-text) / var(--lh-text) var(--font-text);
  text-align: left;
  cursor: url("../sprites/cursor-hand.png") 16 0, pointer;
}

.list > li:last-child > .row,
.list > .row:last-child {
  border-bottom: 0;
}

.row:hover {
  background: var(--muted);
}

.row[aria-pressed="true"],
.row.is-selected {
  background: var(--highlight);
}

.row-static {
  cursor: default;
}

.row-static:hover {
  background: var(--paper);
}

/* ---- messages ----------------------------------------------------------------------- */

.msg {
  margin: 0;
  padding: 8px 12px;
  border: 4px solid var(--ink);
  background: var(--muted);
  color: var(--ink);
}

.msg-error {
  background: var(--danger);
  color: var(--paper);
}

.msg-ok {
  background: var(--success);
  color: var(--ink);
}

.hint {
  margin: 0;
  font-size: var(--fs-small);
  line-height: var(--lh-small);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tabs .btn[aria-selected="true"] {
  background-color: var(--highlight);
}

@media (prefers-reduced-motion: reduce) {
  dialog.window[open],
  .panel:not([hidden]),
  .toast {
    animation: none !important;
  }
}

@media (max-width: 640px) {
  /* On phones every window fills the screen. */
  dialog.window {
    margin: 0;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-image: none;
    border-width: 0;
    filter: none;
  }

  dialog.window .window-body {
    flex: 1;
  }
}
