:root {
  color-scheme: light;
  --page: #f3f0ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #151515;
  --muted: #77716b;
  --line: #ded8cf;
  --accent: #117a72;
  --accent-strong: #0b625c;
  --coral: #d75f47;
  --dark: #111111;
  --paper: #fbf7ef;
  --card-ink: #171717;
  --red: #c82432;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.is-performing {
  overflow: hidden;
  background: #000000;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100svh;
}

.setup-view {
  width: min(1040px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--dark);
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0;
  flex: 0 0 auto;
}

.app-header h1,
.remote-header h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.1;
}

.app-header p,
.remote-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.header-button,
.tool-button,
.start-button,
.reset-button {
  min-height: 42px;
  border-radius: 12px;
  padding: 0 16px;
  display: inline-grid;
  place-items: center;
  text-decoration: none;
  font-weight: 700;
}

.header-button,
.tool-button,
.reset-button {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}

.start-button {
  min-width: 128px;
  min-height: 50px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 12px 28px rgba(17, 122, 114, 0.24);
}

.main-stage-card {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 12px;
}

.device-shell {
  min-height: 0;
  display: grid;
  place-items: center;
}

.preview-stage {
  width: min(100%, 410px);
  height: min(64svh, 730px);
  min-height: 430px;
  border: 10px solid #101010;
  border-radius: 34px;
  background: #101820;
  overflow: hidden;
  box-shadow: 0 30px 60px rgba(25, 20, 15, 0.24);
}

.stage-actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
}

.stage-actions.single-action {
  grid-template-columns: 1fr;
  justify-items: center;
}

.stage-actions .tool-button {
  min-height: 50px;
}

.stage-actions.single-action .start-button {
  width: min(100%, 340px);
}

.start-button:disabled {
  background: #918a80;
  box-shadow: none;
  cursor: not-allowed;
}

.screenshot-row,
.import-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.screenshot-button {
  min-height: 50px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: #171717;
  font-weight: 800;
  overflow: hidden;
  position: relative;
}

.screenshot-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.object-import-button {
  background: var(--accent);
}

.wallpaper-import-button {
  min-height: 58px;
}

.status-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.room-field {
  max-width: 240px;
}

.control-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(35, 28, 20, 0.08);
  overflow: hidden;
}

.tab-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 8px;
  gap: 6px;
  background: #ebe5db;
}

