/* ============================================================
   Brand Style Guide Generator — style.css
   Mobile-first, AdSense-ready
   ============================================================ */

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

:root {
  --color-bg: #f1f5f9;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-muted: #64748b;
  --color-accent: #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", "Hiragino Kaku Gothic Pro", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ============================================================
   Site Header
   ============================================================ */

.site-header {
  background: #1e293b;
  color: #fff;
  padding: 0.875rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.back-link {
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.875rem;
  white-space: nowrap;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 0.25rem;
  transition: color 0.15s;
  flex-shrink: 0;
}

.back-link:hover {
  color: #fff;
}

.header-title h1 {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  color: #fff;
}

.subtitle {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 0.125rem;
  display: none;
}

/* ============================================================
   App Layout (two-column on desktop)
   ============================================================ */

.app-layout {
  display: flex;
  flex-direction: column;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 60px);
}

/* ============================================================
   Input Panel (Left)
   ============================================================ */

.input-panel {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-scroll {
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ============================================================
   Form Sections
   ============================================================ */

.form-section {
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.form-group {
  margin-bottom: 0.75rem;
}

.form-group:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-muted);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  border: 1.5px solid var(--color-border);
  border-radius: 6px;
  background: #fff;
  color: var(--color-text);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

textarea {
  resize: vertical;
  min-height: 64px;
}

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

/* ============================================================
   Color Grid
   ============================================================ */

.color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
}

.color-item label {
  margin-bottom: 0.375rem;
}

.color-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.color-picker {
  width: 44px !important;
  height: 44px;
  padding: 2px;
  border-radius: 6px;
  cursor: pointer;
  border: 1.5px solid var(--color-border);
  flex-shrink: 0;
}

.hex-input {
  flex: 1;
  min-width: 0;
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 0.85rem;
  padding: 0.4rem 0.5rem;
}

.color-values {
  margin-top: 0.375rem;
  font-size: 0.7rem;
  color: var(--color-muted);
  font-family: "SF Mono", "Consolas", monospace;
  line-height: 1.8;
}

/* ============================================================
   Action Buttons
   ============================================================ */

.action-buttons {
  display: flex;
  gap: 0.625rem;
  margin-top: 0.25rem;
}

.btn-primary {
  flex: 1;
  min-height: 56px;
  padding: 0.875rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  font-family: inherit;
}

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

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  min-height: 56px;
  padding: 0.875rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  background: transparent;
  color: var(--color-muted);
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.btn-secondary:hover {
  background: #fee2e2;
  color: var(--color-danger);
  border-color: #fecaca;
}

/* ============================================================
   Ad Units
   ============================================================ */

.ad-unit {
  margin: 1.25rem 0;
}

/* ============================================================
   Preview Panel (Right)
   ============================================================ */

.preview-panel {
  background: #e8edf3;
  padding: 1rem;
  overflow-y: auto;
}

/* ============================================================
   Style Guide Preview Document
   ============================================================ */

.sg-doc {
  background: #fff;
  max-width: 760px;
  margin: 0 auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

/* SG Cover */
.sg-cover {
  padding: 2.5rem 2rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sg-logo-wrap {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Logo: text style */
.sg-logo-text {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.sg-logo-tagline {
  font-size: 0.8rem;
  opacity: 0.75;
  margin-top: 0.125rem;
  letter-spacing: 0.02em;
}

/* Logo: initial style */
.sg-logo-initial {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 900;
  flex-shrink: 0;
}

/* Logo: badge style */
.sg-logo-badge {
  padding: 0.5rem 1.25rem;
  border-radius: 9999px;
  font-size: 1.25rem;
  font-weight: 700;
  border: 2.5px solid currentColor;
  letter-spacing: 0.04em;
}

.sg-brand-meta h2 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.6;
  margin-bottom: 0.375rem;
}

.sg-brand-desc {
  font-size: 0.85rem;
  opacity: 0.85;
  line-height: 1.6;
  max-width: 480px;
}

/* SG Section */
.sg-section {
  padding: 1.75rem 2rem;
  border-top: 1px solid #e9ecef;
}

.sg-section-heading {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #888;
  margin-bottom: 1.25rem;
  font-weight: 700;
}

/* Color Palette */
.sg-palette {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
}

.sg-color-chip {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.sg-color-swatch {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.08);
  min-height: 52px;
}

.sg-color-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
}

.sg-color-hex {
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 0.7rem;
  color: #333;
  word-break: break-all;
}

.sg-color-extra {
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 0.62rem;
  color: #888;
  line-height: 1.7;
}

/* Typography */
.sg-type-row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sg-type-block {
  padding: 1rem;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.sg-type-meta {
  font-size: 0.65rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
  font-weight: 700;
}

.sg-type-sample-heading {
  line-height: 1.3;
  margin-bottom: 0.375rem;
}

.sg-type-sample-body {
  line-height: 1.6;
  opacity: 0.85;
}

.sg-scale-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.sg-scale-table th {
  text-align: left;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.sg-scale-table td {
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.sg-scale-table td:first-child {
  color: #888;
  font-size: 0.75rem;
}

/* Usage Rules */
.sg-usage-rule {
  font-size: 0.85rem;
  padding: 0.75rem 1rem;
  background: #f8fafc;
  border-radius: 8px;
  border-left: 3px solid;
  line-height: 1.6;
  color: #475569;
}

/* ============================================================
   Content Area (SEO / Howto)
   ============================================================ */

.content-area {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.howto-section {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-top: 0.5rem;
}

.howto-section h2 {
  font-size: 1.05rem;
  color: var(--color-text);
  margin-bottom: 0.875rem;
  margin-top: 1.5rem;
}

.howto-section h2:first-child {
  margin-top: 0;
}

.howto-list {
  padding-left: 1.375rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.howto-list li {
  font-size: 0.9rem;
  color: #475569;
  line-height: 1.6;
}

.howto-section p {
  font-size: 0.9rem;
  color: #475569;
  line-height: 1.75;
}

/* ============================================================
   Site Footer
   ============================================================ */

.site-footer {
  text-align: center;
  padding: 1.75rem 1rem;
  font-size: 0.82rem;
  color: #94a3b8;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.site-footer a {
  color: #64748b;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* ============================================================
   Responsive — Tablet (640px+)
   ============================================================ */

@media (min-width: 640px) {
  .subtitle {
    display: block;
  }

  .header-title h1 {
    font-size: 1.1rem;
  }

  .panel-scroll {
    padding: 1.25rem;
  }

  .sg-palette {
    gap: 1rem;
  }
}

/* ============================================================
   Responsive — Desktop (900px+)
   ============================================================ */

@media (min-width: 900px) {
  .app-layout {
    flex-direction: row;
    height: calc(100vh - 68px);
  }

  .input-panel {
    width: 380px;
    min-width: 320px;
    max-width: 420px;
    flex-shrink: 0;
    height: 100%;
  }

  .panel-scroll {
    height: 100%;
    overflow-y: auto;
  }

  .preview-panel {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    padding: 1.5rem;
  }
}

/* ============================================================
   Print Styles (for PDF export)
   ============================================================ */

@media print {
  body {
    background: #fff;
    font-size: 11pt;
  }

  .site-header,
  .input-panel,
  .content-area,
  .site-footer,
  .ad-unit {
    display: none !important;
  }

  .app-layout {
    display: block;
    height: auto;
  }

  .preview-panel {
    display: block;
    padding: 0;
    background: #fff;
    overflow: visible;
  }

  .sg-doc {
    box-shadow: none;
    border-radius: 0;
    max-width: 100%;
  }

  .sg-section {
    break-inside: avoid;
  }

  .sg-palette {
    grid-template-columns: repeat(5, 1fr);
  }

  @page {
    margin: 15mm 15mm 15mm 15mm;
    size: A4;
  }
}
