@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700&family=Noto+Sans+TC:wght@300;400;500;700&family=Noto+Sans+JP:wght@300;400;500;700&display=swap');

:root {
  --bg-dark: #090b0e;
  --panel-bg: rgba(18, 22, 28, 0.75);
  --panel-border: rgba(255, 255, 255, 0.08);
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #ec4899;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-disabled: #475569;
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --font-ui: 'Outfit', 'Inter', -apple-system, sans-serif;
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-ui);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

header {
  background: rgba(9, 11, 14, 0.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--panel-border);
  padding: 1.2rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.back-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
}

.back-link:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.4rem;
  font-weight: 700;
  background: linear-gradient(135deg, #a5b4fc, #6366f1, #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo i {
  font-size: 1.6rem;
  color: var(--primary);
  background: initial;
  -webkit-text-fill-color: initial;
}

.lang-selector {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
}

.lang-selector:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.main-container {
  display: grid;
  grid-template-columns: 1fr 400px;
  flex: 1;
  height: calc(100vh - 65px);
  min-height: 500px;
}

@media (max-width: 1024px) {
  .main-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    height: auto;
    overflow-y: auto;
  }
}

/* Canvas Area / Left Side */
.preview-area {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at 50% 50%, #151922, #090b0e);
  padding: 2rem;
  position: relative;
  overflow: hidden;
}

.canvas-wrapper {
  position: relative;
  box-shadow: var(--shadow-lg);
  border-radius: 8px;
  background-color: #111;
  transition: transform 0.2s ease, width 0.3s ease, height 0.3s ease;
  user-select: none;
  touch-action: none;
  max-width: 95%;
  max-height: 85vh;
}

/* Preview Canvas */
#editorCanvas {
  display: block;
  border-radius: 8px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
  max-width: 100%;
  max-height: 100%;
}

/* Interaction Overlays on Canvas */
.canvas-interaction-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  pointer-events: none; /* Allows mouse events to bubble through */
  z-index: 10;
}

/* Dashed Safe Zone Border indicator */
.safe-zone-overlay {
  position: absolute;
  border: 1px dashed rgba(236, 72, 153, 0.6);
  pointer-events: none;
  z-index: 15;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  color: var(--accent);
  font-size: 10px;
  padding: 4px;
  opacity: 0.8;
  box-sizing: border-box;
}

/* Drop-zone overlay */
.upload-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(9, 11, 14, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 20;
  border-radius: 8px;
  cursor: pointer;
  border: 2px dashed rgba(255, 255, 255, 0.15);
  margin: -2px; /* Fix border offset */
  transition: all 0.3s ease;
}

.upload-overlay:hover, .upload-overlay.dragover {
  background: rgba(15, 20, 30, 0.9);
  border-color: var(--primary);
}

.upload-overlay i {
  font-size: 3.5rem;
  color: var(--primary);
  margin-bottom: 1.5rem;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.upload-overlay p {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-main);
  text-align: center;
}

.upload-overlay span {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.hidden-file-input {
  display: none;
}

/* Control Panel / Right Side */
.control-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  border-left: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1.5rem;
  gap: 1.5rem;
  box-shadow: -5px 0 25px rgba(0, 0, 0, 0.3);
}

@media (max-width: 1024px) {
  .control-panel {
    border-left: none;
    border-top: 1px solid var(--panel-border);
    height: auto;
    max-height: none;
  }
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 1.5rem;
}

.panel-section:last-child {
  border-bottom: none;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.section-title i {
  color: var(--primary);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* Custom styled Form Inputs */
select, input[type="text"], input[type="number"], input[type="month"] {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text-main);
  padding: 0.65rem 0.85rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  outline: none;
  transition: all 0.2s ease;
  width: 100%;
}

select:focus, input[type="text"]:focus, input[type="number"]:focus, input[type="month"]:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

select option {
  background-color: #1a1f26;
  color: #f8fafc;
}

/* Custom Checkbox Toggle Button style (Buttons group) */
.btn-toggle-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: rgba(0, 0, 0, 0.2);
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
}

.btn-toggle {
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.55rem;
  transition: all 0.2s ease;
  text-align: center;
}

.btn-toggle.active {
  background: var(--primary);
  color: var(--text-main);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Custom Slider styling */
.slider-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
  transition: background 0.3s;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.slider-val {
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
}

/* Preset Themes grid */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.theme-btn {
  height: 36px;
  border-radius: 8px;
  border: 1.5px solid var(--panel-border);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
}

.theme-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.3);
}

.theme-btn.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}

/* Theme presets styling definitions */
.theme-btn.t-light { background: #f8fafc; color: #0f172a; }
.theme-btn.t-dark { background: #0f172a; color: #f8fafc; }
.theme-btn.t-glass-dark { background: rgba(15, 23, 42, 0.4); color: #f8fafc; backdrop-filter: blur(4px); }
.theme-btn.t-glass-light { background: rgba(248, 250, 252, 0.4); color: #0f172a; backdrop-filter: blur(4px); }

/* Color pickers row */
.color-picker-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.color-input-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.color-input-wrapper input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 100%;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  background: none;
}

.color-input-wrapper input[type="color"]::-webkit-slider-thumb,
.color-input-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-input-wrapper input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--panel-border);
  border-radius: 6px;
}

/* Action Buttons */
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  border: none;
  border-radius: 8px;
  color: var(--text-main);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.85rem;
  text-align: center;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.4);
  background: linear-gradient(135deg, #7c3aed, var(--primary));
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text-main);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.6rem;
  text-align: center;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Toast Notification styling */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.75rem 1.5rem;
  border-radius: 50px;
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Instruction Tips below the canvas */
.preview-tips {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 450px;
}

.preview-tips p {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.preview-tips i {
  color: var(--accent);
}

/* Loader styling */
.loader-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(9, 11, 14, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.loader-wrapper.active {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  border-top-color: var(--primary);
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Adjust layout on short height displays */
@media (max-height: 700px) {
  header {
    padding: 0.8rem 1.5rem;
  }
  .main-container {
    height: calc(100vh - 54px);
  }
}
