*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: var(--type-body);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--text-primary);
  background-color: var(--bg-main);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

#app {
  max-width: 428px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: 80px;
  position: relative;
}

h1, h2, h3, h4 {
  font-family: var(--font-body);
  font-weight: var(--weight-heavy);
  line-height: 1.2;
}

h1 { font-size: var(--type-h1); }
h2 { font-size: var(--type-h2); }
h3 { font-size: var(--type-section); }
h4 { font-size: var(--type-body); }

p {
  font-size: var(--type-body-sm);
  font-weight: var(--weight-bold);
  color: var(--text-secondary);
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button {
  font-family: var(--font-body);
  font-weight: var(--weight-bold);
  cursor: pointer;
  border: none;
  outline: none;
  background: none;
  font-size: var(--type-body);
}

input {
  font-family: var(--font-body);
  font-size: var(--type-body);
  outline: none;
  border: none;
}

.screen {
  padding: 16px;
  animation: fadeIn var(--transition-normal);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Navbar */
#navbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-navbar);
  border-top: 2px solid var(--border-navbar);
  z-index: 100;
  display: flex;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}

.navbar-inner {
  display: flex;
  width: 100%;
  max-width: 428px;
  justify-content: space-around;
  gap: 2px;
}

input, textarea {
  background: var(--bg-input);
  color: var(--text-primary);
}

input::placeholder, textarea::placeholder {
  color: var(--text-hint);
}

.app-error-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  text-align: center;
  background: var(--bg-main);
  color: var(--text-primary);
  gap: 8px;
}

.app-error-emoji { font-size: 48px; margin-bottom: 12px; }
.app-error-title { font-size: var(--type-h2); font-weight: 800; }
.app-error-sub   { font-size: var(--type-body-sm); color: var(--text-secondary); margin-bottom: 16px; }

.app-error-btn {
  background: var(--color-primary);
  color: #FFFFFF;
  border: 2px solid var(--color-primary-dark);
  border-bottom: 4px solid var(--color-primary-dark);
  border-radius: 14px;
  padding: 14px 32px;
  font-size: var(--type-body);
  font-weight: 800;
  cursor: pointer;
}

.app-error-detail {
  margin-top: 16px;
  max-width: 320px;
  font-size: var(--type-caption);
  color: var(--text-hint);
  white-space: pre-wrap;
  word-break: break-word;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-card) 50%, var(--bg-surface) 75%);
  background-size: 400px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 16px;
}

@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: 200px 0; }
}

/* 3D Card pattern (Duolingo-style) */
.card-3d {
  background: var(--bg-card);
  border: 2px solid var(--border-card);
  border-bottom: 4px solid var(--border-card-bottom);
  border-radius: 16px;
  transition: transform 100ms ease, border-bottom-width 100ms ease;
  -webkit-tap-highlight-color: transparent;
}

.card-3d:active,
.card-3d.pressed {
  border-bottom-width: 2px;
  transform: translateY(2px);
}

.card-3d-primary {
  background: var(--color-primary);
  border: 2px solid var(--color-primary-dark);
  border-bottom: 4px solid var(--color-primary-dark);
  border-radius: 16px;
  color: #FFFFFF;
  transition: transform 100ms ease, border-bottom-width 100ms ease;
  -webkit-tap-highlight-color: transparent;
}

.card-3d-primary:active {
  border-bottom-width: 2px;
  transform: translateY(2px);
}

/* Bounce / pop / wiggle keyframes */
@keyframes bounce-in {
  0% { transform: scale(0.85); opacity: 0; }
  55% { transform: scale(1.04); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-3deg); }
  75% { transform: rotate(3deg); }
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes spring-press {
  0% { transform: scale(1); }
  40% { transform: scale(0.92); }
  70% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

.anim-bounce-in { animation: bounce-in 300ms ease; }
.anim-pop { animation: pop 200ms ease; }
.anim-wiggle { animation: wiggle 300ms ease; }
.anim-spring { animation: spring-press 200ms ease; }

/* Thick 3D progress bar */
.progress-bar-3d {
  height: 12px;
  border-radius: 8px;
  background: var(--bg-progress-track);
  overflow: hidden;
  position: relative;
}

.progress-bar-3d-fill {
  height: 100%;
  border-radius: 8px;
  background: var(--color-gold);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.1), inset 0 2px 0 rgba(255,255,255,0.3);
  transition: width 300ms ease;
}

