/* Garage door page.  Phone first: one column, one big button, and every
   control at least 44 px tall.  No fonts or files from anywhere else. */

:root {
  color-scheme: light dark;
  --page: #f3f4f6;
  --surface: #ffffff;
  --text: #15191d;
  --muted: #58626d;
  --line: #d5dae0;
  --off: #7b8794;
  --busy: #8a6100;
  --ready: #177245;
  --done: #1b62c9;
  --ask: #8a6100;
  --problem: #b3261e;
  --button-text: #ffffff;
  --shadow: 0 6px 20px rgba(16, 24, 32, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #101316;
    --surface: #1a1f24;
    --text: #eef1f4;
    --muted: #a3adb8;
    --line: #2f373f;
    --off: #8693a0;
    --busy: #e0aa2e;
    --ready: #45b97c;
    --done: #6aa9ff;
    --ask: #e0aa2e;
    --problem: #ff7a70;
    --button-text: #0d1012;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0 max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  background: var(--page);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

h1, h2, p, ol {
  margin: 0;
}

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

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

:focus-visible {
  outline: 3px solid var(--done);
  outline-offset: 3px;
}

/* ---- The bar at the top ---- */

.bar {
  position: relative;
  width: 100%;
  max-width: 440px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: max(10px, env(safe-area-inset-top));
  min-height: 60px;
}

.bar h1 {
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.icon-button {
  width: 48px;
  height: 48px;
  margin-right: -12px;
  border: 0;
  border-radius: 50%;
  background: none;
  font-size: 1.6rem;
  line-height: 1;
}

.icon-button:hover, .icon-button[aria-expanded='true'] {
  background: var(--line);
}

.menu {
  position: absolute;
  z-index: 10;
  top: calc(100% - 4px);
  right: 0;
  min-width: 240px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.menu button {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
}

.menu button:hover {
  background: var(--page);
}

/* ---- The state, always on show ---- */

main {
  width: 100%;
  max-width: 440px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* A little above the middle of the screen: in reach of a thumb. */
  justify-content: center;
  padding: 12px 0 9vh;
}

/* The words above the button and the room below it keep their height, so
   that the button stays where it is from one state to the next. */
.status {
  width: 100%;
  min-height: 196px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

main[data-layout='form'] .status {
  min-height: 0;
}

.below {
  width: 100%;
  min-height: 112px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

main[data-layout='form'] .below {
  display: none;
}

.status[data-tone='off'] { --tone: var(--off); }
.status[data-tone='busy'] { --tone: var(--busy); }
.status[data-tone='ready'] { --tone: var(--ready); }
.status[data-tone='done'] { --tone: var(--done); }
.status[data-tone='ask'] { --tone: var(--ask); }
.status[data-tone='problem'] { --tone: var(--problem); }

.lamp {
  width: 14px;
  height: 14px;
  margin: 6px 0 12px;
  border-radius: 50%;
  background: var(--tone, var(--off));
  /* The second line wins where the browser knows color-mix. */
  box-shadow: 0 0 0 5px rgba(128, 128, 128, 0.2);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--tone, var(--off)) 22%, transparent);
}

.status[data-tone='busy'] .lamp {
  animation: pulse 1.1s ease-in-out infinite;
}

.status h2 {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--tone, var(--text));
}

.status[data-tone='off'] h2 {
  color: var(--text);
}

.status p {
  margin-top: 8px;
  max-width: 34ch;
  color: var(--muted);
  text-wrap: balance;
}

/* ---- The one big button ---- */

.big-button {
  --tone: var(--off);
  position: relative;
  width: min(62vw, 232px);
  aspect-ratio: 1;
  margin: 20px 0 16px;
  padding: 16px;
  border: 0;
  border-radius: 50%;
  background: var(--tone);
  color: var(--button-text);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  box-shadow: var(--shadow), 0 0 0 10px rgba(128, 128, 128, 0.18);
  box-shadow: var(--shadow), 0 0 0 10px color-mix(in srgb, var(--tone) 18%, transparent);
  transition: transform 0.08s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.big-button[data-tone='off'] { --tone: var(--ready); }
.big-button[data-tone='ready'] { --tone: var(--ready); }
.big-button[data-tone='problem'] { --tone: var(--ready); }
.big-button[data-tone='busy'] { --tone: var(--off); }
.big-button[data-tone='done'] { --tone: var(--done); }

.big-button:active:not(:disabled) {
  transform: scale(0.96);
}

.big-button:disabled {
  opacity: 0.85;
}

/* A ring that turns while something is under way. */
.big-button.busy::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 4px solid transparent;
  border-top-color: var(--busy);
  animation: turn 0.9s linear infinite;
}

.hint {
  max-width: 30ch;
  text-align: center;
  text-wrap: balance;
  color: var(--muted);
  font-size: 0.9rem;
}

.link-button {
  min-height: 48px;
  margin-top: 8px;
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--done);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---- Pairing ---- */

.card {
  width: 100%;
  margin-top: 8px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.card ol {
  padding-left: 1.3em;
}

.card li + li {
  margin-top: 8px;
}

.card label {
  display: block;
  margin-top: 18px;
  font-weight: 600;
}

.card input {
  width: 100%;
  min-height: 52px;
  margin-top: 6px;
  padding: 0 14px;
  /* Dark enough to show where to type. */
  border: 2px solid var(--off);
  border-radius: 12px;
  background: var(--page);
  font-size: 1.25rem;
  letter-spacing: 0.03em;
}

.card input:focus {
  border-color: var(--done);
  outline: none;
}

.message {
  margin-top: 12px;
  color: var(--problem);
  font-weight: 550;
}

.message[data-kind='progress'] {
  color: var(--muted);
  font-weight: 400;
}

.wide-button {
  width: 100%;
  min-height: 54px;
  margin-top: 16px;
  border: 0;
  border-radius: 12px;
  background: var(--ready);
  color: var(--button-text);
  font-size: 1.1rem;
  font-weight: 700;
}

.wide-button:disabled {
  background: var(--off);
}

/* ---- Details, for when something is wrong ---- */

.details {
  width: 100%;
  max-width: 440px;
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.details-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.details-head h2 {
  flex: 1;
  font-size: 1rem;
  color: var(--text);
}

.details-head button, .dialog-buttons button, .practice-buttons button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.details pre {
  margin: 12px 0 0;
  padding: 12px;
  max-height: 50vh;
  overflow: auto;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: 12px/1.5 ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---- The question before forgetting ---- */

dialog {
  width: min(92vw, 400px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

dialog h2 {
  font-size: 1.25rem;
}

dialog p {
  margin-top: 10px;
  color: var(--muted);
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.dialog-buttons .danger {
  border-color: var(--problem);
  background: var(--problem);
  color: var(--button-text);
  font-weight: 650;
}

/* ---- The phones the opener knows ---- */

.clients {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.clients li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  border-top: 1px solid var(--line);
}

.clients li:last-child {
  border-bottom: 1px solid var(--line);
}

.clients .name {
  flex: 1;
  overflow-wrap: anywhere;
}

.clients .own {
  color: var(--muted);
  font-size: 0.9rem;
}

.clients button {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--problem);
  border-radius: 10px;
  background: none;
  color: var(--problem);
}

/* ---- Practice mode ---- */

.practice {
  width: 100%;
  max-width: 440px;
  padding: 12px 14px;
  border: 1px dashed var(--ask);
  border-radius: 12px;
  background: var(--surface);
  background: color-mix(in srgb, var(--ask) 10%, var(--surface));
  font-size: 0.85rem;
}

.practice-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.practice-head p {
  flex: 1;
}

.practice-leave {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
}

.practice summary::before {
  content: '\25B8';
  display: inline-block;
  margin-right: 6px;
}

.practice details[open] summary::before {
  content: '\25BE';
}

.practice summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.practice-facts {
  color: var(--muted);
}

.practice-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.practice-buttons button {
  padding: 0 12px;
  font-size: 0.85rem;
}

/* On a narrow phone the words wrap more: keep the room that holds the
   button in place. */
@media (max-width: 359px) {
  .status {
    min-height: 228px;
  }
  .status h2 {
    font-size: 1.6rem;
  }
  .below {
    min-height: 132px;
  }
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

@keyframes turn {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .status[data-tone='busy'] .lamp, .big-button.busy::after {
    animation: none;
  }
  .big-button {
    transition: none;
  }
}
