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

:root {
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --accent: #f59e0b;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --checker: repeating-conic-gradient(#e2e8f0 0% 25%, transparent 0% 50%) 50% / 12px 12px;
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 24px;
  color: var(--primary);
  image-rendering: pixelated;
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.ad-slot {
  background: #f1f5f9;
  border: 1px dashed #cbd5e1;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 12px;
}

.ad-header {
  max-width: 1280px;
  margin: 16px auto 0;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
}

.ad-panel {
  margin: 20px 0;
  border-radius: var(--radius-sm);
}

.ad-faq {
  margin: 40px auto 0;
  max-width: 1280px;
  padding: 12px 20px;
}

.tips-banner {
  background: linear-gradient(135deg, #ede9fe, #ddd6fe);
  padding: 12px 20px;
  text-align: center;
  overflow: hidden;
}

.tips-track {
  position: relative;
  height: 24px;
}

.tip {
  position: absolute;
  width: 100%;
  left: 0;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.5s, transform 0.5s;
  font-size: 0.95rem;
  color: #5b21b6;
  font-weight: 500;
}

.tip.active {
  opacity: 1;
  transform: translateY(0);
}

.presets-section {
  padding: 24px 20px 8px;
}

.section-title {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 600;
}

.preset-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.preset-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  font-size: 0.85rem;
}

.preset-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.preset-emoji { font-size: 1.5rem; }
.preset-name { font-weight: 500; }

.preset-hint {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--primary);
  min-height: 20px;
}

.main-layout {
  display: flex;
  gap: 24px;
  padding: 24px 20px 40px;
  align-items: flex-start;
}

.settings-panel {
  flex: 0 0 42%;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.canvas-panel {
  flex: 0 0 58%;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: sticky;
  top: 20px;
}

.subsection-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.tool-section,
.canvas-settings,
.color-section,
.action-section {
  margin-bottom: 22px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
  transition: all 0.15s;
}

.tool-btn:hover {
  border-color: var(--primary);
}

.tool-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.tool-icon {
  font-size: 1.1rem;
}

.shape-fill-label {
  margin-top: 10px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  margin-bottom: 10px;
  cursor: pointer;
}

.checkbox-label input {
  accent-color: var(--primary);
}

.size-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.size-row input[type="number"] {
  width: 64px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
}

.field-label {
  font-size: 0.85rem;
  font-weight: 600;
}

.small-btn {
  padding: 8px 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
}

.small-btn:hover {
  background: var(--primary-dark);
}

.option-group { margin-bottom: 12px; }

.option-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.color-pair {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.color-slot {
  flex: 1;
}

.color-slot label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.color-slot input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 2px;
}

.hex-input {
  width: 100%;
  margin-top: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: monospace;
  font-size: 0.85rem;
}

.swap-colors {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 16px;
}

.palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.palette-color {
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.1s;
}

.palette-color:hover {
  transform: scale(1.15);
  z-index: 1;
}

.palette-color.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px white, 0 0 0 4px var(--primary);
}

.field-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.action-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.action-btn {
  flex: 1;
  min-width: 90px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  transition: all 0.15s;
}

.action-btn:hover {
  border-color: var(--primary);
  background: #f5f3ff;
}

.action-btn.danger:hover {
  border-color: #dc2626;
  background: #fef2f2;
  color: #dc2626;
}

.import-row {
  margin-top: 12px;
}

.import-row .field-label {
  display: block;
  margin-bottom: 6px;
}

.file-input {
  width: 100%;
  font-size: 0.85rem;
}

.history-section {
  margin-top: 4px;
}

.history-list {
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s;
}

.history-item:hover {
  background: var(--bg);
}

.history-thumb {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  image-rendering: pixelated;
  background: var(--checker);
}

.history-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 8px 0;
}

.cross-link {
  margin-top: 16px;
  font-size: 0.85rem;
}

.cross-link a {
  color: var(--primary);
  text-decoration: none;
}

.cross-link a:hover {
  text-decoration: underline;
}

.canvas-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  align-self: flex-start;
}

.canvas-wrapper {
  background: var(--checker);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow: auto;
  max-width: 100%;
  max-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#pixel-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  display: block;
}

.canvas-info {
  margin: 12px 0 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.export-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.export-btn {
  padding: 14px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.2s;
}

.export-btn:hover {
  border-color: var(--primary);
  background: #f5f3ff;
}

.export-btn.primary {
  grid-column: 1 / -1;
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-size: 1.1rem;
  padding: 18px;
}

.export-btn.primary:hover {
  background: var(--primary-dark);
}

.btn-badge {
  display: inline-block;
  background: var(--accent);
  color: #1e293b;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 20px;
  margin-right: 8px;
  font-weight: 700;
}

.faq-section {
  padding: 40px 20px 60px;
}

.faq-section h2 {
  font-size: 1.5rem;
  margin-bottom: 24px;
  text-align: center;
}

.faq-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.faq-item h3 {
  font-size: 1rem;
  margin-bottom: 10px;
  color: var(--primary);
}

.faq-item p {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 24px 0;
  text-align: center;
}

.site-footer p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.site-footer nav a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.85rem;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1e293b;
  color: white;
  padding: 14px 28px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transition: transform 0.3s ease;
}

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

.hidden { display: none !important; }

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  .main-layout { flex-direction: column; }
  .settings-panel, .canvas-panel {
    flex: 1 1 100%;
    width: 100%;
  }
  .canvas-panel { position: static; }
  .export-buttons { grid-template-columns: 1fr; }
  .export-btn.primary { grid-column: 1; }
  .header-inner { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
  .tool-grid { grid-template-columns: repeat(4, 1fr); }
  .preset-cards { grid-template-columns: repeat(2, 1fr); }
}