:root {
  color-scheme: light dark;
  --bg-start: #edf8ff;
  --bg-mid: #fbfdff;
  --bg-end: #eefcf5;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-strong: rgba(255, 255, 255, 0.92);
  --text: #111827;
  --muted: #758195;
  --muted-2: #9aa4b4;
  --blue: #2479e8;
  --blue-2: #28aee4;
  --green: #23b56e;
  --pink: #c24bb3;
  --orange: #d17b17;
  --shadow: 0 14px 34px rgba(35, 74, 108, 0.09);
  --shadow-soft: 0 10px 24px rgba(35, 74, 108, 0.06);
  --radius: 24px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: linear-gradient(135deg, var(--bg-start), var(--bg-mid) 48%, var(--bg-end));
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg-start), var(--bg-mid) 48%, var(--bg-end));
  touch-action: manipulation;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 430px);
  min-height: 100svh;
  margin: 0 auto;
  background:
    radial-gradient(circle at 85% 24%, rgba(141, 214, 255, 0.12), transparent 28%),
    radial-gradient(circle at 16% 82%, rgba(76, 213, 145, 0.14), transparent 26%);
}

.screen {
  min-height: 100svh;
  padding: calc(18px + var(--safe-top)) 20px calc(28px + var(--safe-bottom));
}

.home-screen {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.home-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-top: 42px;
}

.home-header h1 {
  margin: 0 0 6px;
  font-size: clamp(26px, 7vw, 30px);
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: 0;
}

.home-header p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 550;
}

.history-button,
.back-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  border-radius: 999px;
  color: var(--blue);
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 8px 20px rgba(53, 112, 176, 0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.history-button {
  padding: 0 13px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.soft-card,
.examples-card,
.history-row {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.path-card {
  border-radius: var(--radius);
  padding: 18px;
}

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

h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  font-weight: 800;
  letter-spacing: 0;
}

.text-button {
  padding: 0;
  color: var(--blue);
  background: transparent;
  font-size: 13px;
  font-weight: 700;
}

.text-button:disabled,
.icon-action:disabled,
.clear-history:disabled {
  opacity: 0.42;
  cursor: default;
}

.path-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 8px;
  width: 100%;
}

.path-step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.path-chevron {
  width: 7px;
  height: 11px;
  color: rgba(126, 139, 158, 0.6);
  flex: 0 0 auto;
}

.path-token {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 750;
  color: var(--text);
  background: rgba(235, 239, 245, 0.86);
  white-space: nowrap;
}

.path-token.root {
  color: #fff;
  background: linear-gradient(135deg, #2d90ff, #19acf0);
}

.result-card {
  position: relative;
  display: flex;
  min-height: 166px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  overflow: hidden;
  padding: 22px;
  border-radius: 28px;
  background: linear-gradient(135deg, #d9f9e5, #f0fff6);
  box-shadow: 0 18px 42px rgba(35, 181, 110, 0.16);
  animation: cardIn 220ms ease-out both;
}

.result-card.unknown {
  background: linear-gradient(135deg, #fff0d6, #fff9ea);
  box-shadow: 0 18px 42px rgba(209, 123, 23, 0.12);
}

.result-card::after {
  position: absolute;
  top: -48px;
  right: -42px;
  width: 120px;
  height: 120px;
  content: "";
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.36);
}

.result-copy {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.result-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

#resultTitle {
  color: #0b5e3a;
  font-size: 38px;
  line-height: 1.05;
  font-weight: 850;
  letter-spacing: 0;
}

.unknown #resultTitle {
  color: #8a520c;
}

#resultDesc {
  max-width: 210px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
  font-weight: 600;
}

.alias-pill {
  justify-self: start;
  padding: 6px 10px;
  border-radius: 999px;
  color: rgba(23, 144, 89, 0.86);
  background: rgba(255, 255, 255, 0.58);
  font-size: 12px;
  font-weight: 750;
}

.result-illustration {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 94px;
  height: 94px;
  flex: 0 0 auto;
}

.result-illustration::before,
.result-illustration::after {
  position: absolute;
  content: "";
  border-radius: 50%;
}

.result-illustration::before {
  width: 86px;
  height: 86px;
  background: rgba(255, 255, 255, 0.5);
}

.result-illustration::after {
  width: 64px;
  height: 64px;
  background: rgba(35, 181, 110, 0.18);
}

.unknown .result-illustration::after {
  background: rgba(209, 123, 23, 0.18);
}

.family-mark {
  position: relative;
  z-index: 1;
  display: block;
  width: 43px;
  height: 34px;
  color: var(--green);
}

.unknown .family-mark {
  color: var(--orange);
}

.family-mark span {
  position: absolute;
  border-radius: 999px;
  background: currentColor;
}

.family-mark span:nth-child(1) {
  left: 15px;
  top: 0;
  width: 13px;
  height: 13px;
}

.family-mark span:nth-child(2) {
  left: 2px;
  bottom: 0;
  width: 18px;
  height: 18px;
}

.family-mark span:nth-child(3) {
  right: 2px;
  bottom: 0;
  width: 18px;
  height: 18px;
}

.result-illustration i {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 10px;
  width: 14px;
  height: 14px;
  transform: rotate(45deg);
  border-radius: 4px 4px 2px 4px;
  background: #f25486;
}

.result-illustration i::before,
.result-illustration i::after {
  position: absolute;
  width: 14px;
  height: 14px;
  content: "";
  border-radius: 50%;
  background: inherit;
}

.result-illustration i::before {
  left: -7px;
}

.result-illustration i::after {
  top: -7px;
}

.relation-section,
.examples-section {
  display: grid;
  gap: 12px;
}

.relation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.relation-card {
  display: flex;
  align-items: center;
  min-height: 70px;
  gap: 12px;
  padding: 14px;
  border-radius: 20px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow-soft);
  text-align: left;
  transition: transform 120ms ease, opacity 120ms ease;
}

