:root {
  --bg-dark: #09090b;
  --bg-panel: #18181b;
  --accent: #facc15;
  --accent-hover: #fde047;
  --zinc-200: #e4e4e7;
  --zinc-300: #d4d4d8;
  --zinc-400: #a1a1aa;
  --zinc-500: #71717a;
  --zinc-600: #52525b;
  --zinc-700: #3f3f46;
  --zinc-800: #27272a;
  --zinc-900: #18181b;
  --zinc-950: #09090b;
  --red-400: #f87171;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", sans-serif;
  background-color: var(--bg-dark);
  color: var(--zinc-200);
  overflow: hidden;
  touch-action: none;
  -webkit-font-smoothing: antialiased;
}

button, input {
  font-family: inherit;
  outline: none;
  border: none;
}

a {
  text-decoration: none;
  color: inherit;
}

.hidden { display: none !important; }
[x-cloak] { display: none !important; }

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  user-select: none;
}

.app-header {
  height: calc(3.5rem + env(safe-area-inset-top));
  background-color: var(--zinc-950);
  border-bottom: 1px solid var(--zinc-800);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: env(safe-area-inset-top);
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: 0;
  padding-left: max(1rem, env(safe-area-inset-left));
  flex-shrink: 0;
  z-index: 30;
  position: relative;
}

.header-left, .header-right, .header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-actions {
  gap: 0.5rem;
}

.logo-link {
  display: flex;
  align-items: center;
}

.logo-img {
  height: 2rem;
  width: auto;
  object-fit: contain;
}

.divider {
  height: 1.25rem;
  width: 1px;
  background-color: var(--zinc-800);
  margin: 0 0.5rem;
  display: none;
}

@media (min-width: 640px) {
  .divider { display: block; }
  .text-label { display: inline; }
}

@media (max-width: 639px) {
  .text-label { display: none; }
}

.btn {
  padding: 0.375rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-primary {
  font-weight: 700;
  background-color: var(--accent);
  color: #000;
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.2);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
}

.btn-secondary {
  font-weight: 500;
  background-color: transparent;
  color: var(--zinc-400);
  border: 1px solid transparent;
}

.btn-secondary:hover {
  background-color: var(--zinc-800);
  color: #fff;
  border-color: var(--zinc-700);
}

.btn-export {
  padding: 0.375rem 1rem;
  border-radius: 0.25rem;
  font-weight: 700;
  background-color: #fff;
  color: #000;
  box-shadow: 0 10px 15px -3px rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-export:hover:not(:disabled) {
  background-color: var(--zinc-200);
}

.btn-export:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.image-dimensions {
  font-size: 0.75rem;
  color: var(--zinc-500);
  font-family: monospace;
  display: none;
}

@media (min-width: 640px) {
  .image-dimensions { display: inline; }
}

.main-container {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.sidebar {
  width: calc(4rem + env(safe-area-inset-left));
  background-color: var(--zinc-950);
  border-right: 1px solid var(--zinc-800);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 0;
  padding-left: env(safe-area-inset-left);
  gap: 1rem;
  z-index: 20;
  flex-shrink: 0;
}

.sidebar-divider {
  width: 2rem;
  height: 1px;
  background-color: var(--zinc-800);
}

.sidebar-tools {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.tool-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--zinc-500);
  background: transparent;
  transition: all 0.2s;
  cursor: pointer;
}

.tool-btn:hover:not(:disabled) {
  color: #fff;
  background-color: var(--zinc-800);
}

.tool-btn:disabled {
  opacity: 0.2;
  cursor: default;
}

.eye-btn {
  cursor: help;
}

.editor-area {
  flex: 1;
  position: relative;
  background-color: var(--zinc-950);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.transparency-grid {
  background-color: #e5e5e5;
  background-image: none;
  touch-action: none;
}

.canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}

.drop-zone-container {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.drop-zone {
  width: 16rem;
  height: 12rem;
  border: 2px dashed var(--zinc-700);
  border-radius: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: rgba(39, 39, 42, 0.1);
  backdrop-filter: blur(4px);
  cursor: pointer;
  transition: background-color 0.2s;
}

.drop-zone:hover {
  background-color: rgba(39, 39, 42, 0.2);
}

.drop-zone i {
  font-size: 2.25rem;
  margin-bottom: 1rem;
  color: var(--zinc-500);
  transition: color 0.2s;
}

.drop-zone:hover i {
  color: var(--zinc-400);
}

.drop-zone-title {
  color: var(--zinc-600);
  font-weight: 500;
  font-size: 0.875rem;
  transition: color 0.2s;
}

.drop-zone:hover .drop-zone-title {
  color: var(--zinc-500);
}

.drop-zone-subtitle {
  color: var(--zinc-500);
  font-size: 0.75rem;
  margin-top: 0.5rem;
  transition: color 0.2s;
}

.drop-zone:hover .drop-zone-subtitle {
  color: var(--zinc-400);
}

.canvas-stage {
  position: relative;
  box-shadow: 0 0 50px rgba(0,0,0,0.5);
  transform-origin: center;
  will-change: transform;
}

.main-canvas {
  display: block;
}

.mask-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.6;
  pointer-events: none;
  mix-blend-mode: plus-lighter;
}

.pan-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  outline: none;
}

