/* ============================================
   RESET & VARIABLES
   ============================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  /* 광고 및 상단 안전영역을 위한 여유 공간 (약 70px) */
  --top-ad-space: calc(env(safe-area-inset-top));
  
  --blue: #0284C7;
  --blue-dark: #0369A1;
  --blue-lt: #38BDF8;
  --blue-bg: #E0F2FE;
  --blue-bd: #BAE6FD;

  --amber: #F59E0B;
  --amber-bg: #FFFBEB;

  --green: #10B981;
  --green-bg: #ECFDF5;
  --green-bd: #6EE7B7;

  --red: #EF4444;
  --red-bg: #FEF2F2;
  --red-bd: #FCA5A5;

  --purple: #7C3AED;
  --purple-bg: #F5F3FF;
  --purple-bg-dk: #EDE9FE;
  --purple-bd: #DDD6FE;
  --purple-bd-dk: #C4B5FD;
  --purple-dk: #5B21B6;

  --bg: #F8F9FC;
  --bg-outer: #111827;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --border-dk: #CBD5E1;
  --text: #1E293B;
  --text-2: #64748B;
  --text-3: #94A3B8;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Nunito', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  background: var(--bg-outer);
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Safe-area padding for notch/home-bar on webapp home screen mode */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button {
  /* Remove 300ms tap delay on iOS/Android */
  touch-action: manipulation;
}

#rotate-notice {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-outer);
  color: #fff;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 9999;
  text-align: center;
  font-family: 'Nunito', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

.rotate-icon {
  font-size: 3rem;
  animation: rotate-hint 2s ease-in-out infinite;
}

@keyframes rotate-hint {

  0%,
  100% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(90deg);
  }
}

#rotate-notice p {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.6;
  opacity: 0.85;
}

#app {
  position: relative;
  /* dvh = dynamic viewport height (excludes iOS Safari browser chrome) */
  /* vh fallback for browsers that don't support dvh */
  width: min(100vw, calc(100vh * 9 / 16));
  width: min(100vw, calc(100dvh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  height: min(100dvh, calc(100vw * 16 / 9));
  overflow: hidden;
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.5);
  background: var(--bg);
  /* Container context: cqw = 1% of #app width, used for fluid type inside */
  container-type: size;
  container-name: app;
}

/* Show rotate notice when device is in landscape and too short for the game */
@media (orientation: landscape) and (max-height: 500px) {
  #app {
    visibility: hidden;
  }

  #rotate-notice {
    display: flex;
  }
}

/* ============================================
   SCREEN SYSTEM
   ============================================ */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}

.screen.active {
  display: flex;
}

#screen-title.active {
  display: block; /* 스크롤을 위해 flex 대신 block 사용 */
  overflow-y: auto;
  overflow-x: hidden;
  /* IE and Edge */
  -ms-overflow-style: none;
  /* Firefox */
  scrollbar-width: none;
}

/* Chrome, Safari and Opera */
#screen-title.active::-webkit-scrollbar {
  display: none;
}

.title-initial-view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-top: var(--top-ad-space);
}

.app-version {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 0.75rem;
  color: var(--text-3);
  pointer-events: none;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
}

.seo-article {
  padding: 30px 20px 60px;
  background: var(--bg);
  color: var(--text-2);
  font-size: 0.95rem;
  line-height: 1.6;
}

.seo-article h2 {
  font-size: 1.25rem;
  color: var(--text);
  margin-bottom: 12px;
}

.seo-article h3 {
  font-size: 1.05rem;
  color: var(--text);
  margin-top: 24px;
  margin-bottom: 8px;
}

.seo-article p {
  margin-bottom: 12px;
}

.seo-article ul {
  padding-left: 20px;
  margin-bottom: 12px;
}

.seo-article li {
  margin-bottom: 8px;
}

.screen.overlay {
  background: rgba(15, 23, 42, 0.65);
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

/* ============================================
   FOCUS STYLES
   ============================================ */
:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

/* ============================================
   SHARED COMPONENTS
   ============================================ */
.center-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 20px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  margin-top: var(--top-ad-space);
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}

.top-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn-primary {
  background: var(--blue);
  color: #fff;
  border: 2px solid transparent;
  border-radius: var(--r-md);
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 32px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
  width: 100%;
  max-width: 280px;
  box-shadow: 0 4px 0 var(--blue-dark);
  transition: transform 0.1s, box-shadow 0.1s, filter 0.15s;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--blue-dark);
  filter: none;
}

