* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
    Roboto, sans-serif;
  background: #fafafa;
  color: #0a0a0a;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
}

.app {
  height: 100vh;
  height: 100dvh;
  max-width: 540px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 12px;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  gap: 8px;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  color: #4a4a4a;
}

.banner__action {
  color: #0a0a0a;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid #0a0a0a;
  padding-bottom: 1px;
  margin-left: 12px;
}

.image-area {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 10px;
  background: #ededed;
  overflow: hidden;
  touch-action: pan-y;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9a9a9a;
  font-size: 0.92rem;
  text-align: center;
  padding: 24px;
}

.empty-state p {
  margin: 0;
}

.image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #ededed;
  cursor: zoom-in;
}

.image-tabs {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  background: rgba(10, 10, 10, 0.6);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  z-index: 1;
}

.result-dots {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  background: rgba(10, 10, 10, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  padding: 7px 12px;
  border-radius: 999px;
  z-index: 1;
}

.result-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease;
}

.result-dot--active {
  background: #fff;
}

.tab {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.78rem;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: 0.02em;
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tab--active {
  background: #fff;
  color: #0a0a0a;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.row {
  display: flex;
  gap: 8px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #0a0a0a;
  font-size: 0.92rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}

.button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.button--secondary {
  background: #fff;
  border-color: #e5e5e5;
}
.button--secondary:active {
  background: #f5f5f5;
}

.button--primary {
  background: #0a0a0a;
  color: #fff;
  border-color: #0a0a0a;
}
.button--primary:active {
  background: #2a2a2a;
}
.button--primary:disabled {
  background: #d4d4d4;
  border-color: #d4d4d4;
  color: #fff;
  opacity: 1;
}

.button--ghost {
  background: #fff;
  border-color: #e5e5e5;
  color: #555;
}
.button--ghost:active {
  background: #f5f5f5;
}

.button--narrow {
  flex: 0 0 90px;
}

.select {
  flex: 1;
  height: 44px;
  padding: 0 36px 0 12px;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  background: #fff;
  color: #0a0a0a;
  font-size: 0.92rem;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path fill='%23999' d='M5 8l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px 12px;
  cursor: pointer;
}

.select--narrow {
  flex: 0 0 86px;
}

.select--xnarrow {
  flex: 0 0 76px;
}

.select:focus {
  outline: none;
  border-color: #0a0a0a;
}

.prompt-overlay {
  position: fixed;
  inset: 0;
  background: #fafafa;
  z-index: 110;
  display: flex;
  flex-direction: column;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

.prompt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 52px;
  flex-shrink: 0;
  border-bottom: 1px solid #ececec;
}

.prompt-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #0a0a0a;
  letter-spacing: 0.01em;
}

.prompt-action {
  background: transparent;
  border: none;
  color: #0a0a0a;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}

.prompt-action:active {
  background: #ececec;
}

.prompt-action--primary {
  background: #0a0a0a;
  color: #fff;
}

.prompt-action--primary:active {
  background: #2a2a2a;
}

.prompt-fullscreen {
  flex: 1;
  width: 100%;
  border: none;
  background: #fafafa;
  color: #0a0a0a;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  padding: 16px 16px 24px;
  resize: none;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.prompt-fullscreen::placeholder {
  color: #b0b0b0;
}

.status {
  margin: 0;
  padding: 0 4px;
  font-size: 0.78rem;
  color: #888;
  text-align: center;
  min-height: 16px;
}

.status--pending {
  color: #555;
}

.status--ok {
  color: #15803d;
}

.status--error {
  color: #991b1b;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-title {
  margin: 0 0 8px;
  font-size: 1.4rem;
  font-weight: 600;
  color: #0a0a0a;
}

.login-subtitle {
  margin: 0 0 28px;
  color: #777;
  font-size: 0.95rem;
}

.login-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 22px;
  border: 1px solid #d4d4d8;
  border-radius: 10px;
  background: #fff;
  color: #0a0a0a;
  font-size: 1rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease;
}

.login-google:active {
  background: #f0f0f0;
}

.login-error {
  margin: 20px 0 0;
  color: #991b1b;
  font-size: 0.85rem;
}

.logout-btn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: 10px;
  z-index: 50;
  height: 30px;
  padding: 0 12px;
  border: 1px solid #e5e5e5;
  border-radius: 999px;
  background: #fff;
  color: #555;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.logout-btn:active {
  background: #f5f5f5;
}

.image-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.image-overlay img {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  touch-action: none;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

.overlay-close,
.overlay-action {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #fff;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.overlay-close {
  right: 12px;
}

.overlay-action--left {
  left: 12px;
}

.overlay-close:disabled,
.overlay-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.overlay-close svg,
.overlay-action svg {
  width: 18px;
  height: 18px;
}

.gallery-overlay {
  position: fixed;
  inset: 0;
  background: #0a0a0a;
  z-index: 90;
  overflow-y: auto;
  padding: max(64px, calc(env(safe-area-inset-top) + 56px)) 12px
    max(20px, env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.gallery-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gallery-row {
  display: flex;
  gap: 4px;
}

.gallery-thumb {
  flex-shrink: 0;
  background: #1a1a1a;
  border-radius: 4px;
  overflow: hidden;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  transition: border-color 0.15s ease;
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.15s ease;
}

.gallery-thumb--selected {
  border-color: #2563eb;
}

.gallery-thumb--selected img {
  opacity: 0.78;
}

.thumb-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.thumb-check svg {
  width: 12px;
  height: 12px;
  stroke: #fff;
  stroke-width: 3;
  fill: none;
  visibility: hidden;
}

.gallery-thumb--selected .thumb-check {
  background: #2563eb;
  border-color: #2563eb;
}

.gallery-thumb--selected .thumb-check svg {
  visibility: visible;
}

.gallery-action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 91;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(10, 10, 10, 0.92);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.gallery-action {
  flex: 1;
  height: 44px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.gallery-action--ghost {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.gallery-action--ghost:active {
  background: rgba(255, 255, 255, 0.1);
}

.gallery-action--primary {
  background: #2563eb;
  color: #fff;
}

.gallery-action--primary:active {
  background: #1d4ed8;
}

.gallery-action--secondary {
  background: rgba(255, 255, 255, 0.92);
  color: #0a0a0a;
}

.gallery-action--secondary:active {
  background: rgba(255, 255, 255, 0.78);
}

.gallery-action--danger {
  background: #dc2626;
  color: #fff;
}

.gallery-action--danger:active {
  background: #b91c1c;
}

.gallery-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.gallery-overlay--with-action {
  padding-bottom: max(80px, calc(env(safe-area-inset-bottom) + 80px));
}

.gallery-empty {
  color: #777;
  text-align: center;
  font-size: 0.92rem;
  padding: 80px 20px;
  margin: 0;
}

.crop-overlay {
  position: fixed;
  inset: 0;
  background: #0a0a0a;
  z-index: 110;
  display: flex;
  flex-direction: column;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

.crop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 52px;
  flex-shrink: 0;
}

.crop-dims {
  color: #fff;
  font-size: 0.92rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.crop-action {
  background: transparent;
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}

.crop-action:active {
  background: rgba(255, 255, 255, 0.12);
}

.crop-action--primary {
  background: #fff;
  color: #0a0a0a;
}

.crop-action--primary:active {
  background: #ddd;
}

.crop-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
}

#crop-image {
  max-width: 100%;
  max-height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.crop-frame {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  box-sizing: border-box;
}

.crop-aspects {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px 4px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.aspect-chip {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.aspect-chip--active {
  background: #fff;
  color: #0a0a0a;
}
