:root {
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f0f0;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-hint: #999999;
    --border: #e0e0e0;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
}

[data-theme="dark"] {
    --bg-primary: #0a0a0a;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --text-primary: #fafafa;
    --text-secondary: #b0b0b0;
    --text-hint: #707070;
    --border: #333333;
    --accent: #818cf8;
    --accent-hover: #6366f1;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background 0.3s, color 0.3s;
    overflow: hidden;
    height: 100vh;
}

header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.branding h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.tagline {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.header-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.kofi-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 1.25rem;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.kofi-link:hover {
    opacity: 1;
}

#themeToggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 1.25rem;
    transition: all 0.2s;
}

#themeToggle:hover {
    background: var(--bg-tertiary);
}

.generator-layout {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 2rem;
    height: calc(100vh - 5rem);
    overflow: hidden;
}

.inputs-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 1rem;
    max-height: 100%;
}

.inputs-panel::-webkit-scrollbar {
    width: 8px;
}

.inputs-panel::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.inputs-panel::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.inputs-panel::-webkit-scrollbar-thumb:hover {
    background: var(--text-hint);
}

.input-group {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
}

.input-group h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.preset-btn {
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.preset-btn:hover {
    background: var(--bg-primary);
}

.preset-btn.active {
    border-color: var(--accent);
    background: var(--bg-primary);
}

input[type="text"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    transition: border-color 0.2s, background 0.2s;
}

input[type="date"] {
    color-scheme: light;
    cursor: pointer;
}

[data-theme="dark"] input[type="date"] {
    color-scheme: dark;
}

input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23b0b0b0' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
}

select:hover {
    background-color: var(--bg-tertiary);
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
}

textarea {
    resize: vertical;
    min-height: 120px;
}

.char-count {
    font-size: 0.75rem;
    color: var(--text-hint);
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-zone:hover {
    border-color: var(--accent);
    background: var(--bg-primary);
}

.upload-zone svg {
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

.upload-zone p {
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.hint {
    font-size: 0.75rem;
    color: var(--text-hint);
}

details summary {
    cursor: pointer;
    font-weight: 600;
    padding: 0.5rem 0;
    user-select: none;
}

.advanced-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.advanced-controls label {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.875rem;
}

input[type="range"] {
    width: 100%;
    margin: 0;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: var(--accent-hover);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.2);
    background: var(--accent-hover);
}

input[type="color"] {
    width: 100%;
    height: 50px;
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
    background: var(--bg-primary);
    padding: 0.25rem;
    transition: border-color 0.2s;
}

input[type="color"]:hover {
    border-color: var(--accent);
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 0.375rem;
}

input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 0.375rem;
}

input[type="file"] {
    font-size: 0.875rem;
    color: var(--text-primary);
}

input[type="file"]::file-selector-button {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    color: var(--text-primary);
    cursor: pointer;
    margin-right: 0.75rem;
    transition: all 0.2s;
}

input[type="file"]::file-selector-button:hover {
    background: var(--accent);
    color: white;
}

.primary-btn {
    width: 100%;
    padding: 1rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.primary-btn:hover {
    background: var(--accent-hover);
}

.preview-panel {
    position: relative;
}

.preview-sticky {
    position: sticky;
    top: 5rem;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.preview-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

#previewExpand {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}

#previewExpand:hover {
    background: var(--bg-tertiary);
}

.preview-container {
    background: var(--bg-secondary);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-md);
    aspect-ratio: 16/9;
    width: 100%;
    overflow: hidden;
    position: relative;
}

.preview-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-hint);
    font-size: 0.875rem;
}

.mobile-preview-btn {
    display: none;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    font-size: 2rem;
    cursor: pointer;
    transition: background 0.2s;
    z-index: 1001;
}

.modal-close:hover {
    background: rgba(255,255,255,0.2);
}

.modal-content {
    max-width: 600px;
    max-height: 90vh;
    width: 100%;
    overflow: auto;
}

.crop-modal-content {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 1rem;
    max-width: 90vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
}

.crop-modal-content h3 {
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
}

