:root {
  --color-primary: #7c4dff;
  --color-primary-dark: #5e35c7;
  --color-primary-light: #ede7ff;
  --color-accent: #22b573;
  --color-accent-light: #e3f9ee;
  --color-bg: #faf8ff;
  --color-card: #ffffff;
  --color-text: #26213a;
  --color-text-muted: #635e78;
  --color-border: #e3ddf7;
  --color-danger: #d64545;
  --color-danger-light: #fdecec;
  --color-food: #e2971f;
  --color-food-light: #fff3de;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 4px 16px rgba(90, 60, 180, 0.1);
  --font-base: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}

* {
  box-sizing: border-box;
}

/* The HTML `hidden` attribute must always win over any component's own
   `display` value, regardless of selector specificity ties (e.g. .btn,
   .wizard-actions, .loading-overlay all set their own display). */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-base);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: 1rem;
}

h1, h2, h3, h4, p {
  margin: 0 0 0.6em 0;
}

img {
  max-width: 100%;
}

a {
  color: var(--color-primary-dark);
}

:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, var(--color-primary), #9c6bff);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(90, 60, 180, 0.25);
}

.app-header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.app-header-left {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.icon-btn {
  min-height: 40px;
  padding: 0.4rem 0.7rem;
  font-size: 1.1rem;
  line-height: 1;
  flex: none;
}

.app-title {
  font-size: 1.15rem;
  font-weight: 800;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lite-badge {
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.25);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

/* Main */
.app-main {
  max-width: 860px;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

.screen {
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen-title {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 0.6rem;
}

.screen-subtitle {
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}

/* Cards */
.card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  border: 1px solid var(--color-border);
}

.card h2, .card h3 {
  margin-top: 0;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
}

.stat-tile {
  background: var(--color-primary-light);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  text-align: center;
}

.stat-tile .stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-primary-dark);
}

.stat-tile .stat-label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Growth character card */
.growth-card {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.growth-icon {
  font-size: 3rem;
  flex: none;
}

.growth-info {
  min-width: 0;
}

.growth-label {
  font-weight: 800;
  margin-bottom: 0.2rem;
}

.growth-next {
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

/* Suggestion banner */
.suggestion-banner {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  text-align: left;
  background: linear-gradient(135deg, var(--color-accent-light), #fff);
  border: 2px solid var(--color-accent);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1rem;
  cursor: pointer;
  font-weight: 700;
  color: var(--color-text);
  transition: transform 0.08s ease;
}

.suggestion-banner:active {
  transform: scale(0.98);
}

.suggestion-icon {
  font-size: 1.8rem;
  flex: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 48px;
  padding: 0.7rem 1.3rem;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  font-weight: 700;
  cursor: pointer;
  background: var(--color-primary);
  color: #fff;
  transition: transform 0.06s ease, filter 0.15s ease;
}

.btn:hover {
  filter: brightness(1.05);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.btn-secondary {
  background: var(--color-accent);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.6);
  color: #fff;
  min-height: 40px;
  padding: 0.4rem 0.9rem;
}

.btn-outline {
  background: #fff;
  color: var(--color-primary-dark);
  border-color: var(--color-primary);
}

.btn-danger {
  background: var(--color-danger);
}

.btn-sm {
  min-height: 40px;
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}

.menu-card {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  text-align: left;
  background: var(--color-card);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  cursor: pointer;
  box-shadow: var(--shadow-card);
}

.menu-card:hover {
  border-color: var(--color-primary);
}

.menu-card .menu-icon {
  font-size: 1.8rem;
}

.menu-card > span:last-child {
  min-width: 0;
  flex: 1;
}

.nickname-card {
  cursor: default;
}

.menu-resume-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  text-align: left;
  font: inherit;
  color: inherit;
}

.icon-btn-danger {
  flex: none;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
}

.icon-btn-danger:hover {
  background: var(--color-danger-light);
}

.menu-card .menu-title {
  display: block;
  font-weight: 800;
  margin-bottom: 0.15rem;
}

.menu-card .menu-desc {
  display: block;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Choice list (feelings / difficulties / strategies) */
.choice-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.7rem;
}

.choice-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  padding: 0.85rem 1rem;
  border-radius: 999px;
  border: 2px solid var(--color-border);
  background: #fff;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.choice-item:hover {
  border-color: var(--color-primary);
}

.choice-item:active {
  transform: scale(0.96);
}

.choice-item .choice-icon {
  font-size: 1.25rem;
  line-height: 1;
  flex: none;
}

.choice-item .choice-text {
  flex: 1;
}

.choice-item[aria-pressed="true"] {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: 0 3px 10px rgba(124, 77, 255, 0.25);
}

.choice-item[aria-pressed="true"]::after {
  content: "✔";
  color: var(--color-primary-dark);
  font-weight: 800;
  flex: none;
}

.choice-item-food {
  border-color: #f3d7a1;
  background: var(--color-food-light);
}

.choice-item-food:hover {
  border-color: var(--color-food);
}

.choice-item-food[aria-pressed="true"] {
  border-color: var(--color-food);
  background: #ffe6b3;
  box-shadow: 0 3px 10px rgba(226, 151, 31, 0.3);
}

.choice-item-food[aria-pressed="true"]::after {
  color: #a25d00;
}

.section-divider {
  border: none;
  border-top: 2px dashed var(--color-border);
  margin: 1.6rem 0;
}

/* Form elements */
label {
  display: block;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="search"],
input[type="date"],
textarea,
select {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--color-border);
  background: #fff;
  color: var(--color-text);
}

.date-input {
  width: auto;
  max-width: 200px;
}

textarea {
  resize: vertical;
  min-height: 4.5em;
}

.field {
  margin-bottom: 1rem;
}

.field-hint {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-top: 0.3rem;
}

input[type="range"] {
  width: 100%;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.range-value {
  min-width: 2.6em;
  text-align: center;
  font-weight: 800;
  color: var(--color-primary-dark);
  font-size: 1.2rem;
}

/* Step wizard */
.step-indicator {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.step-dot {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--color-border);
}

.onboarding-card {
  padding: 2.5rem 1.5rem;
}

.onboarding-icon {
  font-size: 3.5rem;
  margin-bottom: 0.8rem;
}

.step-dot.active {
  background: var(--color-primary);
}

.wizard-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.2rem;
}

.wizard-actions .btn {
  flex: 1;
}

/* Badges */
.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.8rem;
}

