:root {
  --bg-app: oklch(0.19 0.03 262);
  --bg-page: oklch(0.14 0.02 260);

  --text-primary: oklch(0.95 0.01 260);
  --text-primary-soft: oklch(0.93 0.01 260);
  --text-secondary: oklch(0.6 0.02 260);
  --text-secondary-2: oklch(0.65 0.02 260);
  --text-tertiary: oklch(0.72 0.02 260);
  --text-on-accent: oklch(0.18 0.02 260);

  --surface-1: oklch(0.23 0.025 260);
  --surface-2: oklch(0.25 0.03 260);
  --surface-3: oklch(0.27 0.03 260);
  --border-default: oklch(0.35 0.03 260);

  --accent-green: oklch(0.83 0.12 155);
  --accent-green-strong: oklch(0.7 0.12 155);
  --accent-blue: oklch(0.78 0.1 240);
  --accent-purple: oklch(0.78 0.1 300);

  --search-bg: oklch(0.23 0.03 150);
  --search-border: oklch(0.35 0.04 150);
  --search-icon: oklch(0.66 0.03 150);

  --pill-bg: oklch(0.23 0.03 150);
  --pill-text: oklch(0.9 0.02 150);

  --danger-1: oklch(0.74 0.11 45);
  --danger-2: oklch(0.62 0.11 40);
  --moon: oklch(0.85 0.09 95);

  --ja-bg: oklch(0.25 0.04 250);
  --ja-accent: oklch(0.78 0.1 240);
  --ja-label: oklch(0.68 0.04 240);

  --zhtw-bg: oklch(0.25 0.04 165);
  --zhtw-accent: oklch(0.83 0.12 155);
  --zhtw-label: oklch(0.72 0.06 155);

  --yue-bg: oklch(0.26 0.035 80);
  --yue-accent: oklch(0.75 0.1 70);
  --yue-label: oklch(0.74 0.07 70);

  --font-body: "Pretendard", -apple-system, "Malgun Gothic", system-ui, sans-serif;
  --font-logo: "Poor Story", cursive;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg-page);
  font-family: var(--font-body);
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.app {
  width: 100%;
  max-width: 430px;
  min-height: 100dvh;
  background: var(--bg-app);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 480px) {
  .app-shell { align-items: center; padding: 40px 16px; }
  .app {
    min-height: min(874px, 92dvh);
    height: min(874px, 92dvh);
    border-radius: 40px;
    box-shadow: rgba(0, 0, 0, 0.45) 0px 30px 70px, rgba(0, 0, 0, 0.25) 0px 0px 0px 1px;
  }
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 28px 24px 30px;
  overflow-y: auto;
}

/* ---------- Home ---------- */

.home-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 30px;
  padding: 12px 2px 0;
}

.logo-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--accent-green), var(--accent-green-strong));
  box-shadow: rgba(0, 0, 0, 0.32) 0px 4px 10px, rgba(255, 255, 255, 0.4) 0px 1px 1px inset;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.logo-title {
  font-family: var(--font-logo);
  font-size: 36px;
  color: var(--text-primary);
  margin: 0;
  line-height: 1;
}

.home-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--search-bg);
  border: 1px solid var(--search-border);
  border-radius: 22px;
  height: 60px;
  padding: 0 10px 0 18px;
  margin-bottom: 30px;
}

.search-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.search-icon-btn svg { display: block; }

.search-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 16px;
  font-family: var(--font-body);
}

.search-input::placeholder {
  color: var(--search-icon);
}

.search-go {
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-green));
  color: var(--text-on-accent);
  font-weight: 700;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
}

.chip-label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.chip-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin: 0 -2px;
  padding-left: 2px;
  padding-right: 2px;
}

.chip {
  background: var(--surface-3);
  border: 1.5px solid oklch(0.83 0.12 155 / 0.4);
  color: oklch(0.9 0.01 260);
  font-size: 15px;
  padding: 12px 20px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  font-family: var(--font-body);
}

.chip:hover { border-color: var(--accent-green); }

/* ---------- Shared: back row / pill ---------- */

.back-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.back-btn {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.back-chevron {
  width: 11px;
  height: 11px;
  border-left: 2.4px solid var(--text-primary-soft);
  border-bottom: 2.4px solid var(--text-primary-soft);
  transform: rotate(45deg);
}

.query-pill {
  flex: 1;
  min-width: 0;
  background: var(--pill-bg);
  border-radius: 14px;
  padding: 12px 16px;
  color: var(--pill-text);
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Selection screen ---------- */

.select-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary-soft);
  margin-bottom: 18px;
}

