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

:root {
  --parchment: #f5e6c8;
  --parchment-light: #faf0dc;
  --parchment-dark: #e8d5a8;
  --ink: #2c1810;
  --ink-light: #5c3a28;
  --ink-muted: #8b6f5a;
  --gold: #c9a84c;
  --gold-light: #e8d48a;
  --gold-dark: #a8862a;
  --accent: #8b3a3a;
  --accent-light: #b85454;
  --shadow: rgba(44, 24, 16, 0.1);
  --shadow-strong: rgba(44, 24, 16, 0.2);
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Noto Sans', -apple-system, sans-serif;
}

body {
  font-family: var(--font-body);
  font-size: 17px;
  color: var(--ink);
  min-height: 100vh;
  background-color: #d4c4a0;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(200, 180, 140, 0.4) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 30%, rgba(180, 160, 120, 0.3) 0%, transparent 50%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(139, 111, 90, 0.03) 2px,
      rgba(139, 111, 90, 0.03) 4px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 3px,
      rgba(139, 111, 90, 0.02) 3px,
      rgba(139, 111, 90, 0.02) 6px
    );
  background-attachment: fixed;
  line-height: 1.6;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  min-height: 100vh;
  position: relative;
}

.container::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(245, 230, 200, 0.5) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(232, 213, 168, 0.4) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.container > * {
  position: relative;
  z-index: 1;
}

.header {
  text-align: center;
  padding: 30px 20px 24px;
  margin-bottom: 24px;
  position: relative;
}

.header-decoration {
  position: absolute;
  top: 0; left: 10%; right: 10%;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), var(--gold-light), var(--gold), transparent);
  border-radius: 2px;
}

.header-title {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.03em;
  margin-bottom: 8px;
  text-shadow: 1px 1px 2px rgba(44, 24, 16, 0.1);
}

.header-subtitle {
  font-size: 1rem;
  color: var(--ink-muted);
  font-style: italic;
}

.filters {
  background: linear-gradient(135deg, var(--parchment-light), var(--parchment));
  border: 1px solid var(--parchment-dark);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}

.filters-toggle {
  width: 100%;
  padding: 16px 20px;
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.2s;
}

.filters-toggle:hover {
  background: rgba(201, 168, 76, 0.08);
}

.filters-toggle .chevron {
  transition: transform 0.3s ease;
}

.filters-toggle[aria-expanded="false"] .chevron {
  transform: rotate(-90deg);
}

.filters-content {
  padding: 0 18px 18px;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
  max-height: 500px;
  opacity: 1;
}

.filters-toggle[aria-expanded="false"] + .filters-content {
  max-height: 0;
  padding: 0 18px;
  opacity: 0;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.form-group {
  margin-bottom: 12px;
}

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

label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink-light);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

input, textarea, select {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--parchment-dark);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

input:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.15);
}

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

