/*-----------------------
  Base
------------------------*/

:root {
  --ground: #17111f;
  --raised: #2a2136;
  --line: #4a3d5c;
  --text: #f7f0e8;
  --muted: #b9abc9;
  --face-a: #ff7a59;
  --face-b: #38d6c4;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  height: 100%;
  background: var(--ground);
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "topbar" "stage" "controls";
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--ground);
  color: var(--text);
  font: 500 16px/1.4 ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1,
p {
  margin: 0;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible,
.btn:focus-within:has(:focus-visible) {
  outline: 3px solid var(--face-b);
  outline-offset: 2px;
}


/*-----------------------
  Top bar
------------------------*/

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 8px 6px 16px;
}


/* Face count
--------------------*/

.faces {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.faces .dot {
  width: 12px;
  height: 12px;
  border: 2px solid var(--line);
  border-radius: 50%;
}

.faces .dot-b {
  margin-right: 4px;
}

.faces[data-count="1"] .dot-a,
.faces[data-count="2"] .dot-a {
  border-color: var(--face-a);
  background: var(--face-a);
}

.faces[data-count="2"] .dot-b {
  border-color: var(--face-b);
  background: var(--face-b);
}


/* Tools
--------------------*/

.tools {
  display: flex;
}

.tool {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}

.tool[aria-pressed="true"],
.tool[aria-expanded="true"] {
  background: var(--raised);
  color: var(--text);
}


/*-----------------------
  Stage
------------------------*/

.stage {
  grid-area: stage;
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}

#video {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}


/* Picture
--------------------*/

.picture {
  position: relative;
}

.picture canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

body[data-mode="home"] .picture {
  visibility: hidden;
}


/* Still
--------------------*/

.still {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--ground);
}


/* Messages
--------------------*/

.hint,
.stats {
  position: absolute;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgb(23 17 31 / 0.82);
  pointer-events: none;
}

.hint {
  bottom: 12px;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 24px);
  transform: translateX(-50%);
  text-align: center;
}

.stats {
  top: 8px;
  left: 8px;
  color: var(--muted);
  font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre;
}


/* Settings
--------------------*/

.settings {
  position: absolute;
  top: 4px;
  right: 8px;
  display: grid;
  gap: 4px;
  width: min(300px, calc(100% - 16px));
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--raised);
}

.setting {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 44px;
  font-size: 15px;
}

.setting output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.setting input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  height: 32px;
  margin: 0;
  accent-color: var(--face-a);
}

.setting input[type="checkbox"] {
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--face-a);
}


/*-----------------------
  Home
------------------------*/

.home {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 16px;
  padding: 24px;
  overflow-y: auto;
  text-align: center;
}

.home h1 {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.home-text {
  max-width: 34ch;
  color: var(--muted);
  text-wrap: balance;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
}


/* Logo
--------------------*/

.logo {
  flex: 0 1 auto;
  width: min(240px, 62vw);
  min-height: 0;
  max-height: 40vh;
  object-fit: contain;
}


/* Loader
--------------------*/

.swap {
  position: relative;
  flex: none;
  width: 40px;
  height: 24px;
}

.swap .dot {
  position: absolute;
  top: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.swap .dot-a {
  left: 0;
  background: var(--face-a);
  animation: swap-right 1.6s ease-in-out infinite alternate;
}

.swap .dot-b {
  left: 16px;
  background: var(--face-b);
  mix-blend-mode: screen;
  animation: swap-left 1.6s ease-in-out infinite alternate;
}

@keyframes swap-right {
  to {
    transform: translateX(16px);
  }
}

@keyframes swap-left {
  to {
    transform: translateX(-16px);
  }
}


/*-----------------------
  Controls
------------------------*/

.controls {
  grid-area: controls;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  gap: 12px;
  min-height: 104px;
  padding: 10px 12px;
}

body[data-mode="frozen"] .controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}


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

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 48px;
  padding: 8px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--raised);
  color: var(--text);
  font: inherit;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  background: var(--line);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  border-color: var(--face-a);
  background: var(--face-a);
  color: #2b0f06;
  font-weight: 650;
}

.btn-primary:active {
  background: #ff9478;
}

body:not([data-mode="frozen"]) .controls .btn {
  flex-direction: column;
  gap: 2px;
  min-height: 56px;
  padding: 6px 10px;
  border-color: transparent;
  border-radius: 16px;
  background: none;
  font-size: 13px;
  line-height: 1.2;
}

body:not([data-mode="frozen"]) .controls .btn:active {
  background: var(--raised);
}


/* File input */

.file {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
}


/* Shutter */

.shutter {
  position: relative;
  width: 78px;
  height: 78px;
  padding: 0;
  border: 4px solid var(--text);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.shutter::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: linear-gradient(90deg, var(--face-a) 50%, var(--face-b) 50%);
  transition: transform 0.12s;
}

.shutter:active::before {
  transform: scale(0.88);
}


/*-----------------------
  Adaptations
------------------------*/


/* Landscape phone
--------------------*/

@media (orientation: landscape) and (max-height: 520px) {
  body {
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "topbar stage controls";
  }

  .topbar {
    flex-direction: column;
    padding: 12px 8px;
  }

  .tools {
    flex-direction: column;
  }

  .controls {
    grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-columns: auto;
    min-width: 116px;
    padding: 8px;
  }

  body[data-mode="frozen"] .controls {
    flex-direction: column;
    flex-wrap: nowrap;
    width: 148px;
  }

  .settings {
    max-height: calc(100% - 8px);
    overflow-y: auto;
  }

  .home {
    gap: 10px;
    padding: 12px;
  }
}


/* Reduced motion
--------------------*/

@media (prefers-reduced-motion: reduce) {
  .swap .dot {
    animation-duration: 6s;
  }

  .shutter::before {
    transition: none;
  }
}