.select-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.select-card {
  background: var(--surface-2);
  border-left: 5px solid var(--accent-purple);
  border-radius: 20px;
  padding: 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: rgba(0, 0, 0, 0.25) 0px 8px 18px;
  cursor: pointer;
  border-top: none;
  border-right: none;
  border-bottom: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  color: inherit;
}

.select-card:nth-child(3n+1) { transform: rotate(-1deg); }
.select-card:nth-child(3n+2) { transform: rotate(1deg); }
.select-card:nth-child(3n+3) { transform: rotate(-0.8deg); }

.select-card-body { flex: 1; min-width: 0; }

.select-card-title {
  font-size: 18px;
  color: var(--text-primary);
  font-weight: 700;
  margin-bottom: 5px;
}

.select-card-desc {
  font-size: 13px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

.select-card-arrow {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-purple);
  color: var(--text-on-accent);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---------- Result screen ---------- */

.result-intro {
  background: var(--surface-1);
  border-radius: 18px;
  padding: 16px 18px;
  color: var(--text-tertiary);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 22px;
}

.result-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lang-card {
  border-radius: 20px;
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: rgba(0, 0, 0, 0.25) 0px 8px 18px;
  text-decoration: none;
  border-left: 5px solid transparent;
}

.lang-card:nth-child(3n+1) { transform: rotate(-1.2deg); }
.lang-card:nth-child(3n+2) { transform: rotate(1deg); }
.lang-card:nth-child(3n+3) { transform: rotate(-0.8deg); }

.lang-card.lang-ja { background: var(--ja-bg); border-left-color: var(--ja-accent); }
.lang-card.lang-zhtw { background: var(--zhtw-bg); border-left-color: var(--zhtw-accent); }
.lang-card.lang-yue { background: var(--yue-bg); border-left-color: var(--yue-accent); }

.lang-avatar {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: oklch(0.93 0.02 90);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}

.lang-body { flex: 1; min-width: 0; }

.lang-name {
  font-size: 12px;
  margin-bottom: 3px;
}

.lang-ja .lang-name { color: var(--ja-label); }
.lang-zhtw .lang-name { color: var(--zhtw-label); }
.lang-yue .lang-name { color: var(--yue-label); }

.lang-title {
  font-size: 18px;
  color: var(--text-primary);
  font-weight: 700;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lang-desc {
  font-size: 13px;
  color: var(--text-tertiary);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lang-arrow {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-on-accent);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lang-ja .lang-arrow { background: var(--ja-accent); }
.lang-zhtw .lang-arrow { background: var(--zhtw-accent); }
.lang-yue .lang-arrow { background: var(--yue-accent); }

.lang-card-missing {
  opacity: 0.55;
  cursor: default;
}

.lang-title-missing {
  font-weight: 500;
  font-style: italic;
  color: var(--text-secondary-2);
}

.lang-arrow-missing {
  background: transparent !important;
  color: var(--text-secondary-2);
  box-shadow: inset 0 0 0 1.5px var(--border-default);
}

/* ---------- Empty / Error / Loading (centered states) ---------- */

.state-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding-bottom: 40px;
}

.moon-icon {
  position: relative;
  width: 88px;
  height: 88px;
  transform: rotate(-6deg);
  flex-shrink: 0;
}

.moon-icon::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--moon);
}

.moon-icon::after {
  content: "";
  position: absolute;
  top: -10px;
  left: 26px;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--bg-app);
}

.state-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary-soft);
}

.state-desc {
  font-size: 14px;
  color: var(--text-secondary-2);
  line-height: 1.5;
}

.error-icon {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--danger-1), var(--danger-2));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: rgba(0, 0, 0, 0.3) 0px 6px 14px, rgba(255, 255, 255, 0.35) 0px 1px 1px inset;
  transform: rotate(-4deg);
  flex-shrink: 0;
}

.error-icon span {
  font-size: 34px;
  font-weight: 700;
  color: var(--text-on-accent);
}

.retry-btn {
  background: var(--accent-green);
  color: var(--text-on-accent);
  font-weight: 700;
  font-size: 15px;
  padding: 14px 32px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  margin-top: 6px;
  font-family: var(--font-body);
}

.spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid var(--surface-2);
  border-top-color: var(--accent-green);
  animation: spin 0.8s linear infinite;
}

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