.tappable {
  transition: transform 100ms ease;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tappable:active {
  transform: translateY(2px);
}

.navbar-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  color: #BBBBBB;
  transition: color var(--transition-fast), transform 100ms ease;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.navbar-tab:active { transform: scale(0.95); }

.navbar-tab.active {
  color: var(--color-primary);
}

.navbar-tab.active::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-primary);
}

.navbar-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

.navbar-icon-img {
  object-fit: contain;
  transition: filter 120ms ease, opacity 120ms ease;
  filter: grayscale(100%);
  opacity: 0.5;
}

.navbar-tab.active .navbar-icon-img {
  filter: none;
  opacity: 1;
}

[data-theme="dark"] .navbar-icon-img {
  filter: none;
  opacity: 0.55;
}

[data-theme="dark"] .navbar-tab.active .navbar-icon-img {
  opacity: 1;
}

.navbar-label {
  font-size: var(--type-micro);
  font-weight: 800;
  line-height: 1;
}

.navbar-tab.active .navbar-label {
  font-weight: 800;
}

/* ============================
   Neon game shell v2
   ============================ */
[data-theme="dark"] body {
  background:
    radial-gradient(circle at 18% 0%, rgba(255, 47, 163, 0.16), transparent 28%),
    radial-gradient(circle at 100% 18%, rgba(141, 77, 255, 0.14), transparent 34%),
    var(--neo-bg);
}

#navbar {
  background: rgba(10, 8, 25, 0.86);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 -16px 36px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
}

.navbar-inner {
  max-width: 428px;
  gap: 4px;
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
}

.navbar-tab {
  min-width: 58px;
  min-height: 58px;
  padding: 6px 4px 5px;
  border-radius: 18px;
  color: rgba(222, 210, 244, 0.66);
}

.navbar-tab.active {
  color: #FFFFFF;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 105, 196, 0.34), transparent 62%),
    rgba(255, 47, 163, 0.16);
  box-shadow: inset 0 0 0 1px rgba(255, 75, 176, 0.32), 0 0 24px rgba(255, 47, 163, 0.24);
}

.navbar-tab.active::before {
  top: auto;
  bottom: 0;
  width: 26px;
  height: 4px;
  border-radius: 999px 999px 0 0;
  background: var(--neo-pink);
  box-shadow: 0 0 16px rgba(255, 47, 163, 0.78);
}

.navbar-icon {
  width: 34px;
  height: 34px;
}

.navbar-label {
  color: currentColor;
  font-size: 10px;
  line-height: 1;
  text-transform: uppercase;
}

.navbar-tab.active .navbar-label {
  color: #FFFFFF;
}

.resource-bar {
  display: grid;
  grid-template-columns: 1.08fr 1fr 1fr 0.9fr 44px;
  gap: 8px;
  align-items: center;
  width: 100%;
  margin-bottom: 16px;
}

.resource-chip,
.resource-settings {
  min-width: 0;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.015)),
    rgba(19, 14, 39, 0.88);
  color: #FFFFFF;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 8px 18px rgba(0, 0, 0, 0.26);
}

.resource-chip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.resource-chip small {
  display: block;
  margin-left: -2px;
  color: var(--neo-muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.resource-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex: 0 0 auto;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.36));
}

.resource-chip-streak {
  display: inline-flex;
  gap: 7px;
  justify-content: center;
  padding: 0 10px;
}

.resource-streak-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
}

.resource-streak-copy span {
  display: block;
  color: #FFFFFF;
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
}

.resource-streak-copy small {
  display: block;
  margin-left: 0;
  color: var(--neo-muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.resource-chip-hearts {
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 105, 196, 0.18), transparent 56%),
    rgba(19, 14, 39, 0.88);
}

.resource-settings {
  color: #CFC4EC;
}

.resource-settings:active,
.resource-chip:active {
  transform: translateY(1px) scale(0.98);
}

@media (max-width: 380px) {
  .resource-bar {
    grid-template-columns: repeat(4, minmax(0, 1fr)) 40px;
    gap: 6px;
  }

  .resource-chip,
  .resource-settings {
    height: 40px;
    border-radius: 14px;
  }

  .resource-icon {
    width: 24px;
    height: 24px;
  }

  .resource-chip span {
    font-size: 13px;
  }

  .resource-chip small {
    display: none;
  }
}
