@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;700&family=Sora:wght@300;400;600&display=swap");

:root {
  --bg-1: #f7f2e9;
  --bg-2: #efe6d7;
  --ink: #1f1b16;
  --muted: #6b6256;
  --card: #ffffff;
  --accent: #d06c3f;
  --accent-2: #2b6e6a;
  --accent-3: #f2b365;
  --ring: rgba(208, 108, 63, 0.25);
  --shadow: 0 24px 60px rgba(31, 27, 22, 0.15);
  --shadow-soft: 0 10px 24px rgba(31, 27, 22, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Sora", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 800px at 10% 10%, #fff6e6 0%, var(--bg-1) 45%, var(--bg-2) 100%);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  border-radius: 999px;
  filter: blur(40px);
  opacity: 0.35;
  z-index: 0;
}

body::before {
  width: 380px;
  height: 380px;
  background: #f6c07c;
  top: -120px;
  left: -120px;
}

body::after {
  width: 460px;
  height: 460px;
  background: #7bc5ba;
  bottom: -160px;
  right: -160px;
}

#app {
  position: relative;
  z-index: 1;
}

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 56px 24px 72px;
  animation: fadeUp 0.6s ease both;
}

.hero {
  text-align: left;
  margin-bottom: 32px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.38em;
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 12px;
}

h1 {
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: clamp(34px, 5.2vw, 54px);
  margin: 0 0 12px;
  line-height: 1.05;
}

.sub {
  margin: 0;
  font-size: 16px;
  color: var(--muted);
  max-width: 560px;
}

.card {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.9));
  padding: 28px;
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.chat-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-messages {
  height: min(52vh, 520px);
  overflow: auto;
  padding: 14px;
  background: #f9f1e5;
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
}

.chat-empty {
  color: var(--muted);
  font-size: 14px;
}

.chat-bubble {
  max-width: 78%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  margin: 10px 0;
  white-space: normal;
}

.chat-bubble code {
  font-family: "SFMono-Regular", "Menlo", "Consolas", monospace;
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 6px;
}

.chat-bubble pre.chat-code {
  margin: 8px 0 0;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 10px;
  white-space: pre-wrap;
  font-family: "SFMono-Regular", "Menlo", "Consolas", monospace;
  font-size: 12px;
}

.chat-bubble.user {
  margin-left: auto;
  background: rgba(43, 110, 106, 0.14);
  border: 1px solid rgba(43, 110, 106, 0.2);
}

.chat-bubble.bot {
  margin-right: auto;
  background: rgba(208, 108, 63, 0.12);
  border: 1px solid rgba(208, 108, 63, 0.18);
}

.chat-form {
  display: flex;
  gap: 12px;
}

.chat-input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(31, 27, 22, 0.18);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
}

.chat-input::placeholder {
  color: #9b8f81;
}

.widget {
  min-height: 72px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.result,
.result-card {
  margin-top: 16px;
  padding: 18px;
  border-radius: 16px;
  background: #f9f1e5;
  color: var(--ink);
  font-size: 14px;
  text-align: left;
  box-shadow: var(--shadow-soft);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.settings-item {
  background: #f8efe4;
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow-soft);
}

.settings-label {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.settings-value {
  font-size: 18px;
  font-weight: 600;
}

.hint {
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
}

.hidden {
  display: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(90deg, var(--accent), var(--accent-3));
  color: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

/* Navigation */
.navigation {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.9);
  padding: 12px 20px;
  box-shadow: var(--shadow-soft);
  z-index: 100;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid rgba(31, 27, 22, 0.08);
  backdrop-filter: blur(10px);
}

.navigation::-webkit-scrollbar {
  display: none;
}

.nav-btn {
  padding: 9px 16px;
  background: transparent;
  border: 1px solid rgba(31, 27, 22, 0.2);
  border-radius: 999px;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.nav-btn:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
  transform: translateY(-1px);
}

.back-btn {
  padding: 6px 0;
  background: transparent;
  border: none;
  color: var(--accent-2);
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 16px;
  text-align: left;
  font-weight: 600;
}

.miniapp .back-btn {
  display: none;
}

/* Functions Grid */
.functions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-top: 32px;
}

.function-card {
  background: rgba(255, 255, 255, 0.95);
  padding: 22px;
  border-radius: 20px;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border 0.2s ease;
  text-align: left;
  border: 1px solid rgba(31, 27, 22, 0.08);
}

.function-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow);
  border-color: rgba(208, 108, 63, 0.3);
}

.function-icon {
  font-size: 36px;
  margin-bottom: 14px;
}

