:root {
  --bg-primary: #fdf2f8; /* Soft pink background */
  --panel-bg: rgba(255, 255, 255, 0.85);
  --panel-border: rgba(244, 114, 182, 0.3);
  --primary-color: #f472b6; /* Cute pink */
  --primary-hover: #ec4899;
  --accent-color: #6ee7b7; /* Mint */
  --text-main: #4b5563; /* Dark gray for readability */
  --text-muted: #9ca3af;
  --danger: #fb7185;
  --input-bg: rgba(255, 255, 255, 0.9);
  --card-bg: rgba(255, 255, 255, 0.95);

  /* Redesign Variables */
  --canvas-width: 1600px;
  --canvas-height: 900px;
  --canvas-padding: 36px;
  --card-radius: 24px;
  --card-header-height: 76px;
  --layout-gap: 28px;
  --c-pink: #F26DB2;
  --c-soft-pink: #FCE7F3;
  --c-lavender: #ECEBFF;
  --c-sky-blue: #DFF4FF;
  --c-text-main: #4E5064;
  --c-text-sub: #9299AC;
  --c-white-trans: rgba(255, 255, 255, 0.88);
}

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

body {
  font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
  background-color: var(--bg-primary);
  background-image: url('/illust.jpg');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  position: relative;
  letter-spacing: -0.02em;
}

/* Dim overlay to make content readable against the background */
body::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(253, 242, 248, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: -1;
}

.app-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 20px;
}

.app-header {
  text-align: center;
  margin-bottom: 40px;
  background: var(--panel-bg);
  padding: 20px;
  border-radius: 30px;
  border: 2px dashed var(--primary-color);
  box-shadow: 0 10px 25px rgba(244, 114, 182, 0.15);
}

.app-header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--primary-color);
  margin-bottom: 8px;
  text-shadow: 2px 2px 0px rgba(255,255,255,0.8);
}

.app-header p {
  color: var(--text-main);
  font-size: 1.1rem;
  font-weight: 600;
}

/* Form Styles (Menu Board) */
.menu-board-wrapper {
  background: #fdfbf7;
  padding: 40px;
  border-radius: 16px;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.05), 0 20px 40px rgba(244, 114, 182, 0.15);
  border: 12px solid #f9a8d4;
  position: relative;
}

.menu-board-wrapper::before {
  content: '';
  position: absolute;
  top: 10px; left: 10px; right: 10px; bottom: 10px;
  border: 2px dashed #fbcfe8;
  pointer-events: none;
  border-radius: 8px;
}

.modern-form {
  position: relative;
  z-index: 1;
}

.form-header {
  text-align: center;
  margin-bottom: 30px;
}

