:root {
  color-scheme: light;
  --bg: #45d9f3;
  --surface: #efffff;
  --surface-2: #ffd7f0;
  --text: #26323f;
  --muted: #60707d;
  --line: #26323f;
  --accent: #ff7abc;
  --accent-2: #26d5e5;
  --yellow: #fff477;
  --shadow: 7px 7px 0 rgba(38, 50, 63, 0.18);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans SC", "PingFang SC", sans-serif;
}

:root.light {
  color-scheme: light;
  --bg: #45d9f3;
  --surface: #efffff;
  --surface-2: #ffd7f0;
  --text: #26323f;
  --muted: #60707d;
  --line: #26323f;
  --accent: #ff7abc;
  --accent-2: #26d5e5;
  --yellow: #fff477;
  --shadow: 7px 7px 0 rgba(38, 50, 63, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 7% 20%, rgba(255, 244, 119, 0.9) 0 10px, transparent 11px),
    radial-gradient(circle at 92% 14%, rgba(255, 122, 188, 0.85) 0 12px, transparent 13px),
    radial-gradient(circle at 16% 84%, rgba(239, 255, 255, 0.9) 0 13px, transparent 14px),
    linear-gradient(rgba(255, 255, 255, 0.38) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.38) 2px, transparent 2px),
    var(--bg);
  background-size: auto, auto, auto, 44px 44px, 44px 44px, auto;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(135deg, transparent 0 48%, rgba(255, 255, 255, 0.44) 49% 51%, transparent 52%) 0 0 / 96px 96px,
    radial-gradient(circle at 78% 72%, rgba(255, 122, 188, 0.36), transparent 18%);
  mix-blend-mode: screen;
}

button,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus {
  outline: none;
}

button:focus-visible {
  outline: 2px dotted var(--line);
  outline-offset: 3px;
}

.language-card:focus-visible {
  outline: none;
  box-shadow: var(--shadow), 0 0 0 3px var(--yellow);
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100svh;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(82px + env(safe-area-inset-bottom));
}

