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

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: #10182f;
  color: #f7f7fb;
  min-height: 100dvh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.bg-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

.bg-slide {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 1.2s ease;
}

.bg-slide.is-active {
  opacity: 1;
}

.bg-scrim {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    180deg,
    rgba(16, 24, 47, 0.55),
    rgba(16, 24, 47, 0.75)
  );
  pointer-events: none;
}

.hidden {
  display: none !important;
}

.app {
  width: 100%;
  max-width: min(480px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 32px);
  padding-top: max(clamp(16px, 4vw, 32px), env(safe-area-inset-top));
  padding-right: max(clamp(16px, 4vw, 32px), env(safe-area-inset-right));
  padding-bottom: max(clamp(16px, 4vw, 32px), env(safe-area-inset-bottom));
  padding-left: max(clamp(16px, 4vw, 32px), env(safe-area-inset-left));
  position: relative;
  z-index: 2;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

/* Game HUD */
.game-hud {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(16, 24, 47, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 16px;
  padding: 10px 14px;
  margin-bottom: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hud-level {
  font-size: 0.8125rem;
  font-weight: 700;
  color: #c4b5fd;
  white-space: nowrap;
  background: rgba(139, 124, 246, 0.25);
  padding: 4px 10px;
  border-radius: 10px;
}

.xp-bar {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.xp-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8b7cf6, #d4a853);
  border-radius: 4px;
  transition: width 0.4s ease;
}

.hud-stars {
  font-size: 0.875rem;
  white-space: nowrap;
}

.screen-header {
  margin-bottom: 24px;
}

.app-title {
  font-size: clamp(1.75rem, 5vw, 2rem);
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

h2 {
  font-size: clamp(1.25rem, 4vw, 1.375rem);
  font-weight: 600;
  margin: 0;
  line-height: 1.4;
}

h3.records-list-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: rgba(247, 247, 251, 0.75);
  margin: 0 0 12px;
}

.subtitle {
  font-size: 1.0625rem;
  color: rgba(247, 247, 251, 0.85);
  margin: 0;
}

.greeting {
  font-size: 1rem;
  color: rgba(247, 247, 251, 0.75);
  margin: 0 0 32px;
}

.quest-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #d4a853;
  background: rgba(212, 168, 83, 0.15);
  padding: 4px 12px;
  border-radius: 20px;
  margin: 0 0 8px;
}

.home-progress-card {
  background: rgba(139, 124, 246, 0.12);
  border: 1px solid rgba(139, 124, 246, 0.25);
}

.home-progress-summary {
  margin: 0;
  font-size: 0.9375rem;
  text-align: center;
  color: rgba(247, 247, 251, 0.9);
}

.card {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 24px;
  padding: 20px;
  margin-bottom: 24px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.card-text {
  margin: 0 0 12px;
  font-size: 1rem;
}

.card-meta {
  margin: 0 0 16px;
  font-size: 0.875rem;
  color: rgba(247, 247, 251, 0.65);
}

/* Quest map */
.quest-map {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px 0 20px;
  flex-wrap: nowrap;
}

.quest-map--compact {
  margin: 0 0 16px;
}

.quest-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 56px;
}

.node-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 700;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(247, 247, 251, 0.5);
  transition: all 0.3s ease;
}

.node-label {
  font-size: 0.625rem;
  color: rgba(247, 247, 251, 0.5);
  text-align: center;
  max-width: 64px;
  line-height: 1.2;
}

.node--locked .node-num {
  opacity: 0.5;
}

.node--active .node-num {
  border-color: #8b7cf6;
  background: rgba(139, 124, 246, 0.35);
  color: #fff;
  box-shadow: 0 0 12px rgba(139, 124, 246, 0.5);
}

.node--active .node-label {
  color: #c4b5fd;
  font-weight: 600;
}

.node--cleared .node-num {
  border-color: #d4a853;
  background: rgba(212, 168, 83, 0.25);
  color: #f5d78e;
}

.node--cleared .node-label {
  color: rgba(245, 215, 142, 0.8);
}

.quest-line {
  width: 24px;
  height: 2px;
  background: rgba(255, 255, 255, 0.15);
  margin: 0 4px;
  margin-bottom: 18px;
  flex-shrink: 0;
}

.quest-line--cleared {
  background: linear-gradient(90deg, #d4a853, #8b7cf6);
}

.step-summary {
  list-style: none;
  margin: 0;
  padding: 0;
}

.step-summary li {
  padding: 8px 0;
  font-size: 0.9375rem;
  color: rgba(247, 247, 251, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.step-summary li:last-child {
  border-bottom: none;
}

.button-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

button {
  width: 100%;
  min-height: 52px;
  border: none;
  border-radius: 16px;
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.15s ease;
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: #8b7cf6;
  color: #fff;
  font-weight: 600;
}

.btn-primary:not(:disabled):hover {
  background: #9d8ff8;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #f7f7fb;
  font-weight: 500;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn-link {
  background: transparent;
  color: rgba(247, 247, 251, 0.7);
  min-height: 44px;
  font-size: 0.9375rem;
}

.btn-link:hover {
  color: #f7f7fb;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  font-weight: 500;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.3);
}

.state-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.btn-state {
  background: rgba(255, 255, 255, 0.08);
  color: #f7f7fb;
  text-align: left;
  padding: 16px 20px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 14px;
}

.btn-state:hover {
  background: rgba(255, 255, 255, 0.14);
}

.btn-state.selected {
  background: rgba(139, 124, 246, 0.35);
  border: 2px solid #8b7cf6;
}

.mission-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.mission-label {
  flex: 1;
}

.step-label {
  font-size: 0.875rem;
  color: #c4b5fd;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: 0.03em;
}

.routine-card {
  text-align: center;
}

.routine-text {
  font-size: 1.0625rem;
  margin: 0 0 24px;
  line-height: 1.7;
}

.timer-display {
  font-size: clamp(2rem, 8vw, 2.5rem);
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  margin: 0 0 12px;
  letter-spacing: 0.05em;
}

.progress-label {
  font-size: 0.75rem;
  color: rgba(247, 247, 251, 0.5);
  margin: 0 0 8px;
  text-align: left;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8b7cf6, #a78bfa);
  border-radius: 4px;
  transition: width 1s linear;
}

.complete-header {
  text-align: center;
}

.complete-badge {
  font-size: 2.5rem;
  margin-bottom: 8px;
  animation: starPop 0.6s ease;
}

.complete-bonus {
  font-size: 1rem;
  font-weight: 600;
  color: #f5d78e;
  text-align: center;
  margin: 0 0 12px;
}

.complete-count {
  font-size: 1.0625rem;
  margin: 0;
  text-align: center;
  color: rgba(247, 247, 251, 0.85);
}

.records-summary {
  font-size: 1.0625rem;
  margin: 0 0 20px;
  font-weight: 500;
  white-space: pre-line;
}

.records-stats,
.guide-info {
  margin: 0;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  gap: 16px;
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-row dt {
  font-size: 0.875rem;
  color: rgba(247, 247, 251, 0.65);
  font-weight: 400;
}

.stat-row dd {
  margin: 0;
  font-size: 0.9375rem;
  text-align: right;
}

.records-list {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
}

.records-list li {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 8px;
  font-size: 0.875rem;
}

.records-list .record-date {
  color: rgba(247, 247, 251, 0.6);
  font-size: 0.8125rem;
}

.records-empty {
  text-align: center;
  color: rgba(247, 247, 251, 0.5);
  padding: 24px;
  font-size: 0.9375rem;
}

.guide-card p {
  margin: 0 0 16px;
  font-size: 0.9375rem;
  line-height: 1.7;
}

.guide-card p:last-of-type {
  margin-bottom: 20px;
}

/* Reward overlay */
.reward-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 47, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.reward-card {
  background: linear-gradient(160deg, rgba(139, 124, 246, 0.2), rgba(31, 45, 77, 0.95));
  border: 1px solid rgba(212, 168, 83, 0.35);
  border-radius: 24px;
  padding: 32px 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 24px rgba(212, 168, 83, 0.15);
  animation: rewardFadeIn 0.4s ease;
}

.reward-stars {
  font-size: 3rem;
  margin-bottom: 12px;
  animation: starPop 0.6s ease;
}

#reward-title {
  font-size: 1.375rem;
  margin: 0 0 12px;
  color: #f5d78e;
}

#reward-message {
  font-size: 1rem;
  color: rgba(247, 247, 251, 0.9);
  margin: 0 0 16px;
  line-height: 1.6;
}

.reward-gains {
  font-size: 1.125rem;
  font-weight: 700;
  color: #c4b5fd;
  margin: 0 0 24px;
}

@keyframes starPop {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  60% {
    transform: scale(1.15);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

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

@media (min-width: 768px) {
  .app {
    max-width: 520px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .app {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .screen-header {
    margin-bottom: 16px;
  }

  .card {
    margin-bottom: 16px;
    padding: 16px;
  }

  .greeting {
    margin-bottom: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .progress-fill,
  .xp-bar-fill,
  .bg-slide {
    transition: none;
  }
}
