/* The TV's own look on a phone: its navy, blue tiles, yellow focus and Inter (dashboard/theme.rs). */
@font-face {
  font-family: "Inter";
  src: url("/tiles/inter-semibold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}

:root {
  --background: #041e42;
  --panel: #102a55;
  --panel-raised: #17366b;
  --tile: #0071dc;
  --focus: #ffc220;
  --text: #ffffff;
  --muted: #a9c7ec;
  --line: #24467e;
  --good: #4ade80;
  --bad: #f87171;
  --radius: 14px;
  --gap: 12px;
  --pad: 16px;
  --tap: 48px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--background);
  color: var(--text);
  font: 600 16px/1.35 "Inter", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

.icon,
.tile-icon,
.preview-icon,
.picker-chevron {
  display: grid;
  width: 22px;
  height: 22px;
}

.icon svg,
.tile-icon svg,
.preview-icon svg,
.picker-chevron svg {
  width: 100%;
  height: 100%;
}

/* --- Bar -------------------------------------------------------------------------------------- */

.bar {
  display: grid;
  grid-template-columns: var(--tap) minmax(0, 1fr) var(--tap);
  align-items: center;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.bar-title {
  grid-column: 2;
  margin: 0;
  font-size: 19px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-back,
.bar-history,
.icon-button {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.bar-back {
  grid-column: 1;
}

.bar-history {
  grid-column: 3;
}

.bar-back[hidden],
.bar-history[hidden],
.icon-button[hidden] {
  display: none;
}

.bar-back:active,
.bar-history:active,
.icon-button:active {
  background: var(--panel-raised);
}

/* --- Screen ----------------------------------------------------------------------------------- */

.screen {
  display: grid;
  align-content: start;
  gap: calc(var(--gap) * 1.5);
  padding: var(--pad) var(--pad) calc(var(--pad) * 2);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  margin: 0;
  padding: 0;
  list-style: none;
}

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

.tile-open {
  display: grid;
  grid-template-rows: 1fr auto auto;
  align-items: end;
  justify-items: start;
  gap: 4px;
  width: 100%;
  aspect-ratio: 16 / 10;
  padding: 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--tile-color, var(--tile));
  text-align: left;
  cursor: pointer;
}

.tile-open:active {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.tile-icon {
  align-self: start;
  width: 28px;
  height: 28px;
  color: var(--focus);
}

.tile-title {
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.tile-kind {
  font-size: 12px;
  color: rgb(255 255 255 / 0.75);
}

/* --- Buttons ---------------------------------------------------------------------------------- */

.button,
.picker,
.choice {
  display: grid;
  grid-auto-flow: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
}

.button:active,
.picker:active,
.choice:active {
  background: var(--panel-raised);
}

.button:disabled {
  opacity: 0.45;
  cursor: default;
}

.button-wide {
  width: 100%;
}

.button-primary {
  background: var(--tile);
  border-color: var(--tile);
}

.button-danger {
  color: var(--bad);
}

.picker,
.choice {
  grid-template-columns: auto minmax(0, 1fr) auto;
  justify-content: stretch;
  width: 100%;
  text-align: left;
}

.picker > span:nth-child(2),
.choice > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-chevron {
  color: var(--muted);
}

/* --- Tile form -------------------------------------------------------------------------------- */

.form,
.group {
  display: grid;
  gap: var(--gap);
}

.group-title {
  margin: var(--gap) 0 0;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: var(--gap);
}

.actions .button > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview {
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: start;
  width: min(100%, 240px);
  aspect-ratio: 16 / 10;
  margin: 6px 0 4px;
  justify-self: center;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--tile-color, var(--tile));
  outline: 4px solid var(--focus);
  outline-offset: 4px;
}

.preview-icon {
  width: 40px;
  height: 40px;
  color: var(--icon-color, var(--focus));
}

.preview-title {
  font-size: 22px;
}

.field {
  display: grid;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  color: var(--muted);
}

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 16px;
}

.input:focus,
.color-input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.input-lines {
  resize: vertical;
}

.color {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.color-input {
  width: 100%;
  height: var(--tap);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-input::-webkit-color-swatch {
  border: 0;
  border-radius: calc(var(--radius) - 1px);
}

.color-input::-moz-color-swatch {
  border: 0;
  border-radius: calc(var(--radius) - 1px);
}

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

.note {
  margin: 0;
  color: var(--muted);
}

.note-bad {
  color: var(--bad);
}

.link {
  color: var(--focus);
}

/* --- Sheet ------------------------------------------------------------------------------------ */

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--panel);
  color: var(--text);
}

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

.sheet-body {
  display: grid;
  gap: var(--gap);
  padding: var(--pad) var(--pad) calc(env(safe-area-inset-bottom) + var(--pad));
}

.sheet-title {
  margin: 0;
  font-size: 18px;
}

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

.choice[aria-current="true"],
.icon-choice[aria-current="true"] {
  border-color: var(--focus);
  box-shadow: inset 0 0 0 1px var(--focus);
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.icon-choice {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--background);
  color: var(--focus);
  cursor: pointer;
}

.icon-choice .icon {
  width: 28px;
  height: 28px;
}

.icon-none {
  font-size: 12px;
  color: var(--muted);
}

/* --- Status ----------------------------------------------------------------------------------- */

.status {
  min-height: 0;
  padding: 0 var(--pad) env(safe-area-inset-bottom);
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.status-text {
  display: block;
  padding: 10px 0;
}

.status[data-state="idle"] {
  display: none;
}

.status[data-state="busy"] {
  color: var(--muted);
}

.status[data-state="good"] {
  color: var(--good);
}

.status[data-state="bad"] {
  color: var(--bad);
}