.badge-tile {
  text-align: center;
  padding: 1rem 0.6rem;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  background: #fff;
}

.badge-tile .badge-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 0.35rem;
}

.badge-tile.unlocked {
  background: var(--color-accent-light);
  border-color: var(--color-accent);
}

.badge-tile.locked {
  opacity: 0.55;
  filter: grayscale(0.6);
}

.badge-tile .badge-name {
  font-weight: 700;
  font-size: 0.9rem;
}

.badge-tile .badge-state {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 0.2rem;
}

/* Note entries */
.note-entry {
  border-left: 4px solid var(--color-primary);
  padding: 0.7rem 0.9rem;
  background: #fff;
  border-radius: var(--radius-sm);
  margin-bottom: 0.7rem;
}

.note-entry .note-meta {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 0.3rem;
}

.note-entry dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.6rem;
  font-size: 0.92rem;
}

.note-entry dt {
  font-weight: 700;
  color: var(--color-text-muted);
}

.note-entry dd {
  margin: 0;
}

.confidence-chart {
  display: block;
  width: 100%;
  height: auto;
  max-width: 320px;
  margin: 0.5rem 0;
}

/* Counseling report */
.report-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
}

.report-title {
  font-weight: 800;
  font-size: 1.1rem;
}

.report-dl {
  margin: 0.6rem 0 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.8rem;
}

.report-dl dt {
  font-weight: 700;
  color: var(--color-text-muted);
}

.report-dl dd {
  margin: 0;
}