.crop-container {
    position: relative;
    width: 100%;
    max-width: min(600px, 80vw);
    aspect-ratio: 1;
    background: var(--bg-primary);
    border-radius: 0.5rem;
    overflow: hidden;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

#cropCanvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0.5rem;
}

.crop-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-top: auto;
}

.crop-controls input[type="range"] {
    flex: 1;
    margin: 0;
}

.crop-controls button {
    flex-shrink: 0;
    min-width: 120px;
}

.crop-stage {
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    max-width: 100%;
    max-height: 70vh;
}

.crop-canvas-wrap {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    background: #000;
}

#cropCanvas {
    display: block;
}

.crop-frame {
  z-index: 2;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.9);
  transition: box-shadow .15s ease;
  position: absolute;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
  pointer-events: none;
}

.crop-controls {
  margin-top: 18px;
  display:flex;
  gap:12px;
  align-items:center;
  justify-content:space-between;
  z-index: 10050;
  position: relative;
}

#cropZoom {
    flex: 1;
}

.crop-controls input[type="range"]{
  flex: 1;
  height: 8px;
  background: linear-gradient(90deg,#222,#444);
  border-radius:999px;
  outline:none;
  z-index: 10060;
  pointer-events: auto;
}

.crop-controls input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:18px;height:18px;border-radius:50%;
  background: #6765ff;
  box-shadow:0 2px 6px rgba(0,0,0,0.3);
  margin-top: -5px;
  z-index: 10061;
  position: relative;
}

.crop-controls .primary-btn {
  margin-left: 18px;
  z-index: 10062;
  flex: 0 0 160px;
  width: 160px;
  min-width: 120px;
}

body[data-theme="light"] .crop-canvas-wrap { background:#fff; }
body[data-theme="light"] .crop-frame { border-color: rgba(0,0,0,0.8); box-shadow: 0 0 0 9999px rgba(255,255,255,0.8); }
body[data-theme="light"] .crop-controls input[type="range"]::-webkit-slider-thumb { background: #5b5be6; }

.required {
    color: red;
    font-weight: bold; 
    margin-left: 4px; 
}

#cropModal.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.6);
  z-index: 120;
  padding: 2rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
#cropModal.modal.active {
  opacity: 1;
  pointer-events: auto;
}
#cropModal .modal-inner {
  width: min(92vw, 1100px);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: .75rem;
  max-width: 92vw;
  max-height: 92vh;
  overflow: hidden;
}
#cropModal .modal-close {
  position: absolute;
  right: 1.25rem;
  top: 1.25rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
}
#cropStage {
  position: relative;
  margin: 0 auto;
  max-width: 80vw;
  max-height: 68vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  border-radius: 10px;
  padding: 1rem;
  box-shadow: var(--shadow-md);
}
#cropCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  cursor: grab;
  border-radius: 8px;
  background: #000;
}
#cropCanvas:active { cursor: grabbing; }
#cropFrame {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(64vmin, 420px);
  height: min(64vmin, 420px);
  transform: translate(-50%, -50%);
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.92);
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
  pointer-events: none;
}
.crop-controls input[type="range"] {
  flex: 1;
}
.crop-controls .btn {
  min-width: 120px;
  background: var(--accent);
  color: white;
  border: none;
  padding: .6rem .9rem;
  border-radius: 8px;
  cursor: pointer;
}

.custom-select {
    position: relative;
    margin-bottom: 0.5rem;
}

.select-display {
    width: 100%;
    padding: 0.75rem;
    padding-right: 2.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    position: relative;
}

.select-display:hover {
    background: var(--bg-tertiary);
}

.select-display.open {
    border-color: var(--accent);
}

.select-arrow {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    transition: transform 0.2s;
    pointer-events: none;
    fill: var(--text-secondary);
}

.select-display.open .select-arrow {
    transform: translateY(-50%) rotate(180deg);
}

.select-options {
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-md);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
    transition: opacity 0.2s, transform 0.2s;
}