.tab-button {
  min-height: 40px;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.tab-button.is-active {
  color: var(--ink);
  background: var(--surface-strong);
}

.settings-panel {
  padding: 14px;
}

.panel-section {
  display: grid;
  gap: 14px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.segmented label,
.toggle-row label {
  position: relative;
  min-width: 0;
}

.segmented input,
.toggle-row input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented span,
.toggle-row span {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #faf7f1;
  font-weight: 800;
  user-select: none;
}

.segmented input:checked + span,
.toggle-row input:checked + span {
  color: #ffffff;
  border-color: var(--accent);
  background: var(--accent);
}

.setting-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.select-field,
.file-field,
.range-stack label,
.remote-slider {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.select-field span,
.file-field span,
.range-stack span,
.remote-slider span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

select,
input[type="text"],
input[type="file"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: #faf7f1;
  padding: 0 12px;
}

input[type="file"] {
  padding: 10px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.range-stack {
  display: grid;
  gap: 12px;
}

.toggle-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.sensor-button {
  width: 100%;
  min-height: 46px;
  background: #171717;
  color: #ffffff;
  border-color: #171717;
}

.calibration-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #faf7f1;
}

.range-heading {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.range-heading span,
.range-heading output {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.range-heading output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.calibration-panel input[type="range"] {
  min-width: 0;
}

.compact-tool-button {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 0.82rem;
}

.reset-button {
  width: 100%;
  margin-top: 14px;
  color: var(--coral);
}

.stage-view {
  position: fixed;
  top: 0;
  right: 0;
  bottom: -260px;
  left: 0;
  background: #000000;
  overflow: hidden;
}

.stage {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.stage *,
.stage-view * {
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.stage img,
.stage-view img {
  pointer-events: none;
  -webkit-user-drag: none;
  user-drag: none;
}

.performance-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: auto;
  min-height: 0;
  background: #000000;
}

.stage-background {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #111820;
}

.bg-missing {
  display: grid;
  place-items: center;
  background: #101010;
}

.missing-wallpaper {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.95rem;
  font-weight: 800;
}

.bg-home {
  background:
    radial-gradient(circle at 18% 12%, #2f7b70 0 9%, transparent 10%),
    radial-gradient(circle at 82% 18%, #8c3c44 0 8%, transparent 9%),
    linear-gradient(145deg, #10202b, #151821 45%, #28313c);
}

.home-screen {
  position: absolute;
  inset: 0;
  padding: max(20px, env(safe-area-inset-top)) 16px 28px;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  color: rgba(255, 255, 255, 0.84);
  font-size: 0.78rem;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px 16px;
  margin-top: 34px;
}

.fake-icon {
  aspect-ratio: 1;
  border-radius: 22%;
  background: var(--icon-color, #4b7ec7);
  box-shadow: inset 0 -14px 24px rgba(0, 0, 0, 0.18);
}

.dock {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  padding: 12px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(12px);
}

.bg-notes {
  color: #1b1a17;
  background: #f7f1df;
}

.note-page {
  position: absolute;
  inset: 0;
  padding: max(38px, env(safe-area-inset-top)) 24px 24px;
  background:
    repeating-linear-gradient(to bottom, transparent 0 34px, rgba(90, 96, 120, 0.17) 35px 36px),
    #f7f1df;
}

.note-line {
  height: 18px;
  margin: 18px 0;
  border-radius: 5px;
  background: rgba(36, 41, 48, 0.12);
}

.note-line:nth-child(2) {
  width: 78%;
}

.note-line:nth-child(3) {
  width: 62%;
}

.note-line:nth-child(4) {
  width: 88%;
}

.bg-dark {
  background: #050607;
}

.custom-background {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}

.magic-object {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: 168px;
  will-change: transform, opacity;
  transition: transform 180ms ease-out, opacity 120ms ease-out;
  pointer-events: none;
}

.magic-object.object-card {
  width: 168px;
}

.magic-object.object-coin {
  width: 142px;
}

.magic-object.object-bill {
  width: 222px;
}

.magic-object.object-custom {
  width: auto;
}

.stage.is-dragging .magic-object {
  transition: none;
}

.card-face {
  width: 100%;
  height: 100%;
  aspect-ratio: 63 / 89;
  border-radius: 10px;
  background: var(--paper);
  color: var(--card-ink);
  border: 1px solid rgba(0, 0, 0, 0.18);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.34);
  position: relative;
  overflow: hidden;
}

.card-face.red {
  color: var(--red);
}

.card-corner {
  position: absolute;
  left: 12px;
  top: 10px;
  display: grid;
  justify-items: center;
  font-weight: 900;
  line-height: 0.92;
  font-size: 1.4rem;
}

.card-corner.bottom {
  left: auto;
  top: auto;
  right: 12px;
  bottom: 10px;
  transform: rotate(180deg);
}

.card-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 4.8rem;
}

.coin-face {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  color: #3b2908;
  background:
    radial-gradient(circle at 36% 30%, #ffe69f 0 9%, transparent 10%),
    radial-gradient(circle at 50% 50%, #e7c15c 0 54%, #a67b22 55% 69%, #f3d479 70% 100%);
  border: 5px solid #b68a26;
  box-shadow: 0 16px 35px rgba(0, 0, 0, 0.38);
  font-weight: 900;
  font-size: 2.1rem;
}

.coin-face::after {
  content: "";
  position: absolute;
  width: 76%;
  height: 76%;
  border-radius: 50%;
  border: 2px dashed rgba(74, 50, 10, 0.4);
}

.bill-face {
  width: 100%;
  aspect-ratio: 2.12;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #134236;
  background:
    linear-gradient(90deg, rgba(20, 92, 73, 0.18), transparent 28%, transparent 72%, rgba(20, 92, 73, 0.18)),
    #e7efe4;
  border: 2px solid #7cab94;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
  font-weight: 900;
  font-size: 1.7rem;
}

.custom-object {
  width: 100%;
  max-width: none;
  max-height: none;
  display: block;
  filter: drop-shadow(0 16px 30px rgba(0, 0, 0, 0.45));
}

.card-image {
  height: 100%;
  object-fit: fill;
  user-select: none;
}

.exit-hotspot {
  position: absolute;
  z-index: 5;
  top: env(safe-area-inset-top);
  left: 0;
  width: 76px;
  height: 76px;
  background: transparent;
}

.remote-view {
  min-height: 100svh;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  background: #111111;
  color: #ffffff;
}

.remote-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.remote-header p {
  color: #aaa29a;
}

.remote-header input {
  width: 130px;
  min-height: 44px;
  border: 1px solid #373737;
  border-radius: 12px;
  color: #ffffff;
  background: #1c1c1c;
  padding: 0 12px;
}

.remote-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.remote-grid button {
  min-height: 120px;
  border-radius: 16px;
  background: #202020;
  color: #ffffff;
  border: 1px solid #373737;
  font-size: 1.4rem;
  font-weight: 800;
}

.remote-slider {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid #373737;
  border-radius: 16px;
  background: #181818;
}

[hidden] {
  display: none !important;
}

@media (min-width: 860px) {
  .setup-view {
    grid-template-columns: minmax(420px, 1fr) 390px;
    grid-template-rows: auto minmax(0, 1fr);
    align-items: start;
  }

  .app-header {
    grid-column: 1 / -1;
  }

  .main-stage-card,
  .control-panel {
    align-self: stretch;
  }

  .control-panel {
    position: sticky;
    top: 14px;
  }

  .preview-stage {
    height: min(74svh, 760px);
  }
}

@media (max-width: 520px) {
  .setup-view {
    padding-left: 10px;
    padding-right: 10px;
  }

  .preview-stage {
    width: min(100%, 360px);
    min-height: 390px;
    height: 58svh;
    border-width: 8px;
    border-radius: 30px;
  }

  .setting-grid,
  .toggle-row {
    grid-template-columns: 1fr;
  }

  .segmented {
    grid-template-columns: repeat(2, 1fr);
  }

  .stage-actions {
    grid-template-columns: 1fr 1.2fr 1fr;
  }

  .screenshot-row,
  .import-row {
    grid-template-columns: 1fr;
  }

  .start-button,
  .stage-actions .tool-button {
    padding-inline: 10px;
  }
}