.btn-outline {
  background: var(--surface);
  color: var(--text-2);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 32px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
  width: 100%;
  max-width: 280px;
  transition: transform 0.1s, background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-outline:hover {
  background: var(--bg);
  border-color: var(--border-dk);
  color: var(--text);
}

.btn-outline:active {
  transform: translateY(2px);
}

.btn-danger {
  background: var(--red);
  color: #fff;
  border: 2px solid transparent;
  border-radius: var(--r-md);
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 32px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
  width: 100%;
  max-width: 280px;
  box-shadow: 0 4px 0 #B91C1C;
  transition: transform 0.1s, box-shadow 0.1s, filter 0.15s;
}

.btn-danger:hover {
  filter: brightness(1.08);
}

.btn-danger:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #B91C1C;
  filter: none;
}

.btn-icon {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--r-sm);
  width: 44px;
  height: 44px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: inherit;
  color: var(--text);
  font-weight: 700;
  transition: background 0.15s, border-color 0.15s;
}

.btn-icon:hover {
  background: var(--blue-bg);
  border-color: var(--blue-bd);
}

.btn-icon:active {
  background: var(--blue-bg);
}

/* ============================================
   TITLE SCREEN
   ============================================ */
#screen-title {
  background: linear-gradient(180deg, var(--blue-bg) 0%, var(--bg) 55%);
}

.title-tower {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.t-block {
  height: 18px;
  border-radius: 6px;
  opacity: 0;
  animation: stack-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.tb1 {
  width: 150px;
  background: var(--blue);
  animation-delay: 0.50s;
}

.tb2 {
  width: 120px;
  background: var(--amber);
  animation-delay: 0.35s;
}

.tb3 {
  width: 90px;
  background: var(--green);
  animation-delay: 0.20s;
}

.tb4 {
  width: 60px;
  background: var(--red);
  animation-delay: 0.05s;
}

@keyframes stack-in {
  from {
    opacity: 0;
    transform: translateY(-16px) scale(0.88);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.title-text {
  font-size: clamp(2.6rem, 12cqw, 3.4rem);
  font-weight: 900;
  color: var(--text);
  text-align: center;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.title-sub {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-2);
  margin-top: -4px;
}

/* ============================================
   STAGE SELECT
   ============================================ */
#screen-stage-select {
  background: var(--blue-bg);
  transition: background 0.25s;
}

#screen-stage-select .top-bar {
  background: var(--blue-bg);
  border-bottom-color: var(--blue-bd);
}

#screen-stage-select .top-title {
  color: var(--blue-dark);
}

#screen-stage-select .btn-icon {
  background: var(--surface);
  border-color: var(--blue-bd);
  color: var(--blue-dark);
}

#screen-stage-select .btn-icon:hover {
  background: var(--blue-bg);
  border-color: var(--blue-lt);
}

#screen-stage-select.infinite-mode {
  background: var(--purple-bg);
}

#screen-stage-select.infinite-mode .top-bar {
  background: var(--purple-bg-dk);
  border-bottom-color: var(--purple-bd);
}

#screen-stage-select.infinite-mode .top-title {
  color: var(--purple-dk);
}

#screen-stage-select.infinite-mode .btn-icon {
  background: var(--surface);
  border-color: var(--purple-bd);
  color: var(--purple-dk);
}

#screen-stage-select.infinite-mode .btn-icon:hover {
  background: var(--purple-bg);
  border-color: var(--purple);
}

.stage-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  padding: 12px;
  overflow: hidden;
}

.stage-cell {
  position: relative;
  border-radius: var(--r-sm);
  border: 2px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  gap: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
  overflow: hidden;
}

.stage-cell:hover {
  transform: scale(1.03);
  border-color: var(--blue-bd);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.12);
}

.stage-cell.cleared:hover {
  border-color: var(--blue-dark);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.18);
}

.stage-cell:active {
  transform: scale(0.93);
  box-shadow: none;
}

.stage-cell.unlocked {
  background: var(--surface);
  border-color: var(--blue-bd);
  opacity: 0.85;
}

.stage-cell.played {
  background: var(--surface);
  border-color: var(--blue-lt);
}

.stage-cell.cleared {
  background: var(--blue-bg);
  border-color: var(--blue);
}