.select-options.open {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

.select-option {
    padding: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.select-option:hover {
    background: var(--bg-tertiary);
}

.select-option.selected {
    background: var(--accent);
    color: white;
}

.custom-color-picker {
    position: relative;
}

.color-display {
    width: 100%;
    height: 50px;
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: border-color 0.2s;
    background: var(--bg-primary);
    padding: 0.25rem;
}

.color-display:hover {
    border-color: var(--accent);
}

.color-display-inner {
    width: 100%;
    height: 100%;
    border-radius: 0.375rem;
}

.color-picker-modal {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    z-index: 101;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
    transition: opacity 0.2s, transform 0.2s;
}

.color-picker-modal.open {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

.color-canvas {
    width: 100%;
    height: 200px;
    border-radius: 0.5rem;
    cursor: crosshair;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
}

.color-hue {
    width: 100%;
    height: 20px;
    border-radius: 0.375rem;
    cursor: pointer;
    margin-bottom: 0.75rem;
    background: linear-gradient(to right, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
    border: 1px solid var(--border);
}

.color-preview-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.color-preview-box {
    width: 40px;
    height: 40px;
    border-radius: 0.375rem;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.color-hex-input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    color: var(--text-primary);
    font-family: monospace;
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.color-hex-input:focus {
    outline: none;
    border-color: var(--accent);
}

.date-picker {
    position: relative;
}

.date-display {
    padding: 0.75rem 1rem;
    border-radius: 0.6rem;
    background: var(--input-bg);
    border: 1px solid var(--border);
    cursor: pointer;
    font-variant-numeric: tabular-nums;
}

.date-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    z-index: 2000;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 0.75rem;
    box-shadow: 0 20px 50px rgba(0,0,0,0.35);
    display: none;
    width: 280px;
}

.date-dropdown.open {
    display: block;
}

.calendar-header {
    display: grid;
    grid-template-columns: 32px 1fr 32px;
    align-items: center;
    background: linear-gradient(180deg, rgba(255,255,255,0.06), transparent);
    border-bottom: 1px solid var(--border);
}

.calendar-header button {
    appearance: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: 0.5rem;
}

.calendar-header button:hover {
    background: rgba(255,255,255,0.08);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.25rem;
}

.calendar-day {
    padding: 0.4rem;
    text-align: center;
    border-radius: 0.4rem;
    cursor: pointer;
}

.calendar-day:hover {
    background: var(--hover-bg);
}

.calendar-day.active {
    background: var(--accent);
    color: white;
}

.color-canvas-wrap {
    position: relative;
}

.color-pointer {
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.6);
    pointer-events: none;
}

.color-hue {
    position: relative;
    height: 14px;
    border-radius: 7px;
    background: linear-gradient(to right,
        red, yellow, lime, cyan, blue, magenta, red);
}

.color-hue-thumb {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.6);
}

.brand-icon {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.6rem;
    background: rgba(255,255,255,0.06);
    transition: background 0.2s ease, transform 0.2s ease;
}

.brand-icon img {
    width: 20px;
    height: 20px;
}

.brand-icon:hover {
    background: rgba(255,255,255,0.12);
    transform: translateY(-1px);
}

@media (max-width: 720px) {
  #cropModal .modal-inner { padding: 1rem; }
  #cropFrame { width: min(76vmin, 320px); height: min(76vmin, 320px); }
}

@media (max-width: 1024px) {
    body {
        overflow-y: auto;
    }

    .generator-layout {
        grid-template-columns: 1fr;
        height: auto;
        overflow-y: visible;
        padding-bottom: 6rem;
    }

    .inputs-panel {
        overflow-y: visible;
        padding-right: 0;
        max-height: none;
    }

    .preview-panel {
        display: none;
    }

    .mobile-preview-btn {
        display: block;
        position: fixed;
        bottom: 2rem;
        right: 2rem;
        padding: 1rem 2rem;
        background: var(--accent);
        color: white;
        border: none;
        border-radius: 2rem;
        font-size: 1rem;
        font-weight: 600;
        cursor: pointer;
        box-shadow: var(--shadow-lg);
        z-index: 50;
    }
}