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

:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-muted: #faf8f5;
  --border: #e4ddd4;
  --border-strong: #c9bfb2;
  --text: #1a1714;
  --text-muted: #6b6358;
  --accent: #c45c26;
  --accent-hover: #a84d1f;
  --accent-soft: #f5e8df;
  --shadow: 0 2px 8px rgba(26, 23, 20, 0.06);
  --shadow-lg: 0 8px 32px rgba(26, 23, 20, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --font-sans: 'DM Sans', system-ui, sans-serif;
  --font-serif: 'Instrument Serif', Georgia, serif;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

.app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.nav-brand:hover {
  color: var(--accent);
}

.nav-links {
  display: flex;
  gap: 0.5rem;
}

.nav-link {
  padding: 0.4rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.nav-link.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.header-center,
.logo-center {
  justify-content: center;
  text-align: center;
}

.tagline-center {
  margin-left: 0;
  text-align: center;
}

.app-home {
  max-width: 1100px;
}

.tool-category {
  margin-bottom: 2.5rem;
}

.tool-category-title {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 400;
  margin-bottom: 1rem;
  color: var(--text);
}

.tool-card h3 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 400;
}

.nav-scroll {
  overflow-x: auto;
  max-width: 70vw;
  flex-shrink: 1;
  scrollbar-width: thin;
}

.nav-scroll .nav-link {
  white-space: nowrap;
  flex-shrink: 0;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

.tool-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.tool-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.tool-card-icon {
  font-size: 2rem;
  color: var(--accent);
  font-family: var(--font-serif);
  line-height: 1;
}

.tool-card h2,
.tool-card h3 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 400;
}

.tool-card p {
  font-size: 0.9rem;
  color: var(--text-muted);
  flex: 1;
}

.tool-card-cta {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.header {
  margin-bottom: 2rem;
}

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

.logo-icon {
  font-size: 1.75rem;
  color: var(--accent);
  line-height: 1;
}

.logo h1 {
  font-family: var(--font-serif);
  font-size: 2.25rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.tagline {
  color: var(--text-muted);
  margin-top: 0.25rem;
  margin-left: 2.5rem;
  font-size: 0.95rem;
}

.app-help {
  margin: 1rem 0 0 2.5rem;
  padding: 1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
  color: var(--text-muted);
  max-width: 42rem;
}

.app-help .help-intro {
  margin: 0 0 0.65rem;
  line-height: 1.55;
}

.app-help .help-tips summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
}

.app-help ul {
  margin: 0.4rem 0 0;
  padding-left: 1.2rem;
}

.app-help li {
  margin-bottom: 0.3rem;
  line-height: 1.45;
}

.app-help .help-privacy {
  margin: 0.75rem 0 0;
  font-size: 0.82rem;
}

.workspace {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--surface-muted);
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-content p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.dropzone-icon {
  display: block;
  font-size: 1.5rem;
  color: var(--accent);
  font-weight: 300;
}

.dropzone-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  opacity: 0.7;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

.image-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
  max-height: 200px;
  overflow-y: auto;
}

.image-list:empty {
  display: none;
}

.image-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  background: var(--surface-muted);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.image-item img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.image-item-info {
  flex: 1;
  min-width: 0;
}

.image-item-name {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-item-index {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.image-item-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.image-item-remove:hover {
  color: #c0392b;
  background: #fdecea;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.875rem;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-row label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.unit {
  font-weight: 400;
  color: var(--text-muted);
}

.stepper {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-muted);
}

.stepper-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.stepper-btn:hover {
  background: var(--border);
  color: var(--text);
}

.stepper input {
  flex: 1;
  border: none;
  background: transparent;
  text-align: center;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  min-width: 0;
  -moz-appearance: textfield;
}

.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

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

select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.85rem;
  background: var(--surface-muted);
  cursor: pointer;
}

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

textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.875rem;
  background: var(--surface-muted);
  resize: vertical;
  min-height: 72px;
}

textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.control-row-inline {
  flex-direction: row;
  gap: 1.25rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.image-thumb {
  position: relative;
  margin-top: 1rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.image-thumb img {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: cover;
}

.image-thumb .image-item-remove {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(255, 255, 255, 0.9);
}

.position-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.375rem;
  margin-bottom: 0.875rem;
}

.pos-btn {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.pos-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.pos-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.actions {
  display: flex;
  gap: 0.75rem;
}

.btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-muted);
  color: var(--text);
}

.btn-sm {
  flex: none;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.875rem;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.875rem;
  background: var(--surface-muted);
}

.hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.tile-downloads {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.preview-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  position: sticky;
  top: 1.5rem;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
}

.preview-header h2 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.preview-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.preview-frame {
  padding: 1.5rem;
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(45deg, #ebe6df 25%, transparent 25%),
    linear-gradient(-45deg, #ebe6df 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ebe6df 75%),
    linear-gradient(-45deg, transparent 75%, #ebe6df 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #f0ebe4;
}

.preview-empty {
  text-align: center;
  color: var(--text-muted);
}

.preview-empty-icon {
  font-size: 3rem;
  opacity: 0.3;
  display: block;
  margin-bottom: 0.5rem;
}

.preview-empty p {
  font-size: 0.9rem;
}

#canvas {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: var(--shadow-lg);
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-area {
    position: static;
  }
}