/* Certificate */
.certificate-card {
  text-align: center;
  border: 3px double var(--color-primary);
  background: linear-gradient(180deg, #fff, var(--color-primary-light));
}

.certificate-seal {
  font-size: 3rem;
}

.certificate-title {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.3em;
  color: var(--color-primary-dark);
  margin: 0.3rem 0 1rem;
}

.certificate-name {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 0.8rem;
}

.certificate-body {
  line-height: 1.9;
}

.certificate-signature {
  margin-top: 1.2rem;
  font-weight: 700;
  color: var(--color-primary-dark);
}

@media print {
  .app-header,
  .toast,
  #loadingOverlay,
  .btn,
  .menu-grid {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}

/* Tarot-style talk cards */
.tarot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
}

.tarot-card {
  perspective: 1000px;
  height: 220px;
  cursor: pointer;
}

.tarot-card.flipped {
  cursor: default;
}

.tarot-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

.tarot-card.flipped .tarot-card-inner {
  transform: rotateY(180deg);
}

.tarot-card:not(.flipped):hover .tarot-card-inner {
  transform: scale(1.04);
}

.tarot-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: auto;
}

.tarot-back {
  background: linear-gradient(135deg, var(--color-primary), #9c6bff);
  color: #fff;
  font-size: 2.8rem;
  border: 2px solid var(--color-primary-dark);
  box-shadow: var(--shadow-card);
}

.tarot-front {
  background: var(--color-primary-light);
  border: 2px solid var(--color-primary);
  transform: rotateY(180deg);
  flex-direction: column;
  gap: 0.6rem;
}

.tarot-question {
  font-weight: 700;
  text-align: center;
  margin: 0;
}

.tarot-answer-input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--color-border);
  font-size: 0.85rem;
  text-align: center;
}

/* Game */
.game-question {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 0.9rem;
}

.game-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.8rem 1rem;
  margin-bottom: 0.6rem;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
}

.game-option.correct {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}

.game-option.correct::after {
  content: " ✔ 정답";
  color: var(--color-accent);
  font-weight: 800;
}

.game-option.wrong {
  border-color: var(--color-danger);
  background: var(--color-danger-light);
}

.game-option.wrong::after {
  content: " ✘ 오답";
  color: var(--color-danger);
  font-weight: 800;
}

.game-option:disabled {
  cursor: default;
}

.game-explain {
  background: var(--color-primary-light);
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
  margin-top: 0.8rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
}

.timer-badge {
  display: inline-block;
  background: var(--color-danger-light);
  color: var(--color-danger);
  font-weight: 800;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
}

.canvas-card {
  display: flex;
  justify-content: center;
  padding: 0.8rem;
}

#gameCanvas {
  max-width: 100%;
  height: auto;
  background: #fff;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  touch-action: none;
}

/* Alerts / banners */
.banner {
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

.banner-info {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

.banner-error {
  background: var(--color-danger-light);
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}

.qr-wrap {
  display: flex;
  justify-content: center;
  padding: 0.8rem;
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.qr-wrap svg {
  width: 100%;
  max-width: 260px;
  height: auto;
}

.privacy-list {
  padding-left: 1.2rem;
}

.privacy-list li {
  margin-bottom: 0.4rem;
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(38, 33, 58, 0.55);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  z-index: 100;
}

.loading-spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

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

/* Celebration overlay */
.celebration-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(38, 33, 58, 0.35);
  overflow: hidden;
}

.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}

@keyframes confetti-fall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(420px) rotate(360deg); opacity: 0; }
}

.celebration-stamp {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 2rem 2.5rem;
  text-align: center;
  box-shadow: var(--shadow-card);
  animation: stamp-pop 0.4s ease;
}

@keyframes stamp-pop {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

.celebration-icon {
  font-size: 3.5rem;
}

.celebration-text {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--color-primary-dark);
  margin-top: 0.5rem;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  background: var(--color-text);
  color: #fff;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  max-width: 90vw;
}

/* Utility */
.mt-1 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; }
.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.flex-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.hidden { display: none !important; }

@media (max-width: 480px) {
  .app-title {
    font-size: 1rem;
  }
  .screen-title {
    font-size: 1.2rem;
  }
  .card {
    padding: 0.9rem 1rem;
  }
}

.app-footer {
  padding: 1.5rem 1rem 2rem;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  line-height: 1.6;
}