.perfect-badge {
  position: absolute;
  top: -10px;
  left: -7px;
  width: 44px;
  height: 44px;
  animation: pop-in 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  pointer-events: none;
  mix-blend-mode: multiply;
}

@keyframes pop-in {
  from {
    transform: scale(0);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

#screen-stage-select.infinite-mode .stage-cell.unlocked {
  background: var(--surface);
  border-color: var(--purple-bd);
}

#screen-stage-select.infinite-mode .stage-cell.played {
  background: var(--purple-bg);
  border-color: var(--purple-bd-dk);
}

#screen-stage-select.infinite-mode .stage-cell:hover {
  border-color: var(--purple-bd-dk);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.12);
}

.cell-title {
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--text-3);
  letter-spacing: 0.05em;
  margin-bottom: -4px;
}

.cell-num {
  font-size: clamp(1.6rem, 5cqw, 2.2rem);
  font-weight: 900;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stage-cell.cleared .cell-num {
  color: var(--blue);
}

.cell-scores {
  display: flex;
  flex-direction: row;
  justify-content: center;
  gap: 8px;
  width: 100%;
  align-items: center;
}

.cell-score-item {
  display: flex;
  align-items: center;
  gap: 2px;
  line-height: 1;
}

.cell-score-icon {
  font-size: 0.65rem;
  font-weight: 800;
  opacity: 0.7;
}

.cell-score-val {
  font-size: clamp(0.8rem, 2.3cqw, 1rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.cell-score-blocks .cell-score-icon,
.cell-score-blocks .cell-score-val {
  color: var(--blue);
}

.cell-score-wrongs .cell-score-icon,
.cell-score-wrongs .cell-score-val {
  color: var(--red);
}

.cell-no-score {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.03em;
}

/* Infinite mode toggle */
.btn-inf-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--purple-bg);
  color: var(--purple);
  border: 2px solid var(--purple-bd);
  border-radius: var(--r-sm);
  padding: 5px 14px;
  min-height: 44px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, background 0.2s, color 0.2s, border-color 0.2s, filter 0.15s;
  flex-shrink: 0;
}

.btn-inf-toggle:hover {
  filter: brightness(0.95);
}

.btn-inf-toggle.active {
  background: var(--blue-bg);
  color: var(--blue-dark);
  border-color: var(--blue-bd);
  box-shadow: none;
}

.btn-inf-toggle.active:hover {
  filter: brightness(1.08);
}

.btn-inf-toggle:active {
  transform: scale(0.94);
  filter: none;
}

.inf-toggle-label {
  font-size: 0.75rem;
  font-weight: 800;
}

/* ============================================
   GAME SCREEN
   ============================================ */
#screen-game {
  background: var(--bg);
}

.game-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-top: var(--top-ad-space);
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}

.game-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.mode-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text-2);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.prog-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.prog-track {
  flex: 1;
  height: 10px;
  background: var(--bg);
  border-radius: 5px;
  overflow: hidden;
  border: 1.5px solid var(--border);
}

.prog-fill {
  height: 100%;
  background: var(--blue);
  width: 100%;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
}

.prog-text {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text-2);
  white-space: nowrap;
  min-width: 42px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.wrong-badge {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--red-bg);
  color: var(--red);
  border-radius: var(--r-sm);
  border: 1.5px solid var(--red-bd);
  padding: 4px 8px;
  font-size: 0.95rem;
  font-weight: 900;
  min-width: 46px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.wrong-badge-icon {
  font-size: 0.7rem;
  font-weight: 800;
  opacity: 0.75;
}

.inf-blocks-badge {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--purple-bg);
  color: var(--purple);
  border-radius: var(--r-sm);
  border: 1.5px solid var(--purple-bd);
  padding: 4px 8px;
  font-size: 0.95rem;
  font-weight: 900;
  min-width: 46px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.inf-blocks-icon {
  font-size: 0.7rem;
  font-weight: 800;
  opacity: 0.75;
}

/* Tower */
.tower-area {
  flex: 1;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  min-height: 0;
  background: linear-gradient(180deg, var(--blue-bg) 0%, var(--blue-bd) 100%);
}

