/* ============================================================
   CANVAS Image Prompt Generator — Muji-inspired Design System
   ============================================================ */

/* --- Design Tokens --- */
:root {
  --bg:                #F7F6F2;
  --surface:           #EFEDE7;
  --surface-hover:     #E8E6DF;
  --border:            #D8D5CC;
  --border-focus:      #A8A49B;
  --text-primary:      #2C2B28;
  --text-muted:        #8A8780;
  --text-label:        #6B6965;
  --chip-bg:           #E4E1D8;
  --chip-text:         #4A4845;
  --chip-active-bg:    #2C2B28;
  --chip-active-text:  #F7F6F2;
  --chip-hover-bg:     #D8D5CC;
  --copy-bg:           #2C2B28;
  --copy-text:         #F7F6F2;
  --copy-hover-bg:     #4A4845;
  --counter-active:    #2C2B28;

  --radius-sm:         6px;
  --radius-md:         10px;
  --radius-pill:       20px;
  --spacing-sm:        12px;
  --spacing-md:        20px;
  --spacing-lg:        28px;
  --font:              'Inter', system-ui, -apple-system, sans-serif;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* --- Site Header --- */
.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.site-title {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-primary);
}

.site-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* --- Language Toggle --- */
.lang-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  color: var(--text-muted);
  transition: border-color 0.15s ease;
}

.lang-toggle:hover {
  border-color: var(--border-focus);
}

.lang-sep {
  color: var(--border);
  font-size: 10px;
}

.lang-opt {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  transition: color 0.15s ease, font-weight 0.15s ease;
  cursor: pointer;
}

.lang-opt.active {
  color: var(--text-primary);
  font-weight: 500;
}

/* ============================================================
   Two-column layout
   Desktop: output panel (left, sticky) | form (right, scrollable)
   Mobile:  output panel (top) then form (bottom)
   ============================================================ */

.app-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  align-items: start;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px 60px;
}

/* --- Output Panel (left column on desktop) --- */
.output-panel {
  position: sticky;
  top: 0;
  padding: 28px 24px 28px 0;
  border-right: 1px solid var(--border);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.output-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.output-textarea {
  width: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  resize: none;
  overflow: hidden;   /* JS grows height instead */
  min-height: 120px;
  line-height: 1.75;
  outline: none;
  cursor: default;
  transition: border-color 0.15s ease;
}

.output-textarea::placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
  line-height: 1.6;
}

/* --- Output action buttons --- */
.output-actions {
  display: flex;
  gap: 8px;
}

.copy-btn {
  flex: 1;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--copy-text);
  background-color: var(--copy-bg);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.copy-btn:hover {
  background-color: var(--copy-hover-bg);
}

.copy-btn:active {
  transform: scale(0.97);
}

.copy-btn.copied {
  background-color: #5C7A5C;
}

.clear-btn-panel {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.clear-btn-panel:hover {
  color: var(--text-primary);
  border-color: var(--border-focus);
}

/* --- Main Content (right column on desktop) --- */
.main-content {
  padding: 28px 0 60px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- CANVAS Field Cards --- */
.canvas-field {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.canvas-field:focus-within {
  border-color: var(--border-focus);
}

/* --- Field Label Row --- */
.field-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.field-letter {
  font-size: 18px;
  font-weight: 300;
  color: var(--text-muted);
  line-height: 1;
  min-width: 14px;
}

.field-name {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-primary);
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

/* --- Text Inputs --- */
.field-input {
  width: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s ease;
  line-height: 1.5;
}

.field-input:focus {
  border-color: var(--border-focus);
}

.field-input::placeholder {
  color: var(--text-muted);
  font-size: 13px;
}

/* Small variant for manual chip input */
.field-input-small {
  width: 100%;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-primary);
  background-color: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 5px 0;
  outline: none;
  transition: border-color 0.15s ease;
}

.field-input-small:focus {
  border-bottom-color: var(--border-focus);
}

.field-input-small::placeholder {
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}

/* --- Manual Input Row --- */
.manual-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.manual-input-prefix {
  font-size: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
  line-height: 1;
}

/* --- Chip Grid --- */
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

/* --- Chips --- */
.chip {
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 400;
  color: var(--chip-text);
  background-color: var(--chip-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 5px 13px;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
  line-height: 1.4;
  user-select: none;
}

.chip:hover {
  background-color: var(--chip-hover-bg);
}

.chip.active {
  background-color: var(--chip-active-bg);
  color: var(--chip-active-text);
  border-color: var(--chip-active-bg);
}

/* --- Chip Category Labels (inline inside flex grid) --- */
.chip-category-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.chip-category-label--inline {
  width: 100%;
  margin-top: 6px;
  margin-bottom: 0;
}

.chip-category-break {
  width: 100%;
  height: 0;
}

/* --- Aesthetic Counter --- */
.aesthetic-counter {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  transition: color 0.15s ease;
}

.aesthetic-counter.active {
  color: var(--counter-active);
  font-weight: 500;
}

/* --- History Panel --- */
.history-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.history-toggle {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: color 0.15s ease;
  width: 100%;
}

.history-toggle:hover {
  color: var(--text-primary);
}

.history-toggle-icon {
  display: inline-block;
  font-size: 14px;
  transition: transform 0.2s ease;
  line-height: 1;
}

.history-toggle[aria-expanded="true"] .history-toggle-icon {
  transform: rotate(90deg);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 10px;
}

/* History entry card */
.history-entry {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.history-entry-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-meta {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.history-prompt-text {
  font-size: 12px;
  color: var(--text-label);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.5;
}

.history-actions {
  display: flex;
  gap: 4px;
}

.history-action-btn {
  font-family: var(--font);
  font-size: 11px;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease, background-color 0.12s ease;
  white-space: nowrap;
}

.history-action-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-focus);
  background-color: var(--surface-hover);
}

/* Empty history state */
.history-empty {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  padding: 4px 0;
}

/* --- Site Footer --- */
.site-footer {
  text-align: center;
  padding: var(--spacing-md) 24px 40px;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Mobile layout (< 768px): single column, output on top
   ============================================================ */

@media (max-width: 767px) {
  .site-header {
    padding: 16px 16px 14px;
  }

  .app-layout {
    display: block;
    padding: 0 16px 40px;
  }

  .output-panel {
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 20px 0 20px;
    min-height: auto;
    gap: 12px;
  }

  .output-textarea {
    min-height: 80px;
    font-size: 14px;
  }

  .main-content {
    padding: 20px 0 40px;
  }

  .history-entry {
    flex-direction: column;
  }
}

/* --- Accessibility: reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
