:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #05070c;
  color: #fff;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05070c;
}

button,
input,
label {
  font: inherit;
}

button,
label {
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* Welcome */
.welcome-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 12%, rgba(72, 107, 255, 0.22), transparent 32rem),
    #05070c;
}

.welcome-card {
  width: min(420px, 100%);
  text-align: center;
}

.logo-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  font-size: 28px;
  background: linear-gradient(145deg, #4f7cff, #795cff);
  box-shadow: 0 18px 50px rgba(79, 124, 255, 0.28);
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(1.9rem, 8vw, 2.6rem);
}

.welcome-card > p {
  margin: 0 0 30px;
  color: #aab3c5;
  line-height: 1.5;
}

.choice-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
  padding: 17px 18px;
  color: #fff;
  text-align: left;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  background: rgba(255,255,255,.06);
}

.choice-button.primary {
  border-color: rgba(99, 142, 255, .55);
  background: linear-gradient(145deg, rgba(60, 102, 225, .94), rgba(93, 74, 205, .94));
}

.choice-icon {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 14px;
  font-size: 24px;
  background: rgba(255,255,255,.12);
}

.choice-button strong,
.choice-button small {
  display: block;
}

.choice-button strong {
  font-size: 1rem;
}

.choice-button small {
  margin-top: 3px;
  color: rgba(255,255,255,.68);
}

/* Viewer */
.viewer-screen {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
}

#resultCanvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
  touch-action: manipulation;
}

.top-overlay {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 12px 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,.72), rgba(0,0,0,0));
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  font-size: 20px;
  background: rgba(15, 18, 27, .72);
  backdrop-filter: blur(14px);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 15px;
  background: rgba(15, 18, 27, .72);
  backdrop-filter: blur(14px);
}

.mode-tab {
  min-width: 0;
  padding: 10px 7px;
  border: 0;
  border-radius: 11px;
  color: #bfc7d7;
  font-size: 0.82rem;
  font-weight: 700;
  background: transparent;
}

.mode-tab.active {
  color: #fff;
  background: linear-gradient(145deg, #4778f5, #7259dc);
}

.freeze-hint,
.frozen-banner {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 40px);
  padding: 10px 14px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: .9rem;
  color: #fff;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.frozen-banner {
  background: rgba(54, 91, 211, .88);
}

.bottom-overlay {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 16px max(14px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  background: linear-gradient(to top, rgba(0,0,0,.72), rgba(0,0,0,0));
}

.bottom-button {
  min-width: 160px;
  padding: 14px 20px;
  border: 0;
  border-radius: 16px;
  color: #fff;
  font-weight: 700;
  background: rgba(15, 18, 27, .82);
  backdrop-filter: blur(14px);
}

.bottom-button:disabled {
  opacity: .45;
}

/* Drawer */
.drawer-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  background: rgba(0,0,0,.48);
}

.drawer {
  position: fixed;
  z-index: 21;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(82vh, 760px);
  overflow-y: auto;
  padding: 10px 18px max(24px, env(safe-area-inset-bottom));
  border-radius: 24px 24px 0 0;
  background: #111722;
  transform: translateY(105%);
  transition: transform .28s ease;
  box-shadow: 0 -24px 80px rgba(0,0,0,.5);
}

.drawer.open {
  transform: translateY(0);
}

.drawer-handle {
  width: 44px;
  height: 5px;
  margin: 0 auto 14px;
  border-radius: 999px;
  background: #3b4351;
}

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

.drawer-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.drawer-header p {
  margin: 4px 0 0;
  color: #8f9aae;
  font-size: .9rem;
}

.close-button {
  border: 0;
  color: #8fb0ff;
  background: transparent;
  font-weight: 700;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 20px 0 8px;
}

.preset {
  padding: 11px 8px;
  border: 1px solid #2f3848;
  border-radius: 12px;
  color: #b9c2d2;
  background: #171e2a;
}

.preset.active {
  color: #fff;
  border-color: #5a83ee;
  background: #345ecb;
}

.setting-list label {
  display: block;
  padding: 15px 0;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.setting-list span {
  display: block;
  margin-bottom: 10px;
  color: #d8deea;
}

.setting-list input {
  width: 100%;
}

.reset-button {
  width: 100%;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid #343e50;
  border-radius: 14px;
  color: #c8d0de;
  background: #171e2a;
}

@media (min-width: 800px) {
  .drawer {
    left: auto;
    top: 0;
    width: 390px;
    max-height: 100%;
    border-radius: 24px 0 0 24px;
    transform: translateX(105%);
  }

  .drawer.open {
    transform: translateX(0);
  }

  .drawer-handle {
    display: none;
  }
}