#tower-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Problem */
.problem-area {
  padding: 10px 16px 8px;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
  background: var(--surface);
  border-top: 2px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.problem-box {
  font-size: clamp(2rem, 8cqw, 2.8rem);
  font-weight: 900;
  color: var(--text);
  text-align: center;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

/* Answer buttons */
.answer-area {
  display: flex;
  gap: 10px;
  padding: 10px 14px 14px;
  flex-shrink: 0;
  background: var(--surface);
}

.ans-btn {
  flex: 1;
  height: 62px;
  font-size: clamp(1.5rem, 6cqw, 2.2rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  border: 2px solid var(--border-dk);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 0 var(--border-dk);
  transition: transform 0.08s, box-shadow 0.08s, background 0.12s, border-color 0.12s, color 0.12s;
}

.ans-btn:hover {
  background: var(--blue-bg);
  border-color: var(--blue-bd);
  color: var(--blue);
}

.ans-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--border-dk);
}

.ans-btn.correct {
  background: var(--green-bg);
  border-color: var(--green);
  color: var(--green);
  box-shadow: 0 4px 0 var(--green-bd);
}

.ans-btn.wrong {
  background: var(--red-bg);
  border-color: var(--red);
  color: var(--red);
  box-shadow: 0 4px 0 var(--red-bd);
  animation: shake 0.32s ease;
}

@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-7px);
  }

  75% {
    transform: translateX(7px);
  }
}

/* ============================================
   PAUSE SCREEN
   ============================================ */
.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  padding: 32px 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(300px, 88cqw);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
  border: 2px solid var(--border);
}

.modal-icon {
  font-size: 2.2rem;
  line-height: 1;
  margin-bottom: 2px;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

/* ============================================
   RESULT SCREEN
   ============================================ */
#screen-result {
  background: linear-gradient(180deg, var(--blue-bg) 0%, var(--bg) 50%);
}

.result-heading {
  font-size: clamp(2rem, 9cqw, 2.8rem);
  font-weight: 900;
  text-align: center;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.result-heading.clear {
  color: var(--green);
}

.result-heading.fail {
  color: var(--red);
}

.result-score {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-2);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.result-records {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 14px 20px;
  width: min(260px, 80cqw);
  border: 2px solid var(--border);
}

.rec-title {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--text-2);
  text-align: center;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.rec-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.rec-row:last-child {
  border-bottom: none;
}

.medal {
  font-size: 1.3rem;
}

.rec-score {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.result-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(280px, 80cqw);
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .rotate-icon {
    transform: rotate(90deg);
  }
}

/* ============================================
   AUTH AREA (TITLE SCREEN)
   ============================================ */
.auth-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 280px;
}

.btn-google-login {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border-dk);
  border-radius: var(--r-md);
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  width: 100%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.btn-google-login:hover {
  background: var(--bg);
  border-color: #4285F4;
  box-shadow: 0 2px 10px rgba(66, 133, 244, 0.22);
}

.btn-google-login:active {
  transform: translateY(1px);
  box-shadow: none;
}

.google-icon {
  flex-shrink: 0;
}

.user-info {
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 12px;
  width: 100%;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-name {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.btn-logout {
  background: var(--red-bg);
  color: var(--red);
  border: 1.5px solid var(--red-bd);
  border-radius: var(--r-sm);
  padding: 5px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
  transition: background 0.15s;
}

.btn-logout:hover {
  background: var(--red-bd);
}

/* ============================================
   SYNC CONFLICT POPUP
   ============================================ */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
}

.popup-box {
  background: var(--surface);
  border-radius: var(--r-xl);
  padding: 28px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(320px, 90vw);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
  border: 2px solid var(--border);
}

.popup-icon {
  font-size: 2.2rem;
  line-height: 1;
}

.popup-title {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--text);
  text-align: center;
}

.popup-desc {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-2);
  text-align: center;
  line-height: 1.55;
}

.popup-compare {
  width: 100%;
  background: var(--bg);
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 2px;
}

.compare-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.compare-label {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-2);
  flex-shrink: 0;
}

.compare-val {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
}

.btn-ghost {
  background: transparent;
  color: var(--text-3);
  border: none;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  border-radius: var(--r-sm);
  width: 100%;
  max-width: 280px;
  transition: color 0.15s, background 0.15s;
}

/* ============================================
   TITLE FOOTER
   ============================================ */
.title-footer {
  width: 100%;
  padding: 16px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-2);
  flex-shrink: 0;
}

.footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.footer-links a {
  color: var(--text-2);
  text-decoration: none;
  font-weight: 700;
  transition: color 0.15s;
}

.footer-links a:hover {
  color: var(--blue);
}

.footer-divider {
  opacity: 0.3;
}

.copyright {
  opacity: 0.6;
}