.function-card h3 {
  font-family: "Fraunces", serif;
  font-size: 22px;
  margin: 0 0 8px;
  color: var(--ink);
}

.function-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
  text-align: left;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--ink);
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(31, 27, 22, 0.15);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.9);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.form-group small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.btn {
  padding: 12px 22px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: #fff;
  box-shadow: var(--shadow-soft);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn-primary:disabled {
  background: var(--muted);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-small {
  padding: 6px 12px;
  font-size: 14px;
}

.btn-danger {
  background: #cc3d3d;
  color: #fff;
}

/* Result Cards */
.result-card h3 {
  font-family: "Fraunces", serif;
  font-size: 24px;
  margin: 0 0 16px;
  color: var(--ink);
}

.prediction-card {
  text-align: left;
}

.prediction-number {
  font-size: 28px;
  font-weight: 600;
  color: var(--accent-2);
  margin-bottom: 16px;
}

.prediction-text,
.compatibility-text {
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
}

/* Name Result */
.name-value,
.name-origin {
  margin: 12px 0;
  color: var(--ink);
}

.name-character {
  margin-top: 16px;
  line-height: 1.7;
  color: var(--ink);
}

/* Contacts */
.contact-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: #fff8ef;
  border-radius: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(31, 27, 22, 0.08);
}

.contact-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.contact-info strong {
  font-size: 16px;
  color: var(--ink);
}

.contact-info span {
  font-size: 13px;
  color: var(--muted);
}

/* Loading and Error */
.loading,
.error {
  text-align: center;
  padding: 24px;
  color: var(--muted);
}

.error {
  color: #cc3d3d;
}

.card h2 {
  font-family: "Fraunces", serif;
  font-size: 24px;
  margin: 0 0 20px;
  color: var(--ink);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 720px) {
  .page {
    padding: 28px 16px 56px;
  }

  .hero {
    text-align: left;
  }

  h1 {
    font-size: clamp(26px, 7vw, 36px);
  }

  .sub {
    font-size: 14px;
  }

  .card {
    padding: 18px;
    border-radius: 18px;
  }

  .navigation {
    padding: 10px 12px;
    gap: 6px;
  }

  .nav-btn {
    padding: 7px 10px;
    font-size: 12px;
  }

  .functions-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .chat-messages {
    height: min(50vh, 420px);
    padding: 12px;
  }

  .chat-form {
    flex-direction: column;
  }

  .chat-input {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .page {
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }

  .navigation {
    padding: 10px 14px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .nav-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  .chat-messages {
    height: min(46vh, 360px);
  }

  .contact-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .contact-item .btn {
    width: 100%;
  }
}

.miniapp .page {
  padding: 20px 14px 48px;
}

.miniapp h1 {
  font-size: clamp(24px, 7vw, 32px);
}

.miniapp .sub {
  font-size: 13px;
}

.miniapp .navigation {
  display: none;
}

.miniapp .nav-btn {
  padding: 6px 10px;
  font-size: 12px;
}

.miniapp .card {
  padding: 16px;
  border-radius: 16px;
}

.miniapp .function-card {
  padding: 16px;
}

.miniapp .function-card h3 {
  font-size: 18px;
}

.miniapp .function-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.miniapp .chat-messages {
  height: auto;
  flex: 1;
  min-height: 0;
}

.mini-nav {
  display: none;
}

body.miniapp .mini-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid rgba(31, 27, 22, 0.08);
  box-shadow: 0 -10px 24px rgba(31, 27, 22, 0.08);
  z-index: 120;
}

.mini-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--ink);
  padding: 6px 4px;
  border-radius: 12px;
}

.mini-nav-btn span {
  font-size: 11px;
  color: var(--muted);
}

body.miniapp .mini-nav-btn:active {
  background: rgba(208, 108, 63, 0.12);
}

body.miniapp,
body.miniapp #app,
body.miniapp #main-screen {
  height: 100dvh;
}

body.miniapp {
  overflow: hidden;
}

body.miniapp .page {
  height: 100dvh;
  padding: 12px 10px 76px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

body.miniapp .hero {
  margin-bottom: 8px;
}

body.miniapp .card {
  padding: 14px;
  border-radius: 14px;
}

body.miniapp .functions-grid {
  margin-top: 10px;
  gap: 10px;
}

body.miniapp .function-card {
  padding: 14px;
}

body.miniapp .chat-card {
  flex: 1;
  min-height: 0;
}

body.miniapp #page-chat .hero {
  margin-bottom: 6px;
}

body.miniapp .chat-messages {
  padding: 10px;
  border-radius: 12px;
}

body.miniapp .chat-form {
  gap: 8px;
}