.topbar,
.section-heading {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 12px 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar::before,
.section-heading::before {
  position: absolute;
  inset: 0 0 auto;
  height: 22px;
  border-bottom: 2px solid var(--line);
  border-radius: 6px 6px 0 0;
  background: linear-gradient(90deg, #ff9bcf, #ffd7f0);
  content: "";
}

.topbar > *,
.section-heading > * {
  position: relative;
  z-index: 1;
  padding-top: 16px;
}

.topbar h1,
.section-heading h2 {
  margin: 2px 0 0;
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: #3c4a56;
  font-size: 12px;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.brand-logo {
  position: relative;
  flex: 0 0 auto;
  width: 52px;
  height: 46px;
  padding-top: 14px;
}

.logo-bubble {
  position: absolute;
  right: 0;
  bottom: 0;
  display: grid;
  width: 44px;
  height: 38px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 14px 14px 14px 6px;
  background:
    radial-gradient(circle at 72% 28%, #fff 0 4px, transparent 5px),
    linear-gradient(135deg, var(--yellow) 0 46%, #ff9bcf 47% 57%, var(--accent-2) 58%);
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: 3px 3px 0 rgba(38, 50, 63, 0.2);
}

.logo-bubble::after {
  position: absolute;
  right: 6px;
  bottom: -7px;
  width: 11px;
  height: 11px;
  border-right: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  background: var(--accent-2);
  transform: rotate(45deg);
  content: "";
}

.logo-spark {
  position: absolute;
  top: 11px;
  left: 0;
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #ff9bcf;
  color: var(--yellow);
  font-size: 12px;
  line-height: 1;
  box-shadow: 2px 2px 0 rgba(38, 50, 63, 0.18);
}

.view {
  display: none;
  padding-top: 14px;
}

.view.active {
  display: block;
}

.language-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 14px;
}

.language-tabs button,
.bottom-tabs button,
.actions button,
.ai-panel button,
.ai-result button {
  border: 2px solid var(--line);
  border-radius: 7px;
  background: #f2ffff;
  color: var(--text);
  box-shadow: 3px 3px 0 rgba(38, 50, 63, 0.16);
}

.language-tabs button {
  min-height: 38px;
  padding: 7px 5px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.language-tabs button.active,
.bottom-tabs button.active {
  border-color: var(--line);
  color: var(--text);
  background: linear-gradient(180deg, #ff9bcf, #ffd7f0);
}

.card-stage {
  display: grid;
  gap: 10px;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  color: #304656;
  font-size: 13px;
}

.language-card {
  display: grid;
  min-height: min(42svh, 330px);
  width: 100%;
  place-items: center;
  align-content: center;
  gap: 18px;
  padding: 22px 18px;
  border: 3px solid var(--line);
  border-radius: 9px;
  background:
    linear-gradient(90deg, #ff9bcf 0 100%) top / 100% 26px no-repeat,
    linear-gradient(45deg, rgba(255, 255, 255, 0.58) 25%, transparent 25%) 0 26px / 26px 26px,
    linear-gradient(-45deg, rgba(255, 255, 255, 0.58) 25%, transparent 25%) 0 26px / 26px 26px,
    var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  text-align: center;
}

.language-card strong {
  max-width: 12ch;
  font-size: clamp(34px, 12vw, 52px);
  line-height: 1.08;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  text-shadow: 3px 3px 0 #ffd7f0;
}

.card-stage:has(.card-detail.open) .language-card {
  min-height: min(34svh, 260px);
}

.source-chip {
  align-self: start;
  justify-self: center;
  max-width: 100%;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--yellow);
  color: var(--text);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.card-detail {
  display: none;
  max-height: 32svh;
  overflow-y: auto;
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-detail.open {
  display: grid;
  gap: 12px;
}

.detail-row {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: start;
}

.detail-row span {
  color: #4a5c68;
  font-size: 13px;
}

.detail-row p {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill-list span,
.saved-card span,
.ai-expression span {
  border: 2px dotted var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: #ffd7f0;
  color: var(--text);
  font-size: 12px;
}

.source-line {
  color: #667481;
  font-size: 12px;
  line-height: 1.5;
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.actions button {
  min-height: 44px;
  padding: 9px 4px;
  font-size: 14px;
}

.actions button.saved {
  background: var(--yellow);
  color: var(--text);
}

.bottom-tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  max-width: 480px;
  margin: 0 auto;
  padding: 9px 14px calc(10px + env(safe-area-inset-bottom));
  background: rgba(69, 217, 243, 0.78);
  backdrop-filter: blur(8px);
  border-top: 2px solid var(--line);
}

.bottom-tabs button {
  min-height: 46px;
  font-size: 15px;
}

.saved-list,
.ai-results {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.saved-card,
.ai-expression {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.saved-card strong,
.ai-expression strong {
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.saved-card p,
.ai-expression p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.empty-state {
  padding: 28px 16px;
  border: 2px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  box-shadow: var(--shadow);
}

.ai-panel {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.ai-panel label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.ai-panel textarea,
.ai-panel select {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 7px;
  background: #f2ffff;
  color: var(--text);
  padding: 12px;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: end;
}

.form-grid button,
.ai-result button {
  min-height: 44px;
  padding: 0 14px;
}

@media (min-width: 680px) {
  .app-shell {
    padding-top: 24px;
  }

  .language-card {
    min-height: 360px;
  }

  .language-card strong {
    max-width: 13ch;
    font-size: 58px;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .language-tabs {
    overflow-x: auto;
    grid-template-columns: repeat(4, max-content);
    scrollbar-width: none;
  }

  .language-tabs::-webkit-scrollbar {
    display: none;
  }

  .language-tabs button {
    min-width: 78px;
    padding-right: 12px;
    padding-left: 12px;
  }

  .language-card strong {
    font-size: clamp(32px, 11vw, 44px);
  }

  .card-detail {
    max-height: 27svh;
  }

  .card-stage:has(.card-detail.open) .language-card {
    min-height: min(30svh, 230px);
  }
}

@media (max-width: 360px) {
  .topbar h1,
  .section-heading h2 {
    font-size: 18px;
  }

  .actions button,
  .bottom-tabs button {
    font-size: 13px;
  }

  .detail-row {
    grid-template-columns: 38px 1fr;
  }
}
