:root {
  color-scheme: light;
  --bg-gradient-start: #637aff;
  --bg-gradient-end: #ab6cff;
  --card-bg: rgba(255, 255, 255, 0.26);
  --card-border: rgba(255, 255, 255, 0.35);
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --accent: #4d64ff;
  --accent-strong: #243aff;
  --danger: #ef4444;
  --shadow-color: rgba(21, 41, 64, 0.25);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text-primary);
  background: #0f172a;
  position: relative;
  overflow-x: hidden;
}

.background-gradient {
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 120% at top left, var(--bg-gradient-start), rgba(255, 255, 255, 0)),
              radial-gradient(140% 140% at bottom right, var(--bg-gradient-end), rgba(255, 255, 255, 0));
  filter: blur(40px);
  z-index: -2;
}

.app-header,
.app-footer {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
  color: white;
}

.app-header h1 {
  font-size: clamp(2rem, 3vw, 3rem);
  margin: 0;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.75rem auto 0;
  max-width: 40rem;
  font-weight: 300;
  line-height: 1.6;
}

.app-footer {
  font-size: 0.85rem;
  opacity: 0.8;
}

.layout {
  width: min(960px, 92vw);
  margin: 0 auto 3rem;
  display: grid;
  gap: 1.5rem;
}

.card {
  padding: clamp(1.5rem, 2.5vw, 2.75rem);
  border-radius: 18px;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  box-shadow: 0 25px 50px -20px var(--shadow-color);
  color: var(--text-primary);
}

.input-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.input-stack .primary-button,
.input-stack .status-message {
  align-self: flex-start;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

textarea {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.4);
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.5;
  resize: vertical;
  min-height: 110px;
  transition: box-shadow 0.3s ease, transform 0.2s ease;
}

textarea:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(77, 100, 255, 0.35);
  transform: translateY(-2px);
}

.primary-button,
.secondary-button,
.ghost-button,
.filter-toggle button {
  font: inherit;
  border-radius: 999px;
  border: none;
  padding: 0.75rem 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.primary-button {
  background: linear-gradient(120deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: white;
  font-weight: 600;
  margin-top: 1.25rem;
  position: relative;
  overflow: hidden;
}

.primary-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 30px -18px rgba(38, 56, 255, 0.7);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
  box-shadow: none;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.45);
  color: var(--accent-strong);
  font-weight: 600;
}

.secondary-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 22px -16px rgba(25, 29, 88, 0.45);
}

.ghost-button {
  background: transparent;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.45);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

.ghost-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px -18px rgba(255, 255, 255, 0.6);
}

.filter-toggle {
  background: rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  padding: 0.25rem;
  display: inline-flex;
  gap: 0.25rem;
}

.filter-toggle button {
  background: transparent;
  color: var(--text-secondary);
  padding-inline: 0.9rem;
  font-size: 0.85rem;
}

.filter-toggle button.is-active {
  background: white;
  color: var(--accent-strong);
  font-weight: 600;
  box-shadow: 0 8px 20px -14px rgba(58, 73, 231, 0.6);
}

.api-controls {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.api-controls label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.api-controls select,
.api-controls input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.5);
  padding: 0.7rem 0.9rem;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.api-controls input:focus,
.api-controls select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(77, 100, 255, 0.25);
}

.api-key[data-visible="false"] {
  display: none;
}

.status-message {
  min-height: 1.5rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.status-message.error {
  color: var(--danger);
}

.sample-label {
  margin-top: 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: rgba(15, 23, 42, 0.82);
}

.sample-chips {
  margin-top: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sample-chips button {
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  padding: 0.45rem 1rem;
  background: rgba(255, 255, 255, 0.55);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.sample-chips button:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 12px 20px -18px rgba(21, 41, 64, 0.35);
  color: var(--accent-strong);
}

.loader {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: rgba(255, 255, 255, 1);
  animation: spin 1s linear infinite;
  display: none;
}

.primary-button.loading .loader {
  display: inline-block;
}

.primary-button.loading span:first-child {
  opacity: 0.7;
}

.canvas-wrapper {
  margin-top: 1.5rem;
  display: grid;
  gap: 1rem;
  justify-items: center;
}

#shareCanvas {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  max-width: 100%;
  box-shadow: 0 20px 45px -30px rgba(15, 23, 42, 0.65);
}

#sharePreview {
  max-width: 100%;
  border-radius: 18px;
  box-shadow: 0 20px 30px -28px rgba(5, 10, 40, 0.6);
}

.share-area {
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

@media (min-width: 900px) {
  .layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .layout > section:nth-child(3) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .card {
    padding: 1.5rem;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .ghost-button {
    align-self: flex-end;
  }

  .input-stack {
    max-width: 100%;
  }

  textarea {
    min-height: 100px;
  }
}

@media (max-width: 480px) {
  .layout {
    width: min(520px, 94vw);
  }

  .app-header,
  .app-footer {
    padding-inline: 1.25rem;
  }

  .filter-toggle {
    width: 100%;
  }

  .filter-toggle button {
    flex: 1;
  }
}
