:root {
  --bg: #080611;
  --surface: rgba(255,255,255,0.04);
  --surface-hover: rgba(255,255,255,0.07);
  --border: rgba(220,185,130,0.18);
  --border-bright: rgba(220,185,130,0.4);
  --gold: #c9964a;
  --gold-light: #f0b86e;
  --rose: #e8829a;
  --rose-light: #f5a8bc;
  --lavender: #a090c0;
  --text: #f0e8d8;
  --text-dim: rgba(240,232,216,0.45);
  --text-muted: rgba(240,232,216,0.25);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Noto Serif KR', 'Noto Serif', 'Georgia', serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Background layers ── */
.bg-mesh {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 70% 55% at 15% 15%, rgba(100,50,170,0.22) 0%, transparent 65%),
    radial-gradient(ellipse 55% 65% at 85% 85%, rgba(200,70,110,0.16) 0%, transparent 65%),
    radial-gradient(ellipse 45% 45% at 60% 25%, rgba(180,120,50,0.10) 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 30% 75%, rgba(60,80,180,0.10) 0%, transparent 60%);
}

.stars-layer { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.star-dot {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,238,210,0.8);
  animation: starTwinkle var(--dur, 3s) ease-in-out infinite alternate;
  animation-delay: var(--delay, 0s);
}
@keyframes starTwinkle {
  from { opacity: var(--op-min, 0.05); transform: scale(0.8); }
  to   { opacity: var(--op-max, 0.6);  transform: scale(1.2); }
}

/* ── Layout ── */
.container {
  position: relative; z-index: 1;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 1.5rem 5rem;
}

/* ── Header ── */
header {
  text-align: center;
  padding: 3.5rem 0 2rem;
  position: relative;
}

.btn-back {
  position: absolute;
  top: 3.5rem;
  left: 0;
  font-family: 'Noto Serif KR', serif;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-decoration: none;
  letter-spacing: 0.05em;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 50px;
  background: var(--surface);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.btn-back:hover {
  color: var(--gold-light);
  border-color: rgba(201,150,74,0.4);
  background: var(--surface-hover);
}

.header-eyebrow {
  font-family: 'Georgia', serif;
  font-style: italic;
  font-size: 0.82rem;
  letter-spacing: 0.35em;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: 1rem;
  opacity: 0.85;
}

h1 {
  font-family: 'Noto Serif KR', 'Noto Serif', 'Georgia', serif;
  font-size: clamp(2.4rem, 6vw, 3.8rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.15;
  background: linear-gradient(140deg, #f0e8d8 0%, #d4a85e 45%, #e8829a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-rule {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  margin-top: 1.2rem;
  color: var(--text-muted);
  font-size: 0.7rem;
  letter-spacing: 0.4em;
}

.header-rule::before, .header-rule::after {
  content: '';
  display: block;
  height: 1px;
  width: 56px;
  background: linear-gradient(90deg, transparent, var(--gold-light));
}
.header-rule::after { background: linear-gradient(90deg, var(--gold-light), transparent); }

.header-desc {
  font-size: 0.88rem;
  font-weight: 300;
  color: var(--text-dim);
  letter-spacing: 0.03em;
  line-height: 1.8;
  margin-top: 0.9rem;
  text-align: center;
}

/* ── Input row ── */
.input-row {
  display: grid;
  grid-template-columns: 1fr 56px 1fr;
  align-items: center;
  gap: 1rem;
  margin: 2.5rem 0 1.75rem;
}

.name-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  position: relative;
}

.name-group label {
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  color: var(--text-dim);
  text-align: center;
  text-transform: uppercase;
}

.name-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.25rem;
  font-family: 'Noto Serif KR', 'Noto Serif', 'Georgia', serif;
  font-size: 1.55rem;
  font-weight: 400;
  color: var(--text);
  text-align: center;
  outline: none;
  transition: border-color 0.3s, box-shadow 0.3s, background 0.3s;
  caret-color: var(--gold-light);
}

.name-input:focus {
  background: var(--surface-hover);
  border-color: rgba(201,150,74,0.55);
  box-shadow: 0 0 0 3px rgba(201,150,74,0.08), 0 4px 24px rgba(0,0,0,0.3);
}

.name-input::placeholder { color: var(--text-muted); }

.name-input.shake {
  animation: inputShake 0.35s ease;
  border-color: rgba(232,130,154,0.6);
}

@keyframes inputShake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-5px); }
  40%       { transform: translateX(5px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}

.korean-hint {
  position: absolute;
  bottom: -1.6rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  color: var(--rose-light);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.korean-hint.show { opacity: 1; }

.heart-center {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  animation: pulse 2.4s ease-in-out infinite;
  filter: drop-shadow(0 0 10px rgba(232,130,154,0.55));
  line-height: 1;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  20% { transform: scale(1.22); }
  40% { transform: scale(1.0); }
  55% { transform: scale(1.12); }
  70% { transform: scale(1.0); }
}

/* ── Button ── */
.calc-btn {
  display: block;
  margin: 0 auto 3rem;
  padding: 0.85rem 3.2rem;
  background: linear-gradient(135deg, #b8823e 0%, #c9964a 40%, #e8829a 100%);
  border: none;
  border-radius: 50px;
  font-family: 'Noto Serif KR', 'Noto Serif', 'Georgia', serif;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: #fff;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 22px rgba(180,120,60,0.32), 0 1px 0 rgba(255,255,255,0.08) inset;
}
.calc-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(180,120,60,0.45); }
.calc-btn:active { transform: translateY(0px); }

/* ── Results wrapper ── */
#results {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.65s ease, transform 0.65s ease;
  pointer-events: none;
}
#results.show { opacity: 1; transform: none; pointer-events: auto; }

/* ── Section card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.75rem 1.5rem;
  margin-bottom: 1.25rem;
}

.card-label {
  font-size: 0.65rem;
  letter-spacing: 0.3em;
  color: var(--text-muted);
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 1.4rem;
}

/* ── Stroke breakdown ── */
.breakdown-wrap {
  display: flex;
  justify-content: center;
  gap: 3rem;
  flex-wrap: wrap;
}

.name-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.name-block-title {
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.1em;
}

.chars-row {
  display: flex;
  gap: 0.5rem;
}

.char-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  min-width: 54px;
  opacity: 0;
  animation: fadeUp 0.4s ease forwards;
}

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

