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

:root {
  --brand: #FF6B2C;
  --brand-hover: #E55A1B;
  --dark: #1C1C28;
  --bg: #FAFAF7;
  --card: #FFFFFF;
  --border: #E8E6E1;
  --muted: #8B8B9A;
  --success: #059669;
  --error-bg: #FEF2F2;
  --error-border: #FECACA;
  --error-text: #B91C1C;
}

body {
  font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--dark);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px 40px;
}

.container {
  width: 100%;
  max-width: 620px;
}

/* --- Header & Logo --- */
header {
  margin-bottom: 36px;
}

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

.logo-icon {
  width: 36px;
  height: 43px;
  color: var(--brand);
  flex-shrink: 0;
}

header h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--dark);
}

.subtitle {
  margin-top: 8px;
  font-size: 16px;
  color: var(--muted);
  font-weight: 400;
}

/* --- URL Input Group --- */
.input-group {
  display: flex;
  gap: 10px;
}

#url-input {
  flex: 1;
  padding: 14px 18px;
  font-size: 15px;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--dark);
  outline: none;
  transition: border-color 0.2s;
}

#url-input:focus {
  border-color: var(--brand);
}

#url-input::placeholder {
  color: #bbb;
}

#archive-btn {
  padding: 14px 28px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--brand);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

#archive-btn:hover {
  background: var(--brand-hover);
}

#archive-btn:active {
  transform: scale(0.97);
}

#archive-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* --- Usage Bar --- */
.usage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding: 0 4px;
  font-size: 12px;
  color: var(--muted);
}

.usage-dots {
  display: flex;
  gap: 6px;
}

.usage-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s;
}

.usage-dot.active {
  background: var(--brand);
}

.usage-bar.pro {
  color: var(--success);
  font-weight: 600;
}

/* --- Upgrade Banner --- */
.upgrade-banner {
  margin-top: 20px;
  padding: 24px;
  background: linear-gradient(135deg, #1C1C28 0%, #2D2D3F 100%);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.upgrade-banner[hidden] {
  display: none;
}

.upgrade-icon {
  width: 36px;
  height: 36px;
  color: var(--brand);
}

.upgrade-icon svg {
  width: 100%;
  height: 100%;
}

.upgrade-body strong {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}

.upgrade-body p {
  margin-top: 4px;
  font-size: 13px;
  color: #9898A8;
  line-height: 1.4;
}

.upgrade-btn {
  width: 100%;
  padding: 14px 28px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(255, 107, 44, 0.4);
}

.upgrade-btn:hover {
  background: var(--brand-hover);
  box-shadow: 0 6px 20px rgba(255, 107, 44, 0.5);
}

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

/* --- Error --- */
.error-msg {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 10px;
  color: var(--error-text);
  font-size: 14px;
}

/* --- Cage Animation Area --- */
.cage-area {
  margin-top: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cage-scene {
  position: relative;
  width: 100px;
  height: 120px;
}

/* Page document icon — always visible, centered, behind cage */
.page-doc {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  color: var(--border);
  transition: color 0.4s;
  z-index: 1;
}

.page-doc svg {
  width: 100%;
  height: auto;
}

/* Cage bars — hidden by default, drops in on fetch, renders in front of page */
.cage-bars {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 72px;
  color: var(--muted);
  opacity: 0;
  transition: top 0.7s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s, color 0.4s;
  pointer-events: none;
  z-index: 2;
}

.cage-bars svg {
  width: 100%;
  height: auto;
}

/* --- Caging state: cage drops down --- */
.cage-area.caging .cage-bars {
  top: 0;
  opacity: 1;
  color: var(--brand);
  animation: cage-pulse 1.5s ease-in-out infinite;
}

.cage-area.caging .page-doc {
  color: var(--dark);
}

@keyframes cage-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* --- Caged state: success --- */
.cage-area.caged .cage-bars {
  top: 0;
  opacity: 1;
  color: var(--success);
  animation: none;
}

.cage-area.caged .page-doc {
  color: var(--success);
}

.cage-area.caged .cage-status {
  color: var(--success);
  font-weight: 600;
}

/* Status text under cage */
.cage-status {
  margin-top: 16px;
  font-size: 14px;
  color: var(--muted);
  transition: color 0.3s;
}

/* --- Result --- */
.result {
  margin-top: 32px;
}

.article-preview {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
}

.article-preview h2 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--dark);
}

.article-meta {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.article-excerpt {
  margin-top: 16px;
  font-size: 14px;
  line-height: 1.6;
  color: #666;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- PDF Button --- */
.pdf-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  margin-top: 20px;
  padding: 22px 32px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(255, 107, 44, 0.3);
}

.pdf-btn:hover {
  background: var(--brand-hover);
  box-shadow: 0 6px 24px rgba(255, 107, 44, 0.4);
}

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

.pdf-btn:disabled {
  background: #ccc;
  box-shadow: none;
  cursor: wait;
}

.pdf-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.pdf-btn-text {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.pdf-btn-text strong {
  font-size: 18px;
  font-weight: 700;
}

.pdf-btn-text small {
  font-size: 12px;
  opacity: 0.85;
  font-weight: 400;
}

/* --- History --- */
.history {
  margin-top: 48px;
  border-top: 1px solid var(--border);
  padding-top: 32px;
}

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

.history-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--dark);
}

.clear-history-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}

.clear-history-btn:hover {
  color: var(--error-text);
  background: var(--error-bg);
}

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

.history-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  transition: border-color 0.2s;
}

.history-card:hover {
  border-color: #ccc;
}

.history-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--dark);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-card-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.history-card-excerpt {
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.5;
  color: #888;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.history-card-actions button {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  border: none;
}

.history-card-actions button:active {
  transform: scale(0.96);
}

.history-download-btn {
  background: var(--brand);
  color: #fff;
}

.history-download-btn:hover {
  background: var(--brand-hover);
}

.history-download-btn:disabled {
  background: #ccc;
  cursor: wait;
}

.history-delete-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border) !important;
}

.history-delete-btn:hover {
  color: var(--error-text);
  border-color: var(--error-border) !important;
  background: var(--error-bg);
}

/* --- Responsive --- */
@media (max-width: 500px) {
  body {
    padding: 40px 16px 32px;
  }

  header h1 {
    font-size: 26px;
  }

  .input-group {
    flex-direction: column;
  }

  #archive-btn {
    width: 100%;
  }

  .pdf-btn {
    padding: 18px 24px;
  }
}