.is-panning {
  cursor: grab;
}

.is-panning:active {
  cursor: grabbing;
}

.bottom-toolbar {
  position: absolute;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 1rem;
  z-index: 20;
  pointer-events: none;
  width: 100%;
  justify-content: center;
  padding: 0 1rem;
}

.action-panel {
  background-color: var(--zinc-950);
  border: 1px solid var(--zinc-800);
  padding: 0.5rem;
  border-radius: 0.75rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  gap: 1rem;
  pointer-events: auto;
}

.btn-process {
  height: 2.25rem;
  padding: 0 1rem;
  background-color: var(--accent);
  color: #000;
  font-weight: 700;
  font-size: 0.75rem;
  border-radius: 0.5rem;
  box-shadow: 0 0 15px rgba(250, 204, 21, 0.2);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 80px;
  justify-content: center;
  cursor: pointer;
}

@media (min-width: 640px) {
  .btn-process {
    padding: 0 1.5rem;
    min-width: 100px;
  }
}

.btn-process:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

.btn-process:active:not(:disabled) {
  transform: scale(0.95);
}

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

.zoom-panel {
  display: none;
  background-color: var(--zinc-950);
  border: 1px solid var(--zinc-800);
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  pointer-events: auto;
  align-items: center;
  gap: 0.75rem;
}

@media (min-width: 640px) {
  .zoom-panel { display: flex; }
}

.icon-small {
  font-size: 10px;
  color: var(--zinc-500);
}

.zoom-slider {
  width: 6rem;
  cursor: pointer;
}

.zoom-label {
  font-size: 0.75rem;
  font-family: monospace;
  color: var(--zinc-300);
  width: 2.5rem;
  text-align: right;
  user-select: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  backdrop-filter: blur(4px);
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background-color: var(--zinc-950);
  border: 1px solid var(--zinc-800);
  border-radius: 0.75rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  padding: 1.5rem;
  width: 100%;
  max-width: 28rem;
  margin: 0 1rem;
  animation: modalSlideIn 0.2s ease-out;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: #fff;
}

.close-btn {
  color: var(--zinc-400);
  background: transparent;
  cursor: pointer;
  transition: color 0.2s;
}

.close-btn:hover {
  color: #fff;
}

.modal-desc {
  font-size: 0.875rem;
  color: var(--zinc-400);
  margin-bottom: 1rem;
}

.modal-input {
  width: 100%;
  padding: 0.625rem 1rem;
  background-color: var(--zinc-900);
  border: 1px solid var(--zinc-700);
  border-radius: 0.5rem;
  color: #fff;
  margin-bottom: 1rem;
  outline: none;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.modal-input::placeholder {
  color: var(--zinc-500);
}

.modal-input:focus {
  box-shadow: 0 0 0 2px var(--accent);
  border-color: transparent;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.btn-cancel {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--zinc-400);
  background: transparent;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-cancel:hover {
  color: #fff;
  background-color: var(--zinc-800);
}

.btn-confirm {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 700;
  background-color: var(--accent);
  color: #000;
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.2);
  transition: all 0.2s;
  cursor: pointer;
}

.btn-confirm:hover {
  background-color: var(--accent-hover);
}

.alert-container {
  position: fixed;
  top: 5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
}

.alert-notification {
  background-color: var(--zinc-950);
  border: 1px solid var(--zinc-800);
  border-radius: 0.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 28rem;
  margin: 0 1rem;
}

.alert-icon-wrapper {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background-color: rgba(239, 68, 68, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.alert-icon {
  color: var(--red-400);
  font-size: 0.75rem;
}

.alert-message {
  font-size: 0.875rem;
  color: #fff;
  flex: 1;
}

.alert-close {
  flex-shrink: 0;
  color: var(--zinc-400);
  background: transparent;
  cursor: pointer;
  transition: color 0.2s;
}

.alert-close:hover {
  color: #fff;
}

.alert-enter { transition: all 0.3s ease-out; }
.alert-enter-start { opacity: 0; transform: translateY(0.5rem); }
.alert-enter-end { opacity: 1; transform: translateY(0); }
.alert-leave { transition: all 0.2s ease-in; }
.alert-leave-start { opacity: 1; transform: translateY(0); }
.alert-leave-end { opacity: 0; transform: translateY(0.5rem); }

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 14px;
  width: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  margin-top: -5px;
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.5);
}

input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  background: var(--zinc-700);
  border-radius: 2px;
}

.loader {
  width: 16px;
  height: 16px;
  border: 2px solid #000;
  border-bottom-color: transparent;
  border-radius: 50%;
  display: inline-block;
  box-sizing: border-box;
  animation: rotation 1s linear infinite;
}

@keyframes rotation {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--zinc-700);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--zinc-600);
}

.update-toast {
  position: fixed;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  right: max(1.5rem, env(safe-area-inset-right));
  background-color: var(--zinc-900);
  border: 1px solid var(--zinc-800);
  border-radius: 0.75rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  z-index: 100;
}

.update-toast-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: #fff;
}

@media (max-width: 639px) {
  .update-toast {
    bottom: calc(5rem + env(safe-area-inset-bottom));
    left: max(1rem, env(safe-area-inset-left));
    right: max(1rem, env(safe-area-inset-right));
    justify-content: space-between;
  }
}