.char-glyph {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text);
}

.char-stroke {
  font-family: 'Courier New', monospace;
  font-size: 0.72rem;
  color: var(--gold-light);
  letter-spacing: 0;
}

/* ── Triangle ── */
.triangle-wrap {
  overflow-x: auto;
  padding: 0.5rem;
  text-align: center;
}

.tri-rows {
  display: inline-flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
}

.tri-char-row {
  display: flex;
  gap: 3px;
  padding: 0 6px;
  margin-bottom: 2px;
}

.tri-char-label {
  font-family: 'Noto Serif KR', 'Noto Serif', 'Georgia', serif;
  font-size: 0.78rem;
  color: var(--text-dim);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
}

.tri-row {
  display: flex;
  gap: 3px;
  border-radius: 7px;
  padding: 2px 6px;
  opacity: 0;
  animation: rowIn 0.25s ease forwards;
}

@keyframes rowIn {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: none; }
}

.tri-cell {
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  color: rgba(200,180,160,0.65);
  transition: color 0.3s;
}

.tri-cell.accent { color: rgba(220,190,140,0.9); }

.tri-row.final-row { background: rgba(201,150,74,0.12); border: 1px solid rgba(201,150,74,0.3); }
.tri-row.final-row .tri-cell {
  font-size: 1.05rem;
  font-weight: 500;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(201,150,74,0.25), rgba(232,130,154,0.2));
  border: 1px solid rgba(201,150,74,0.5);
  color: var(--gold-light);
  box-shadow: 0 0 14px rgba(201,150,74,0.2);
}

.ellipsis-row {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.35em;
  padding: 0.1rem 0;
}

/* ── Result ── */
.result-wrap {
  text-align: center;
  padding: 1rem 0 0.5rem;
}

.result-hearts {
  font-size: 1.6rem;
  letter-spacing: 0.3em;
  margin-bottom: 0.6rem;
  animation: fadeUp 0.5s ease forwards;
  opacity: 0;
}

.result-pct {
  font-family: 'Georgia', serif;
  font-size: clamp(4.5rem, 14vw, 8rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  animation: fadeUp 0.6s 0.1s ease forwards;
  opacity: 0;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.result-pct.tier-low  { background: linear-gradient(135deg, #ff7b7b, #ff5252); -webkit-background-clip: text; background-clip: text; }
.result-pct.tier-mid  { background: linear-gradient(135deg, #ffd166, #ff9f43); -webkit-background-clip: text; background-clip: text; }
.result-pct.tier-good { background: linear-gradient(135deg, #6bcb77, #44d9b0); -webkit-background-clip: text; background-clip: text; }
.result-pct.tier-fate {
  background: linear-gradient(135deg, #ffd700 0%, #ff8cc8 50%, #ffd700 100%);
  background-size: 200%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: shimmer 2.5s linear infinite, fadeUp 0.6s 0.1s ease forwards;
}

@keyframes shimmer { to { background-position: 200% center; } }

.result-msg {
  font-size: 1.1rem;
  font-weight: 300;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  margin-top: 0.6rem;
  animation: fadeUp 0.6s 0.2s ease forwards;
  opacity: 0;
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: 0.25rem 0 1rem;
}

/* ── Dual grid ── */
.dual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

.direction-label {
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  margin-bottom: 0.75rem;
  min-height: 2.4em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.direction-label strong {
  color: var(--gold-light);
  font-weight: 600;
}

.dual-grid .result-pct   { font-size: clamp(3rem, 8vw, 5rem); }
.dual-grid .result-hearts { font-size: 1.2rem; }
.dual-grid .result-msg    { font-size: 0.9rem; }

/* ── Example chips ── */
.examples {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  margin: -1rem 0 2rem;
  flex-wrap: wrap;
}

.example-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 0.35rem 1rem;
  font-family: 'Noto Serif KR', serif;
  font-size: 0.78rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  letter-spacing: 0.05em;
}
.example-chip:hover {
  border-color: var(--border-bright);
  color: var(--text);
  background: var(--surface-hover);
}
.example-chip.active {
  border-color: rgba(201,150,74,0.5);
  color: var(--gold-light);
  background: rgba(201,150,74,0.08);
}

/* ── Footer ── */
footer {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-top: 3rem;
  padding-bottom: 2rem;
}
footer a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}
footer a:hover { color: var(--gold-light); }

/* ── Responsive ── */
@media (max-width: 620px) {
  .dual-grid { grid-template-columns: 1fr; }
}

@media (max-width: 500px) {
  .btn-back { font-size: 0.72rem; padding: 0.3rem 0.65rem; }
  .input-row { grid-template-columns: 1fr; grid-template-rows: auto 40px auto; gap: 0.75rem; }
  .heart-center { font-size: 1.4rem; }
  .breakdown-wrap { gap: 1.5rem; }
  .tri-cell { width: 20px; height: 20px; font-size: 0.7rem; }
  .tri-row.final-row .tri-cell { width: 28px; height: 28px; font-size: 0.88rem; }
}
