:root {
  color-scheme: dark;
  --bg-0: #12181e;
  --bg-1: rgba(24, 31, 40, 0.72);
  --bg-2: rgba(36, 45, 55, 0.84);
  --line: rgba(255, 255, 255, 0.16);
  --text-0: #f3f1e8;
  --text-1: rgba(243, 241, 232, 0.76);
  --accent: #d9a441;
  --accent-strong: #f1c76c;
  --danger: #c96d55;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --font-ui: "Avenir Next", "Helvetica Neue", Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(210, 164, 65, 0.22), transparent 32%),
    linear-gradient(180deg, #314252 0%, #202a35 36%, #11181f 100%);
  color: var(--text-0);
  font-family: var(--font-ui);
}

body {
  min-height: 100vh;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  --status-panel-width: min(520px, calc(100vw - 40px));
  --preview-width: 1280;
  --preview-height: 720;
  background:
    radial-gradient(circle at top, rgba(255, 244, 214, 0.05), transparent 32%),
    linear-gradient(180deg, #3c4b5b 0%, #202a35 44%, #11181f 100%);
}

#preview-canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 244, 214, 0.05), rgba(7, 11, 15, 0.2)),
    #394754;
}

.top-bar,
.bottom-bar {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  pointer-events: none;
}

.top-bar {
  top: 0;
  align-items: flex-start;
  z-index: 2;
}

.bottom-bar {
  bottom: 0;
  flex-direction: column;
  z-index: 2;
}

.brand-lockup,
.top-actions,
.mode-control,
.command-row {
  pointer-events: auto;
}

.brand-lockup {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-kicker {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mode-chip {
  margin: 0;
  width: fit-content;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: rgba(27, 35, 44, 0.62);
  font-family: var(--font-display);
  font-size: 1rem;
}

.top-actions,
.command-row,
.live-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.sheet-toggle {
  display: none;
}

.live-actions {
  display: none;
}

.icon-button,
.mode-button,
.primary-button,
.secondary-button {
  min-height: 46px;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.icon-button {
  width: 46px;
  border: 1px solid var(--line);
  background: var(--bg-1);
  color: var(--text-0);
  font-size: 1.3rem;
  box-shadow: var(--shadow);
}

.primary-button,
.secondary-button {
  padding: 0 18px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.primary-button {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #20150a;
  font-weight: 700;
}

.secondary-button {
  background: var(--bg-1);
  color: var(--text-0);
}

.mode-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: min(720px, calc(100vw - 40px));
}

.mode-button {
  border: 1px solid var(--line);
  background: rgba(28, 36, 45, 0.78);
  color: var(--text-0);
  padding: 14px 16px;
  text-align: left;
}

.mode-button.is-active {
  border-color: rgba(241, 199, 108, 0.7);
  background: linear-gradient(180deg, rgba(126, 92, 31, 0.94), rgba(79, 57, 20, 0.94));
}

.mode-label {
  display: block;
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.mode-meta {
  display: block;
  margin-top: 6px;
  color: var(--text-1);
  font-size: 0.78rem;
}

.status-panel {
  position: absolute;
  left: 20px;
  right: auto;
  bottom: 20px;
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 18px;
  width: var(--status-panel-width);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    linear-gradient(180deg, rgba(29, 39, 49, 0.9), rgba(21, 29, 37, 0.94)),
    radial-gradient(circle at top right, rgba(241, 199, 108, 0.1), transparent 28%);
  box-shadow: var(--shadow);
  z-index: 2;
}

.status-copy {
  max-width: 100%;
}

.status-title {
  margin: 6px 0 10px;
  font-family: var(--font-display);
  font-size: clamp(1.65rem, 4vw, 2.7rem);
  font-weight: 500;
}

.status-message {
  margin: 0;
  max-width: 34rem;
  color: var(--text-1);
  font-size: clamp(0.98rem, 1.8vw, 1.08rem);
  line-height: 1.5;
}

.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.app-shell.is-live-camera:not(.has-status) {
  overflow: hidden;
}

.app-shell.is-live-camera:not(.has-status) #preview-canvas {
  width: 100vw;
  height: 100vh;
}

.app-shell.is-live-camera:not(.has-status) .top-bar,
.app-shell.is-live-camera:not(.has-status) .bottom-bar {
  position: absolute;
  left: 0;
  right: 0;
}

.app-shell.is-live-camera:not(.has-status) .top-bar {
  align-items: flex-start;
  background: linear-gradient(180deg, rgba(10, 15, 20, 0.18), rgba(10, 15, 20, 0));
}

.app-shell.is-live-camera:not(.has-status) .bottom-bar {
  bottom: 0;
  align-items: flex-end;
  padding-top: 120px;
  background: linear-gradient(180deg, rgba(10, 15, 20, 0), rgba(10, 15, 20, 0.16) 42%, rgba(10, 15, 20, 0.26));
}

.app-shell.is-live-camera:not(.has-status) .mode-control,
.app-shell.is-live-camera:not(.has-status) .command-row {
  width: min(720px, calc(100vw - 40px));
}

.info-dialog {
  width: min(560px, calc(100vw - 24px));
  padding: 0;
  border: 1px solid rgba(241, 199, 108, 0.18);
  background: rgba(27, 35, 44, 0.96);
  color: var(--text-0);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.5);
}

.info-dialog::backdrop {
  background: rgba(0, 0, 0, 0.52);
}

.info-sheet {
  padding: 22px;
}

.info-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.info-header h2 {
  margin: 8px 0 0;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 500;
}

.info-copy,
.info-disclaimer {
  line-height: 1.6;
}

.info-copy {
  color: var(--text-0);
}

.info-disclaimer {
  color: var(--text-1);
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: default;
  opacity: 0.54;
  transform: none;
}

@media (max-width: 720px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-height: 100vh;
    overflow: auto;
  }

  #preview-canvas {
    width: min(100%, calc(62vh * var(--preview-width) / var(--preview-height)));
    max-width: 100%;
    height: auto;
    min-height: 0;
    max-height: 62vh;
    aspect-ratio: var(--preview-width) / var(--preview-height);
    align-self: center;
    flex: 0 0 auto;
  }

  .top-bar,
  .bottom-bar {
    position: relative;
    padding: 16px;
    gap: 14px;
  }

  .top-bar {
    align-items: center;
    background: rgba(17, 24, 31, 0.78);
    backdrop-filter: blur(10px);
  }

  .bottom-bar {
    order: 3;
    padding-top: 0;
    background: rgba(17, 24, 31, 0.82);
  }

  .mode-control {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .status-title {
    font-size: 2rem;
  }

  .command-row {
    justify-content: stretch;
  }

  .primary-button,
  .secondary-button {
    flex: 1 1 180px;
  }

  .status-panel {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    width: auto;
    margin: 0 16px 16px;
    order: 2;
    padding: 18px;
  }

  .app-shell.has-status .bottom-bar {
    left: auto;
    right: auto;
  }

  .brand-lockup {
    gap: 6px;
  }

  .top-actions {
    flex: 0 0 auto;
  }

  .mode-chip {
    max-width: calc(100vw - 140px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .status-actions,
  .command-row {
    width: 100%;
  }

  .command-row {
    justify-content: stretch;
  }

  .command-row .primary-button,
  .status-actions .primary-button,
  .status-actions .secondary-button {
    width: 100%;
  }

  .status-actions {
    flex-direction: column;
  }

  .info-dialog {
    width: calc(100vw - 16px);
  }

  .info-sheet {
    padding: 18px;
  }

  .app-shell.is-live-camera:not(.has-status) {
    display: block;
    overflow: hidden;
  }

  .app-shell.is-live-camera:not(.has-status) #preview-canvas {
    width: min(100vw, calc(100dvh * var(--preview-width) / var(--preview-height)));
    height: min(100dvh, calc(100vw * var(--preview-height) / var(--preview-width)));
    max-width: 100vw;
    max-height: 100dvh;
    min-height: 0;
    aspect-ratio: var(--preview-width) / var(--preview-height);
    margin: 0 auto;
    align-self: center;
  }

  .app-shell.is-live-camera:not(.has-status) .top-bar,
  .app-shell.is-live-camera:not(.has-status) .bottom-bar {
    position: absolute;
    left: 0;
    right: 0;
  }

  .app-shell.is-live-camera:not(.has-status) .top-bar {
    top: 0;
    align-items: center;
    justify-content: flex-start;
    padding: 16px;
    background: linear-gradient(180deg, rgba(10, 15, 20, 0.22), rgba(10, 15, 20, 0));
    backdrop-filter: none;
  }

  .app-shell.is-live-camera:not(.has-status) .top-actions {
    display: none;
  }

  .app-shell.is-live-camera:not(.has-status) .bottom-bar {
    bottom: 0;
    display: grid;
    gap: 10px;
    padding: 0 12px calc(12px + env(safe-area-inset-bottom, 0px));
    background: none;
    transform: translateY(calc(100% - 60px));
    transition: transform 180ms ease;
  }

  .app-shell.is-live-camera:not(.has-status).controls-open .bottom-bar {
    transform: translateY(0);
  }

  .app-shell.is-live-camera:not(.has-status) .sheet-toggle {
    display: grid;
    justify-items: center;
    gap: 8px;
    width: calc(100vw - 24px);
    padding: 12px 16px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(17, 24, 31, 0.9);
    color: var(--text-0);
    box-shadow: var(--shadow);
  }

  .app-shell.is-live-camera:not(.has-status) .live-actions {
    display: flex;
    width: calc(100vw - 24px);
    justify-content: flex-end;
  }

  .sheet-grabber {
    width: 44px;
    height: 4px;
    border-radius: 999px;
    background: rgba(243, 241, 232, 0.36);
  }

  .sheet-toggle-label {
    font-size: 0.84rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .app-shell.is-live-camera:not(.has-status) .mode-control,
  .app-shell.is-live-camera:not(.has-status) .command-row {
    width: calc(100vw - 24px);
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(17, 24, 31, 0.92);
    box-shadow: var(--shadow);
  }

  .app-shell.is-live-camera:not(.has-status) .mode-control {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .app-shell.is-live-camera:not(.has-status) .mode-button {
    padding: 12px 14px;
  }

  .app-shell.is-live-camera:not(.has-status) .command-row,
  .app-shell.is-live-camera:not(.has-status) .command-row .primary-button {
    width: 100%;
  }

  .app-shell.is-live-camera:not(.has-status) .command-row {
    justify-content: stretch;
  }

}

.app-shell.has-status {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: auto;
}

.app-shell.has-status #preview-canvas {
  order: 2;
  width: min(100%, calc(clamp(240px, 42vh, 420px) * var(--preview-width) / var(--preview-height)));
  max-width: 100%;
  height: auto;
  min-height: 0;
  max-height: clamp(240px, 42vh, 420px);
  aspect-ratio: var(--preview-width) / var(--preview-height);
  align-self: center;
  flex: 0 0 auto;
}

.app-shell.has-status .top-bar,
.app-shell.has-status .status-panel,
.app-shell.has-status .bottom-bar {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  width: min(720px, calc(100vw - 40px));
  margin: 0 auto;
}

.app-shell.has-status .top-bar {
  order: 1;
  align-items: center;
  padding: 20px;
  background: rgba(17, 24, 31, 0.82);
  backdrop-filter: blur(10px);
}

.app-shell.has-status .status-panel {
  order: 3;
  gap: 14px;
  margin-top: 16px;
  padding: 20px;
}

.app-shell.has-status .status-actions {
  width: 100%;
}

.app-shell.has-status .bottom-bar {
  order: 4;
  padding: 16px 0 20px;
  background: transparent;
}

.app-shell.has-status .mode-control {
  width: 100%;
}

.app-shell.has-status .command-row {
  width: 100%;
}

@media (max-width: 720px) {
  .app-shell.has-status .top-bar,
  .app-shell.has-status .status-panel,
  .app-shell.has-status .bottom-bar {
    width: calc(100vw - 32px);
  }

  .app-shell.has-status .top-bar {
    padding: 16px;
  }

  .app-shell.has-status .status-panel {
    margin-top: 0;
    margin-bottom: 12px;
    padding: 18px;
  }

  .app-shell.has-status #preview-canvas {
    width: min(100%, calc(clamp(220px, 34vh, 320px) * var(--preview-width) / var(--preview-height)));
    max-height: clamp(220px, 34vh, 320px);
  }

  .app-shell.has-status .status-actions {
    flex-direction: row;
    align-items: stretch;
    gap: 10px;
  }

  .app-shell.has-status .status-actions .primary-button,
  .app-shell.has-status .status-actions .secondary-button {
    flex: 1 1 0;
    width: auto;
  }

  .app-shell.has-status .bottom-bar {
    padding-top: 0;
  }

  .app-shell.has-status .mode-control {
    gap: 8px;
  }

  .app-shell.has-status .mode-button {
    padding: 12px 14px;
  }
}