.form-header h2 {
  color: var(--primary-color);
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.form-header p {
  color: #64748b;
  font-weight: 600;
}

.form-row {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}

.input-group {
  display: flex;
  flex-direction: column;
  flex: 1;
  margin-bottom: 20px;
}

.form-row .input-group {
  margin-bottom: 0;
}

label {
  font-family: 'Gowun Dodum', sans-serif;
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 8px;
  color: #475569;
}

/* Colorful Labels */
.form-row:nth-child(2) .input-group:nth-child(1) label { color: #ec4899; }
.form-row:nth-child(2) .input-group:nth-child(2) label { color: #3b82f6; }
.form-row:nth-child(3) .input-group:nth-child(1) label { color: #10b981; }
.form-row:nth-child(3) .input-group:nth-child(2) label { color: #8b5cf6; }
.form-row:nth-child(4) .input-group:nth-child(1) label { color: #f59e0b; }
.form-row:nth-child(4) .input-group:nth-child(2) label { color: #ef4444; }
.form-row:nth-child(5) .input-group:nth-child(1) label { color: #14b8a6; }
.form-row:nth-child(5) .input-group:nth-child(2) label { color: #6366f1; }
.modern-form > .input-group:nth-of-type(1) label { color: #d946ef; }
.modern-form > .input-group:nth-of-type(2) label { color: #06b6d4; }

.required {
  color: var(--primary-color);
}

input[type="text"], select, textarea, input[type="file"] {
  background: transparent;
  border: none;
  border-bottom: 2px solid #fbcfe8;
  border-radius: 0;
  padding: 10px 4px;
  color: #334155;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  transition: all 0.3s ease;
}

input[type="text"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  background: rgba(255,255,255,0.5);
}

input[type="file"] {
  padding: 10px;
  font-size: 0.9rem;
}

textarea {
  resize: vertical;
}

/* Custom File Upload Styling */
.file-upload-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--input-bg);
  border: 2px dashed #f9a8d4;
  border-radius: 16px;
  padding: 16px;
  cursor: pointer;
  color: var(--primary-color);
  font-weight: 700;
  font-size: 1.05rem;
  transition: all 0.3s ease;
}

.file-upload-label:hover {
  background: #fdf2f8;
  border-color: #f472b6;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(244, 114, 182, 0.15);
}

.upload-icon {
  font-size: 1.3rem;
}

.radio-options {
  display: flex;
  gap: 16px;
  background: var(--input-bg);
  padding: 14px 16px;
  border-radius: 16px;
  border: 2px solid #fbcfe8;
}

.radio-options label {
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text-main);
  font-weight: 600;
}

.btn-primary {
  flex: 1;
  background: linear-gradient(135deg, #f472b6, #fb7185);
  color: #fff;
  border: none;
  padding: 18px;
  border-radius: 99px; /* Pill shape */
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 8px 20px rgba(244, 114, 182, 0.4);
}

.btn-primary:hover {
  transform: translateY(-3px);
  background: linear-gradient(135deg, #ec4899, #e11d48);
  box-shadow: 0 12px 25px rgba(244, 114, 182, 0.6);
}

.btn-secondary, .btn-outline {
  flex: 1;
  padding: 14px;
  border-radius: 99px; /* Pill shape */
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary {
  background: var(--accent-color);
  color: #fff;
  border: none;
  box-shadow: 0 4px 15px rgba(110, 231, 183, 0.4);
}

.btn-secondary:hover {
  background: #34d399;
  transform: translateY(-2px);
}

.btn-outline {
  background: #fff;
  color: var(--primary-color);
  border: 2px solid var(--primary-color);
}

.btn-outline:hover {
  background: #fdf2f8;
}

.error-msg {
  color: var(--danger);
  margin-top: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  display: none;
}

/* Cute Loading Animation */
.loading-wrapper {
  text-align: center;
  padding: 40px;
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 6px solid #fbcfe8;
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px auto;
}

.loading-text {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary-color);
  animation: pulse 1.5s infinite;
}

@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes pulse { 0% { opacity: 0.7; } 50% { opacity: 1; } 100% { opacity: 0.7; } }

.result-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 24px;
}

/* Result Card Redesign UI */
.result-view {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.result-wrapper {
  width: 100%;
  overflow: visible; /* Changed from hidden to prevent html2canvas cropping */
}

.result-preview-container {
  width: min(92vw, 1500px);
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px 0;
}

@keyframes fadeUp {
  0% { opacity: 0; transform: translateY(30px); }
  100% { opacity: 1; transform: translateY(0); }
}

#finalGeneratedImg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  animation: fadeUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.result-card {
  position: relative;
  width: var(--canvas-width);
  height: var(--canvas-height);
  min-width: var(--canvas-width);
  min-height: var(--canvas-height);
  flex-shrink: 0;
  background: #fbf9ff;
  font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
  overflow: hidden;
  box-shadow: 0 40px 100px rgba(113, 82, 130, 0.15);
  transform-origin: center top;
  border: 6px solid #fce7f3;
}

/* Very subtle background pattern */
.result-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: radial-gradient(var(--c-lavender) 2px, transparent 2px);
  background-size: 30px 30px;
  opacity: 0.4;
  z-index: 0;
}

.result-layout-grid {
  position: relative;
  z-index: 1;
  display: flex;
  width: 100%;
  height: 100%;
  padding: var(--canvas-padding);
  gap: var(--layout-gap);
}

.left-panel {
  width: 560px; /* Fixed width for stability (approx 36% of 1600, but exact) */
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.right-panel {
  flex: 1; /* Take the rest of the space */
  position: relative;
  display: flex;
}

/* Common Desktop Card Style */
.desktop-window-card {
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 3px solid #fbcfe8;
  border-radius: var(--card-radius);
  box-shadow: 0 16px 40px rgba(113, 82, 130, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.window-header {
  height: var(--card-header-height);
  padding: 0 28px;
  background: linear-gradient(90deg, #fce7f3, #e0e7ff);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  border-bottom: 2px dashed #fbcfe8;
}

.window-title {
  font-size: 29px;
  font-weight: 800;
  color: var(--c-pink);
  letter-spacing: -0.02em;
}

.window-controls span {
  display: inline-block;
  margin-left: 12px;
  color: var(--c-pink);
  font-weight: 800;
  font-size: 24px;
  cursor: default;
}

.res-game-nick {
  font-size: 14px;
  color: #fff;
  background: linear-gradient(135deg, #A78BFA, #8B5CF6);
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: 800;
  margin: 10px auto 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
  letter-spacing: 0.5px;
}

.window-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 36px;
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(252,247,251,0.92));
  /* Very subtle grid pattern for readability */
  background-image: 
    linear-gradient(rgba(242, 109, 178, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(242, 109, 178, 0.03) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(252,247,251,0.92));
  background-size: 20px 20px, 20px 20px, 100% 100%;
}

/* About Me Specifics */
.about-me-card {
  height: 100%;
}

.profile-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 40px;
}

.profile-avatar {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  object-fit: cover;
  border: 6px solid #fff;
  box-shadow: 0 8px 30px rgba(113, 82, 130, 0.12);
  margin-bottom: 20px;
}

.profile-nick {
  font-size: 42px;
  font-weight: 900;
  color: var(--c-pink);
  line-height: 1.1;
  margin-bottom: 6px;
  text-shadow: 2px 2px 0px rgba(255,255,255,0.8);
}

.profile-sub {
  font-size: 23px;
  font-weight: 700;
  color: var(--c-text-sub);
  line-height: 1.2;
}

/* Preferences Area */
.preference-section {
  display: flex;
  flex-direction: column;
}

.pref-row {
  display: flex;
  align-items: center;
  height: 58px;
  border-bottom: 1px solid rgba(113, 82, 130, 0.08);
}

.pref-row:last-child {
  border-bottom: none;
}

.pref-label {
  display: flex;
  align-items: center;
  width: 150px;
  font-size: 22px;
  font-weight: 700;
  color: var(--c-text-main);
  flex-shrink: 0;
}

.pref-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 12px;
}

.pref-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  flex: 1;
}

.chip {
  font-size: 21px;
  font-weight: 600;
  color: var(--c-text-sub);
}

.chip.active {
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 99px;
  margin: -4px 0; /* offset padding */
}

/* Custom Chip Colors for Active State */
#resGenderList .chip.active { background: #FFE3F1; color: #E86AA6; }
#resAgeList .chip.active { background: #E3F2FF; color: #5A9BE8; }
#resContentList .chip.active { background: #DDF7EE; color: #36B98A; }
#resMicList .chip.active { background: #EEE7FF; color: #8A6BEA; }
#resStyleList .chip.active { background: #FFF2CC; color: #D59A1A; }

.etc-section {
  margin-top: auto;
  display: flex;
  flex-direction: column;
}

.etc-box {
  background: rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  padding: 16px 20px;
  border: 1px dashed rgba(113, 82, 130, 0.2);
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

#resMessage {
  font-size: 17px;
  font-weight: 500;
  color: var(--c-text-main);
  line-height: 1.6;
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  width: 100%;
}

/* Right Side: Artwork & Floats */
.character-artwork-container {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}



.character-artwork {
  position: absolute;
  width: 100%;
  height: 100%;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 2;
}

/* Tier Card */
.tier-card {
  position: absolute;
  top: 0;
  right: 0;
  width: 250px;
  height: 300px;
  z-index: 10;
}

.tier-content {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
}

.tier-icon-container {
  width: 128px;
  height: 128px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.tier-content img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.1));
}

/* Most Characters Card */
.res-character {
  position: absolute;
  bottom: 0;
  left: 56%;
  width: 900px;
  height: 900px;
  transform: translateX(-50%);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: bottom center;
  z-index: 2;
  pointer-events: none;
  clip-path: inset(0 0 0 10px); /* Crop thin line artifact on the left edge */
}

.most-card {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 500px;
  height: 230px;
  z-index: 10;
}

.most-content {
  display: flex;
  flex-direction: row;
  justify-content: space-evenly;
  align-items: center;
  padding: 0 16px;
}

.most-char-img {
  width: 88px;
  height: 88px;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid #fff;
  box-shadow: 0 8px 24px rgba(113, 82, 130, 0.12);
}

/* Cropper Modal */
.cropper-modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(5px);
  display: none; justify-content: center; align-items: center;
  z-index: 9999;
}
.cropper-modal-content {
  background: #fff; padding: 30px; border-radius: 30px;
  width: 90%; max-width: 500px; text-align: center;
}
.cropper-modal-content h3 { margin-bottom: 20px; color: var(--primary-color); }
.cropper-container {
  width: 100%; height: 350px; margin-bottom: 20px; background: #e2e8f0; border-radius: 16px; overflow: hidden;
}
.cropper-actions { display: flex; gap: 16px; }

/* Responsive */
@media (max-width: 600px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .card-header {
    flex-direction: column;
    text-align: center;
  }
  .twit-nick-container {
    justify-content: center;
  }
  .card-stats {
    flex-direction: column;
  }
  .result-actions {
    flex-direction: column;
  }
}