.form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-primary {
  width: 100%;
  justify-content: center;
  padding: 16px 28px;
  background: linear-gradient(135deg, var(--gold-dark), var(--gold));
  color: var(--parchment-light);
  font-family: var(--font-body);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: var(--radius);
  margin-bottom: 24px;
  box-shadow: 0 4px 16px rgba(168, 134, 42, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 24px rgba(168, 134, 42, 0.4);
  transform: translateY(-1px);
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-group {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.btn-group .btn-primary {
  margin-bottom: 0;
  flex: 1;
}

.btn-stop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px 20px;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  background: rgba(139, 58, 58, 0.08);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-stop:hover {
  background: rgba(139, 58, 58, 0.15);
  border-color: var(--accent-light);
}

.btn-secondary {
  background: rgba(201, 168, 76, 0.12);
  color: var(--ink-light);
  border: 1px solid rgba(201, 168, 76, 0.3);
  font-size: 0.82rem;
  padding: 8px 14px;
}

.btn-secondary:hover {
  background: rgba(201, 168, 76, 0.2);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 0 4px;
  flex-wrap: wrap;
  gap: 12px;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.toggle-text {
  font-size: 0.82rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--parchment-dark);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

.toggle-switch input:checked + .toggle-slider {
  background: linear-gradient(135deg, var(--gold-dark), var(--gold));
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.card-count-control {
  display: flex;
  gap: 4px;
}

.count-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--parchment-dark);
  background: rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-light);
  cursor: pointer;
  transition: all 0.2s;
}

.count-btn.active {
  background: var(--gold);
  color: var(--parchment-light);
  border-color: var(--gold);
  box-shadow: 0 2px 8px rgba(201, 168, 76, 0.3);
}

.count-btn:hover:not(.active) {
  background: rgba(201, 168, 76, 0.15);
}

.cards-section {
  margin-bottom: 24px;
  min-height: 100px;
}

.cards-grid {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  perspective: 1000px;
}

.tarot-card {
  width: 160px;
  height: 240px;
  position: relative;
  border-radius: 8px;
  background: var(--parchment);
  border: 2px solid var(--gold);
  box-shadow: 0 4px 16px var(--shadow-strong);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: default;
}

.tarot-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-bottom: 1px solid var(--gold);
  display: block;
}

.tarot-card .card-name {
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
  line-height: 1.3;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  z-index: 2;
}

.card-badge.reversed {
  background: var(--accent);
  color: white;
}

.card-badge.upright {
  background: var(--gold);
  color: var(--ink);
}

.response-section {
  background: linear-gradient(135deg, var(--parchment-light), var(--parchment));
  border: 1px solid var(--parchment-dark);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px var(--shadow);
  padding: 24px;
  min-height: 60px;
  display: none;
  position: relative;
}

.response-section::before {
  content: '☥';
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.2rem;
  color: var(--gold);
  background: var(--parchment);
  padding: 0 12px;
}

.response-section.visible {
  display: block;
}

.response-content {
  font-family: var(--font-body);
  font-size: 1.1rem;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
}

.response-content .typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--gold);
  margin-left: 2px;
  animation: blink 0.8s step-end infinite;
  vertical-align: text-bottom;
}

@keyframes blink {
  50% { opacity: 0; }
}

.response-loading {
  display: none;
  text-align: center;
  padding: 30px 0;
}

.response-loading.visible {
  display: block;
}

.loading-label {
  margin-top: 16px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.progress-ring {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 0 auto;
}

.progress-ring svg {
  width: 100%;
  height: 100%;
  animation: spin 1.2s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.progress-bg {
  fill: none;
  stroke: rgba(201, 168, 76, 0.15);
  stroke-width: 6;
}

.progress-fill {
  fill: none;
  stroke: #c9a84c;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 170;
  stroke-dashoffset: 0;
  animation: pulse 1.2s ease-in-out infinite;
  filter: drop-shadow(0 0 4px rgba(201, 168, 76, 0.4));
}

@keyframes pulse {
  0% { stroke-dashoffset: 170; opacity: 0.6; }
  50% { stroke-dashoffset: 0; opacity: 1; }
  100% { stroke-dashoffset: -170; opacity: 0.6; }
}

@media (max-width: 600px) {
  .container {
    padding: 12px 12px 32px;
  }

  .header {
    padding: 24px 12px 20px;
  }

  .header-title {
    font-size: 1.5rem;
  }

  .header-subtitle {
    font-size: 0.8rem;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .control-group {
    justify-content: center;
  }

  .tarot-card {
    width: 140px;
    height: 210px;
  }

  .tarot-card img {
    height: 140px;
  }

  .tarot-card .card-name {
    font-size: 0.78rem;
    padding: 6px 8px;
  }

  .response-section {
    padding: 16px;
  }

  .response-content {
    font-size: 0.95rem;
  }

  .filters-content {
    padding: 0 14px 14px;
  }
}

@media (min-width: 601px) and (max-width: 900px) {
  .tarot-card {
    width: 150px;
    height: 225px;
  }

  .tarot-card img {
    height: 150px;
  }
}

@keyframes cardAppear {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.tarot-card.appearing {
  animation: cardAppear 0.4s ease-out both;
}

.tarot-card.appearing:nth-child(1) { animation-delay: 0.1s; }
.tarot-card.appearing:nth-child(2) { animation-delay: 0.2s; }
.tarot-card.appearing:nth-child(3) { animation-delay: 0.3s; }
.tarot-card.appearing:nth-child(4) { animation-delay: 0.4s; }
.tarot-card.appearing:nth-child(5) { animation-delay: 0.5s; }