.relation-card:active,
.icon-action:active,
.calculate-button:active,
.history-button:active,
.example-row:active {
  transform: scale(0.96);
  opacity: 0.86;
}

.relation-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 14px;
  color: var(--blue);
  background: rgba(36, 121, 232, 0.13);
}

.relation-card.female .relation-icon {
  color: var(--pink);
  background: rgba(194, 75, 179, 0.13);
}

.relation-card span:last-child {
  font-size: 17px;
  font-weight: 800;
}

.action-row {
  display: grid;
  grid-template-columns: 54px 54px 1fr;
  gap: 12px;
  align-items: center;
}

.icon-action {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 18px;
  color: var(--blue);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  transition: transform 120ms ease, opacity 120ms ease;
}

.calculate-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  gap: 10px;
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(135deg, #2588ef, #26aede);
  box-shadow: 0 16px 28px rgba(33, 126, 224, 0.24);
  font-size: 17px;
  font-weight: 850;
  transition: transform 120ms ease, opacity 120ms ease;
}

.examples-card {
  overflow: hidden;
  border-radius: 22px;
}

.example-row {
  display: grid;
  grid-template-columns: 32px 1fr auto 12px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 14px 16px;
  color: var(--text);
  background: transparent;
  text-align: left;
  transition: transform 120ms ease, opacity 120ms ease;
}

.example-row + .example-row {
  border-top: 1px solid rgba(120, 134, 156, 0.16);
}

.example-index {
  color: var(--muted-2);
  font-size: 14px;
  font-weight: 850;
}

.example-expression {
  min-width: 0;
  font-size: 15px;
  font-weight: 750;
}

.example-result {
  color: var(--green);
  font-size: 15px;
  font-weight: 850;
  white-space: nowrap;
}

.example-chevron {
  color: var(--muted-2);
}

.history-screen {
  background: linear-gradient(180deg, var(--bg-start), var(--bg-end));
}

.history-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 48px 1fr 56px;
  align-items: center;
  min-height: 54px;
  padding-top: 42px;
  margin-bottom: 18px;
}

.history-header h1 {
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
}

.back-button {
  width: 38px;
  height: 38px;
}

.clear-history {
  justify-self: end;
  color: #d43d3d;
  background: transparent;
  font-size: 15px;
  font-weight: 700;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-row {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 22px;
}

.history-row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.history-result {
  color: var(--green);
  font-size: 22px;
  font-weight: 850;
}

.history-result.unknown {
  color: var(--orange);
}

.history-time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.history-path {
  margin: 0;
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  font-weight: 750;
}

.history-desc {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  font-weight: 500;
}

.empty-history {
  display: grid;
  place-items: center;
  min-height: 55svh;
  color: var(--muted);
  text-align: center;
}

.empty-history strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 20px;
}

.icon {
  position: relative;
  display: inline-block;
  width: 20px;
  height: 20px;
}

.clock-icon {
  border: 2px solid currentColor;
  border-radius: 50%;
}

.clock-icon::before,
.clock-icon::after {
  position: absolute;
  left: 8px;
  top: 4px;
  width: 2px;
  height: 6px;
  content: "";
  border-radius: 2px;
  background: currentColor;
  transform-origin: bottom;
}

.clock-icon::after {
  top: 8px;
  height: 5px;
  transform: rotate(52deg);
}

.delete-icon::before {
  position: absolute;
  inset: 4px 3px 4px 1px;
  content: "";
  border: 2px solid currentColor;
  border-radius: 5px;
  transform: skewX(-8deg);
}

.delete-icon::after {
  position: absolute;
  left: 7px;
  top: 9px;
  width: 9px;
  height: 2px;
  content: "";
  border-radius: 2px;
  background: currentColor;
  box-shadow: 0 0 0 0 currentColor;
  transform: rotate(45deg);
}

.trash-icon::before {
  position: absolute;
  left: 5px;
  top: 7px;
  width: 10px;
  height: 10px;
  content: "";
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 4px 4px;
}

.trash-icon::after {
  position: absolute;
  left: 4px;
  top: 4px;
  width: 12px;
  height: 2px;
  content: "";
  border-radius: 2px;
  background: currentColor;
  box-shadow: 3px -3px 0 -1px currentColor;
}

.back-icon::before {
  position: absolute;
  left: 7px;
  top: 4px;
  width: 10px;
  height: 10px;
  content: "";
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.person-svg {
  width: 22px;
  height: 22px;
}

[hidden] {
  display: none !important;
}

@keyframes cardIn {
  from {
    transform: scale(0.96);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-start: #111827;
    --bg-mid: #142033;
    --bg-end: #10251f;
    --surface: rgba(31, 41, 55, 0.74);
    --surface-strong: rgba(31, 41, 55, 0.92);
    --text: #f7fafc;
    --muted: #a8b3c5;
    --muted-2: #7f8ca1;
    --shadow: 0 14px 34px rgba(0, 0, 0, 0.26);
    --shadow-soft: 0 10px 24px rgba(0, 0, 0, 0.22);
  }

  .path-token {
    background: rgba(71, 85, 105, 0.76);
  }

  .soft-card,
  .relation-card,
  .examples-card,
  .history-row {
    border-color: rgba(255, 255, 255, 0.08);
  }
}

@media (max-width: 360px) {
  .screen {
    padding-left: 16px;
    padding-right: 16px;
  }

  .relation-grid {
    gap: 10px;
  }

  .relation-card {
    padding: 12px;
  }

  .result-illustration {
    width: 76px;
  }
}
