:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (max-width: 768px) {
  html {
    -webkit-text-size-adjust: 100%;
  }

  body {
    min-height: 100dvh;
    min-height: 100svh;
  }

  .app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: calc(var(--space-sm) + var(--safe-top)) var(--space-md) var(--space-sm);
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
    background: rgba(255, 255, 255, 0.95);
  }

  .app-header .logo {
    gap: var(--space-xs);
  }

  .app-header .logo-icon {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  .app-header .app-title {
    font-size: 1.2rem;
  }

  .app-main {
    margin-top: calc(56px + var(--safe-top));
    padding: var(--space-md);
    padding-bottom: calc(var(--space-md) + var(--safe-bottom));
    min-height: calc(100dvh - 56px - var(--safe-top));
  }

  .page-content {
    padding: 0;
  }

  .zen-card {
    padding: var(--space-md);
    border-radius: 20px;
  }

  .zen-button {
    min-height: 44px;
    padding: 12px 24px;
  }

  .mood-selector {
    grid-template-columns: repeat(5, 1fr);
    gap: var(--space-xs);
    margin: var(--space-md) 0;
  }

  .mood-item {
    padding: var(--space-sm) var(--space-xs);
    border-radius: 16px;
  }

  .mood-emoji {
    width: 48px;
    height: 48px;
    font-size: 1.8rem;
  }

  .mood-label {
    font-size: 0.75rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }

  .stat-card {
    padding: var(--space-md);
  }

  .stat-card-icon {
    font-size: 1.5rem;
  }

  .stat-card-value {
    font-size: 1.5rem;
  }

  .stat-card-label {
    font-size: 0.75rem;
  }

  .chart-container {
    height: 220px;
    padding: var(--space-sm);
    border-radius: 16px;
  }

  .chart-dimension-switcher {
    width: 100%;
    justify-content: flex-end;
    margin-top: var(--space-sm);
  }

  .mood-history-item {
    padding: var(--space-sm);
  }

  .mood-history-emoji {
    font-size: 1.6rem;
  }

  .mood-history-mood {
    font-size: 0.9rem;
  }

  .mood-history-note {
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  .app-main {
    padding: var(--space-sm);
    padding-bottom: calc(var(--space-sm) + var(--safe-bottom));
  }

  .app-header {
    padding: calc(var(--space-xs) + var(--safe-top)) var(--space-sm) var(--space-xs);
    min-height: 48px;
  }

  .app-main {
    margin-top: calc(48px + var(--safe-top));
  }

  .mood-selector {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }

  .mood-item {
    padding: var(--space-xs) 4px;
    border-radius: 12px;
  }

  .mood-emoji {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
  }

  .mood-label {
    font-size: 0.7rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-card-value {
    font-size: 1.3rem;
  }

  .chart-container {
    height: 180px;
  }

  .zen-card h3 {
    font-size: 0.95rem;
  }

  .chart-legend {
    font-size: 0.75rem;
    gap: var(--space-sm);
  }
}

@media (prefers-color-scheme: dark) and (max-width: 768px) {
  .app-header {
    background: rgba(30, 30, 30, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
  }
}

@media (max-width: 768px) and (orientation: landscape) {
  .app-main {
    padding-bottom: calc(var(--space-md) + var(--safe-bottom));
  }
}
