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

:root {
  --primary: #f59e0b;
  --primary-dark: #d97706;
  --primary-light: #fef3c7;
  --accent: #000000;
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-hover: #f5f5f4;
  --text: #1c1917;
  --text-secondary: #78716c;
  --text-muted: #a8a29e;
  --border: #e7e5e4;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --max-width: 600px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
header {
  background: var(--accent);
  color: #fff;
  text-align: center;
  padding: 20px 16px 16px;
}

.header-inner h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.logo-icon {
  font-size: 1.4rem;
}

.tagline {
  font-size: 0.85rem;
  color: var(--primary);
  margin-top: 4px;
  font-weight: 600;
}

/* ===== Main ===== */
main {
  flex: 1;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ===== Input Section ===== */
.input-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.input-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text);
}

.input-textarea {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
  transition: border-color 0.2s;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.input-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.input-textarea::placeholder {
  color: var(--text-muted);
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

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

/* ===== Generate Button ===== */
.btn-generate {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary);
  color: var(--accent);
  border: none;
  border-radius: 100px;
  padding: 12px 28px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.btn-generate:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-generate:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn-generate .btn-icon {
  font-size: 1.2rem;
}

/* ===== Loading ===== */
.loading {
  text-align: center;
  padding: 40px 20px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ===== Results ===== */
.results-section {
  margin-top: 24px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.result-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: box-shadow 0.2s;
}

.result-card:hover {
  box-shadow: var(--shadow-md);
}

.result-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.result-type {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-dark);
  background: var(--primary-light);
  padding: 4px 12px;
  border-radius: 100px;
}

.btn-copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-copy:hover {
  background: var(--surface-hover);
  border-color: var(--text-muted);
  color: var(--text);
}

.btn-copy.copied {
  border-color: var(--success);
  color: var(--success);
}

.result-text {
  font-size: 0.95rem;
  line-height: 1.8;
  white-space: pre-wrap;
  color: var(--text);
  margin-bottom: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.result-tip {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.result-tip-icon {
  flex-shrink: 0;
  margin-top: 1px;
}

/* ===== History ===== */
.history-section {
  margin-top: 32px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.btn-text-danger {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

.btn-text-danger:hover {
  background: #fef2f2;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
}

.history-item:hover {
  background: var(--surface-hover);
  box-shadow: var(--shadow-md);
}

.history-item-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.history-item-input {
  font-size: 0.85rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.btn-history-action {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-history-delete {
  color: var(--danger);
  border-color: transparent;
}

.btn-history-delete:hover {
  background: #fef2f2;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--accent);
  color: #fff;
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 1000;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

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

/* ===== Error Banner ===== */
.error-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--danger);
  color: #fff;
  padding: 12px 16px;
  font-size: 0.8rem;
  z-index: 9999;
  text-align: center;
  word-break: break-all;
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .header-inner h1 {
    font-size: 1.4rem;
  }

  .input-section {
    padding: 16px;
  }

  .input-footer {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .btn-generate {
    justify-content: center;
    width: 100%;
  }

  .char-count {
    text-align: right;
  }
}
